Skip to content

Commit 15d9f4c

Browse files
committed
SILGen: Ignore invalid associated conformances.
With lazy type checking, invalid conformances can make it all the way to SILGen. As a result, `SILGenModule::useConformance()` needs to handle invalid conformances more gracefully by ignoring them instead of asserting. Resolves rdar://128286622
1 parent 26f5385 commit 15d9f4c

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

lib/SILGen/SILGenLazyConformance.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ void SILGenModule::useConformance(ProtocolConformanceRef conformanceRef) {
3333
// If the conformance is invalid, crash deterministically even in noassert
3434
// builds.
3535
if (conformanceRef.isInvalid()) {
36+
// When lazy type checking is enabled, a conformance may only be diagnosed
37+
// as invalid during SILGen. Ignore it instead of asserting.
38+
auto &ctx = getASTContext();
39+
if (ctx.TypeCheckerOpts.EnableLazyTypecheck && ctx.hadError())
40+
return;
41+
3642
llvm::report_fatal_error("Invalid conformance in type-checked AST");
3743
}
3844

test/SILGen/lazy_typecheck_errors.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ public struct ConformsToProtoWithAssociatedType_MissingTypeRequirement: ProtoWit
2525
// expected-error@-1 {{type 'ConformsToProtoWithAssociatedType_MissingTypeRequirement' does not conform to protocol 'ProtoWithAssociatedType'}}
2626
}
2727

28+
public protocol ProtoWithConstrainedAssociatedType {
29+
associatedtype A: Proto
30+
}
31+
32+
public struct ConformsToProtoWithConstrainedAssociatedType_MissingTypeRequirement: ProtoWithConstrainedAssociatedType {
33+
// expected-error@-1 {{type 'ConformsToProtoWithConstrainedAssociatedType_MissingTypeRequirement' does not conform to protocol 'ProtoWithConstrainedAssociatedType'}}
34+
}
35+
2836
public struct GenericStruct<T> {
2937
public var t: T
3038
}

0 commit comments

Comments
 (0)