Skip to content

Commit 5ac1fc1

Browse files
committed
Sema: Don't produce spurious diagnostic if the constraint type of an failed to resolve
1 parent 33ab33a commit 5ac1fc1

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

lib/Sema/TypeCheckType.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3892,6 +3892,10 @@ TypeResolver::resolveExistentialType(ExistentialTypeRepr *repr,
38923892
if (constraintType->is<ExistentialMetatypeType>())
38933893
return constraintType;
38943894

3895+
// If we already failed, don't diagnose again.
3896+
if (constraintType->hasError())
3897+
return ErrorType::get(getASTContext());
3898+
38953899
auto anyStart = repr->getAnyLoc();
38963900
auto anyEnd = Lexer::getLocForEndOfToken(getASTContext().SourceMgr, anyStart);
38973901
if (!constraintType->isExistentialType()) {

test/type/explicit_existential.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,3 +225,6 @@ func testAnyTypeExpr() {
225225
let invalid = any P
226226
test(invalid)
227227
}
228+
229+
func hasInvalidExistential(_: any DoesNotExistIHope) {}
230+
// expected-error@-1 {{cannot find type 'DoesNotExistIHope' in scope}}

0 commit comments

Comments
 (0)