From ac8dfcf89bfa51b6f3dcbff5f992fde960921e38 Mon Sep 17 00:00:00 2001 From: Pavel Yaskevich Date: Thu, 11 Jun 2020 17:03:28 -0700 Subject: [PATCH] [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. --- lib/Sema/CSGen.cpp | 4 +--- test/decl/protocol/req/recursion.swift | 3 +-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/Sema/CSGen.cpp b/lib/Sema/CSGen.cpp index 15b1d5ee7a85a..fba6b9a4023c0 100644 --- a/lib/Sema/CSGen.cpp +++ b/lib/Sema/CSGen.cpp @@ -1420,7 +1420,7 @@ namespace { if (auto *VD = dyn_cast(E->getDecl())) { knownType = CS.getTypeIfAvailable(VD); if (!knownType) - knownType = VD->getInterfaceType(); + knownType = VD->getType(); if (knownType) { assert(!knownType->isHole()); @@ -1432,8 +1432,6 @@ namespace { } // Set the favored type for this expression to the known type. - if (knownType->hasTypeParameter()) - knownType = VD->getDeclContext()->mapTypeIntoContext(knownType); CS.setFavoredType(E, knownType.getPointer()); } diff --git a/test/decl/protocol/req/recursion.swift b/test/decl/protocol/req/recursion.swift index 3026cb561d389..f9d9761ee5077 100644 --- a/test/decl/protocol/req/recursion.swift +++ b/test/decl/protocol/req/recursion.swift @@ -48,8 +48,7 @@ public struct S where A.T == S { // expected-error {{circular reference // expected-error@-2 {{generic struct 'S' references itself}} // expected-note@-3 {{while resolving type 'S'}} func f(a: A.T) { - g(a: id(t: a)) - // expected-error@-1 {{type of expression is ambiguous without more context}} + g(a: id(t: a)) // `a` has error type which is diagnosed as circular reference _ = A.T.self }