Skip to content

Commit a079c5c

Browse files
authored
Merge pull request #74596 from tshortli/silgen-invalid-associated-requirement
SILGen: Ignore invalid associated conformances
2 parents 2fbc8b3 + 15d9f4c commit a079c5c

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
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: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ public protocol Proto {
77
func req()
88
}
99

10-
public struct ConformsToProtoMissingRequirement: Proto {
11-
// expected-error@-1 {{type 'ConformsToProtoMissingRequirement' does not conform to protocol 'Proto'}}
10+
public struct ConformsToProto_MissingRequirement: Proto {
11+
// expected-error@-1 {{type 'ConformsToProto_MissingRequirement' does not conform to protocol 'Proto'}}
1212
}
1313

14-
public struct ConformsToProtoNearMiss: Proto {
15-
// expected-error@-1 {{type 'ConformsToProtoNearMiss' does not conform to protocol 'Proto'}}
14+
public struct ConformsToProto_NearMiss: Proto {
15+
// expected-error@-1 {{type 'ConformsToProto_NearMiss' does not conform to protocol 'Proto'}}
1616

1717
public func req(x: Int) {}
1818
}
@@ -21,8 +21,16 @@ public protocol ProtoWithAssociatedType {
2121
associatedtype A
2222
}
2323

24-
public struct ConformsToProtoProtoWithAssociatedType: ProtoWithAssociatedType {
25-
// expected-error@-1 {{type 'ConformsToProtoProtoWithAssociatedType' does not conform to protocol 'ProtoWithAssociatedType'}}
24+
public struct ConformsToProtoWithAssociatedType_MissingTypeRequirement: ProtoWithAssociatedType {
25+
// expected-error@-1 {{type 'ConformsToProtoWithAssociatedType_MissingTypeRequirement' does not conform to protocol 'ProtoWithAssociatedType'}}
26+
}
27+
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'}}
2634
}
2735

2836
public struct GenericStruct<T> {

0 commit comments

Comments
 (0)