Skip to content

Commit ac8dfcf

Browse files
committed
[CSGen] Replace getInterfaceType() -> mapTypeIntoContext() for VarDecl with getType
In `ConstraintGenerator::visitDeclRefExpr` instead of using `getInterfaceType()` for unknown type and later mapping it into context, let's use `getType()` which does that interally, that allows to detect presence of error types in resulting type and abort constraint generation.
1 parent b5a8b51 commit ac8dfcf

File tree

2 files changed

+2
-5
lines changed

2 files changed

+2
-5
lines changed

lib/Sema/CSGen.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,7 +1420,7 @@ namespace {
14201420
if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) {
14211421
knownType = CS.getTypeIfAvailable(VD);
14221422
if (!knownType)
1423-
knownType = VD->getInterfaceType();
1423+
knownType = VD->getType();
14241424

14251425
if (knownType) {
14261426
assert(!knownType->isHole());
@@ -1432,8 +1432,6 @@ namespace {
14321432
}
14331433

14341434
// Set the favored type for this expression to the known type.
1435-
if (knownType->hasTypeParameter())
1436-
knownType = VD->getDeclContext()->mapTypeIntoContext(knownType);
14371435
CS.setFavoredType(E, knownType.getPointer());
14381436
}
14391437

test/decl/protocol/req/recursion.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ public struct S<A: P> where A.T == S<A> { // expected-error {{circular reference
4848
// expected-error@-2 {{generic struct 'S' references itself}}
4949
// expected-note@-3 {{while resolving type 'S<A>'}}
5050
func f(a: A.T) {
51-
g(a: id(t: a))
52-
// expected-error@-1 {{type of expression is ambiguous without more context}}
51+
g(a: id(t: a)) // `a` has error type which is diagnosed as circular reference
5352
_ = A.T.self
5453
}
5554

0 commit comments

Comments
 (0)