Skip to content

Commit 6707eb0

Browse files
committed
Fix a bug introduced by the recursive-protocol validation
special case by ensuring that protocols are fully validated before Sema completes. The test case doesn't currently fail without this patch, but there are pending changes which will cause SILGen and IRGen to depend on the requirement signature existing.
1 parent e626dd5 commit 6707eb0

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

lib/Sema/TypeCheckDecl.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7302,6 +7302,9 @@ void TypeChecker::validateDeclForNameLookup(ValueDecl *D) {
73027302
validateDeclForNameLookup(ATD);
73037303
}
73047304
}
7305+
7306+
// Make sure the protocol is fully validated by the end of Sema.
7307+
TypesToFinalize.insert(proto);
73057308
break;
73067309
}
73077310
case DeclKind::AssociatedType: {

lib/Sema/TypeChecker.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,15 @@ static void finalizeType(TypeChecker &TC, NominalTypeDecl *nominal) {
490490
TC.addImplicitConstructors(CD);
491491
TC.addImplicitDestructor(CD);
492492
}
493+
494+
// validateDeclForNameLookup will not trigger an immediate full
495+
// validation of protocols, but clients will assume that things
496+
// like the requirement signature have been set.
497+
if (auto PD = dyn_cast<ProtocolDecl>(nominal)) {
498+
if (!PD->isRequirementSignatureComputed()) {
499+
TC.validateDecl(PD);
500+
}
501+
}
493502
}
494503

495504
static void typeCheckFunctionsAndExternalDecls(TypeChecker &TC) {

test/IRGen/Inputs/witness_table_multifile_2.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ struct X : P {
99
}
1010

1111
func go() -> P { return X("hello") }
12+
13+
protocol ProtocolOnlyUsedAsAType {
14+
}

test/IRGen/witness_table_multifile.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,9 @@ func bar() {
1111
// CHECK-NEXT: getelementptr inbounds i8*, i8** [[WITNESS_TABLE]], i32 3
1212
go().foo()
1313
}
14+
15+
// Ensure that protocols from other files get fully validated even
16+
// when they're only used as types.
17+
func useAProtocol() -> ProtocolOnlyUsedAsAType? {
18+
return nil
19+
}

0 commit comments

Comments
 (0)