Skip to content

Commit 9226c4c

Browse files
authored
Merge pull request #14567 from DougGregor/conformance-check-null-generic-env
[Type checker] Tolerate missing generic environments better.
2 parents fb3ed8a + fd5d3af commit 9226c4c

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

include/swift/AST/Decl.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2300,9 +2300,7 @@ class ValueDecl : public Decl {
23002300
/// Set the interface type for the given value.
23012301
void setInterfaceType(Type type);
23022302

2303-
bool hasValidSignature() const {
2304-
return hasInterfaceType() && !isBeingValidated();
2305-
}
2303+
bool hasValidSignature() const;
23062304

23072305
/// isSettable - Determine whether references to this decl may appear
23082306
/// on the left-hand side of an assignment or as the operand of a

lib/AST/Decl.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1957,6 +1957,10 @@ void ValueDecl::setInterfaceType(Type type) {
19571957
TypeAndAccess.setPointer(type);
19581958
}
19591959

1960+
bool ValueDecl::hasValidSignature() const {
1961+
return hasInterfaceType() && !isBeingValidated();
1962+
}
1963+
19601964
Optional<ObjCSelector> ValueDecl::getObjCRuntimeName() const {
19611965
if (auto func = dyn_cast<AbstractFunctionDecl>(this))
19621966
return func->getObjCSelector();

lib/Sema/ConstraintSystem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,7 @@ void ConstraintSystem::openGeneric(
10741074

10751075
// Create the type variables for the generic parameters.
10761076
for (auto gp : sig->getGenericParams()) {
1077-
auto contextTy = genericEnv->mapTypeIntoContext(gp);
1077+
auto contextTy = GenericEnvironment::mapTypeIntoContext(genericEnv, gp);
10781078
if (auto *archetype = contextTy->getAs<ArchetypeType>())
10791079
locatorPtr = getConstraintLocator(
10801080
locator.withPathElement(LocatorPathElt(archetype)));

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -959,9 +959,15 @@ bool WitnessChecker::findBestWitness(
959959
continue;
960960
}
961961

962-
if (!witness->hasInterfaceType())
962+
if (!witness->hasValidSignature()) {
963963
TC.validateDecl(witness);
964964

965+
if (!witness->hasValidSignature()) {
966+
doNotDiagnoseMatches = true;
967+
continue;
968+
}
969+
}
970+
965971
auto match = matchWitness(TC, Proto, conformance, DC,
966972
requirement, witness);
967973
if (match.isViable()) {

0 commit comments

Comments
 (0)