Skip to content

Commit 7eac14b

Browse files
committed
changing diagnostics err to use ValueDecl and created note
1 parent 2d61c56 commit 7eac14b

File tree

6 files changed

+17
-4
lines changed

6 files changed

+17
-4
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,9 @@ NOTE(single_confusable_character,none,
10551055
ERROR(cannot_find_type_in_scope,none,
10561056
"cannot find type %0 in scope", (DeclNameRef))
10571057
ERROR(cannot_find_type_in_cast_expression,none,
1058-
"type-casting operator expects a type on its right-hand side (got: %0)", (DeclNameRef))
1058+
"type-casting operator expects a type on its right-hand side (got: %0)", (const ValueDecl *))
1059+
NOTE(note_declared_here,none,
1060+
"declared here",())
10591061
ERROR(cannot_find_type_in_scope_did_you_mean,none,
10601062
"cannot find type %0 in scope; did you mean to use '%1'?", (DeclNameRef, StringRef))
10611063
NOTE(note_typo_candidate_implicit_member,none,

lib/Sema/TypeCheckType.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1388,8 +1388,10 @@ static Type diagnoseUnknownType(TypeResolution resolution,
13881388
auto lookupResult = TypeChecker::lookupUnqualified(
13891389
dc, repr->getNameRef(), repr->getLoc(), lookupOptions);
13901390
if (!lookupResult.empty()) {
1391-
diags.diagnose(L, diag::cannot_find_type_in_cast_expression, repr->getNameRef())
1391+
auto first = lookupResult.front().getValueDecl();
1392+
diags.diagnose(L, diag::cannot_find_type_in_cast_expression, first)
13921393
.highlight(R);
1394+
diags.diagnose(first->getNameLoc(), diag::note_declared_here);
13931395
return ErrorType::get(ctx);
13941396
}
13951397
}

test/Constraints/casts.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -745,8 +745,13 @@ do {
745745
// https://github.com/apple/swift/issues/68825
746746
do {
747747
func x(a: Any) {
748-
_ = a is a // expected-error {{type-casting operator expects a type on its right-hand side (got: 'a')}}
749-
_ = a as a // expected-error {{type-casting operator expects a type on its right-hand side (got: 'a')}}
748+
_ = a is a
749+
// expected-error@-1 {{type-casting operator expects a type on its right-hand side (got: 'a')}}
750+
// expected-note@-3 {{declared here}}
751+
_ = a as a
752+
// expected-error@-1 {{type-casting operator expects a type on its right-hand side (got: 'a')}}
753+
// expected-note@-6 {{declared here}}
754+
_ = a is Issue68825 // expected-error {{cannot find type 'Issue68825' in scope}}
750755
_ = a is String // OK
751756
}
752757
}

test/Parse/omit_return.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,6 +1711,7 @@ class CImplicitDotSelfExpr { func gimme() -> CImplicitDotSelfExpr { self.self }
17111711

17121712
func badIs<T>(_ value: Any, anInstanceOf type: T.Type) -> Bool {
17131713
value is type // expected-error {{type-casting operator expects a type on its right-hand side (got: 'type')}}
1714+
// expected-note@-2 {{declared here}}
17141715
}
17151716

17161717

test/Parse/omit_return_fail.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
func badIs<T>(_ value: Any, anInstanceOf type: T.Type) -> Bool {
44
value is type // expected-error {{type-casting operator expects a type on its right-hand side (got: 'type')}}
5+
// expected-note@-2 {{declared here}}
56
}
67

78
func foo() -> Int {
@@ -11,6 +12,7 @@ func foo() -> Int {
1112
func badIs_ifdecl<T>(_ value: Any, anInstanceOf type: T.Type) -> Bool {
1213
#if true
1314
value is type // expected-error {{type-casting operator expects a type on its right-hand side (got: 'type')}}
15+
// expected-note@-3 {{declared here}}
1416
#endif
1517
}
1618

test/Parse/omit_return_ifdecl.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2433,6 +2433,7 @@ class CImplicitDotSelfExpr { func gimme() -> CImplicitDotSelfExpr { self.self }
24332433
func badIs<T>(_ value: Any, anInstanceOf type: T.Type) -> Bool {
24342434
#if true
24352435
value is type // expected-error {{type-casting operator expects a type on its right-hand side (got: 'type')}}
2436+
// expected-note@-3 {{declared here}}
24362437
#endif
24372438
}
24382439

0 commit comments

Comments
 (0)