Skip to content

Commit c435646

Browse files
authored
[GSB] Delay mapping an invalid subject type to an error type (#29813)
1 parent d8bc35b commit c435646

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4358,10 +4358,16 @@ ConstraintResult GenericSignatureBuilder::addTypeRequirement(
43584358
->getDependentType(getGenericParams());
43594359

43604360
Impl->HadAnyError = true;
4361-
4361+
43624362
if (subjectType->is<DependentMemberType>()) {
43634363
subjectType = resolveDependentMemberTypes(*this, subjectType);
4364-
} else {
4364+
}
4365+
4366+
if (!subjectType->is<DependentMemberType>()) {
4367+
// If we end up here, it means either the subject type was never a
4368+
// a dependent member type, or it was initially a dependent member
4369+
// type, but resolving it lead to some other type. Let's map this
4370+
// to an error type so we can emit correct diagnostics.
43654371
subjectType = ErrorType::get(subjectType);
43664372
}
43674373

test/Constraints/associated_types.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,14 @@ struct UsesSameTypedDefaultDerivedWithoutSatisfyingReqts: SameTypedDefaultDerive
109109
static var y: YType { return YType() }
110110
}
111111

112+
// SR-12199
113+
114+
protocol SR_12199_P1 {
115+
associatedtype Assoc
116+
}
117+
118+
enum SR_12199_E {}
119+
120+
protocol SR_12199_P2: SR_12199_P1 where Assoc == SR_12199_E {
121+
associatedtype Assoc: SR_12199_E // expected-error {{type 'Self.Assoc' constrained to non-protocol, non-class type 'SR_12199_E'}}
122+
}

0 commit comments

Comments
 (0)