summaryrefslogtreecommitdiff
path: root/source/slang/slang-check-conformance.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/slang/slang-check-conformance.cpp')
-rw-r--r--source/slang/slang-check-conformance.cpp20
1 files changed, 16 insertions, 4 deletions
diff --git a/source/slang/slang-check-conformance.cpp b/source/slang/slang-check-conformance.cpp
index 71b87f447..ba1b8ea55 100644
--- a/source/slang/slang-check-conformance.cpp
+++ b/source/slang/slang-check-conformance.cpp
@@ -122,6 +122,8 @@ SubtypeWitness* SemanticsVisitor::checkAndConstructSubtypeWitness(
ensureDecl(superDeclRefType->getDeclRef().getDecl(), DeclCheckState::ReadyForLookup);
}
+ SubtypeWitness* failureWitness = nullptr;
+
// In the common case, we can use the pre-computed inheritance information for `subType`
// to enumerate all the types it transitively inherits from.
//
@@ -148,9 +150,19 @@ SubtypeWitness* SemanticsVisitor::checkAndConstructSubtypeWitness(
// If the `superType` appears in the flattened inheritance list
// for the `subType`, then we know that the subtype relationship
- // holds. Conveniently, the `facet` stores a pre-computed witness
- // for the subtype relationship, which we can return here.
- //
+ // holds.
+
+ // If the witness is optional, we should only return it if no certain
+ // witness was found.
+ auto declWitness = as<DeclaredSubtypeWitness>(facet->subtypeWitness);
+ if (declWitness && declWitness->isOptional())
+ {
+ failureWitness = facet->subtypeWitness;
+ continue;
+ }
+
+ // Conveniently, the `facet` stores a pre-computed witness for the
+ // subtype relationship, which we can use here.
return facet->subtypeWitness;
}
//
@@ -271,7 +283,7 @@ SubtypeWitness* SemanticsVisitor::checkAndConstructSubtypeWitness(
return m_astBuilder->getEachSubtypeWitness(subType, superType, elementWitness);
}
// default is failure
- return nullptr;
+ return failureWitness;
}
bool SemanticsVisitor::isValidGenericConstraintType(Type* type)