Skip to content

Commit 97b51d2

Browse files
committed
adding validation to check if unknown type is found somewhere else
1 parent 439ae80 commit 97b51d2

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

lib/Sema/TypeCheckType.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,9 +1385,13 @@ static Type diagnoseUnknownType(TypeResolution resolution,
13851385

13861386
// type-casting operators such as 'is' and 'as'.
13871387
if (resolution.getOptions().is(TypeResolverContext::ExplicitCastExpr)) {
1388-
diags.diagnose(L, diag::cannot_find_type_in_cast_expression, repr->getNameRef())
1389-
.highlight(R);
1390-
return ErrorType::get(ctx);
1388+
auto lookupResult = TypeChecker::lookupUnqualified(
1389+
dc, repr->getNameRef(), repr->getLoc(), lookupOptions);
1390+
if (!lookupResult.empty()) {
1391+
diags.diagnose(L, diag::cannot_find_type_in_cast_expression, repr->getNameRef())
1392+
.highlight(R);
1393+
return ErrorType::get(ctx);
1394+
}
13911395
}
13921396

13931397
diags.diagnose(L, diag::cannot_find_type_in_scope, repr->getNameRef())

0 commit comments

Comments
 (0)