Skip to content

Commit 439ae80

Browse files
committed
changing message and fixing tests
1 parent 1e03ecc commit 439ae80

File tree

7 files changed

+16
-16
lines changed

7 files changed

+16
-16
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,7 @@ 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-
"cast expression 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)", (DeclNameRef))
10591059
ERROR(cannot_find_type_in_scope_did_you_mean,none,
10601060
"cannot find type %0 in scope; did you mean to use '%1'?", (DeclNameRef, StringRef))
10611061
NOTE(note_typo_candidate_implicit_member,none,

lib/Sema/TypeCheckType.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,12 +1294,6 @@ static Type diagnoseUnknownType(TypeResolution resolution,
12941294

12951295
// Unqualified lookup case.
12961296
if (parentType.isNull()) {
1297-
if (resolution.getOptions().hasBase(TypeResolverContext::ExplicitCastExpr)) {
1298-
diags.diagnose(repr->getNameLoc(), diag::cannot_find_type_in_cast_expression,
1299-
repr->getNameRef());
1300-
return ErrorType::get(ctx);
1301-
}
1302-
13031297
// Tailored diagnostic for custom attributes.
13041298
if (resolution.getOptions().is(TypeResolverContext::CustomAttr)) {
13051299
diags.diagnose(repr->getNameLoc(), diag::unknown_attribute,
@@ -1388,6 +1382,13 @@ static Type diagnoseUnknownType(TypeResolution resolution,
13881382

13891383
return I->second;
13901384
}
1385+
1386+
// type-casting operators such as 'is' and 'as'.
1387+
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);
1391+
}
13911392

13921393
diags.diagnose(L, diag::cannot_find_type_in_scope, repr->getNameRef())
13931394
.highlight(R);

test/ClangImporter/Darwin_test.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import Darwin
66
import MachO
77

8-
_ = nil as Fract? // expected-error{{cast expression expects a type on its right-hand side (got: 'Fract')}}
8+
_ = nil as Fract? // expected-error{{cannot find type 'Fract' in scope}}
99
_ = nil as Darwin.Fract? // okay
1010

1111
_ = 0 as OSErr
@@ -14,7 +14,7 @@ _ = 0 as UniChar
1414

1515
_ = ProcessSerialNumber()
1616

17-
_ = 0 as Byte // expected-error {{cast expression expects a type on its right-hand side (got: 'Byte')}}
17+
_ = 0 as Byte // expected-error {{cannot find type 'Byte' in scope}} {{10-14=UInt8}}
1818
Darwin.fakeAPIUsingByteInDarwin() as Int // expected-error {{cannot convert value of type 'UInt8' to type 'Int' in coercion}}
1919

2020
_ = FALSE // expected-error {{cannot find 'FALSE' in scope}}

test/Constraints/casts.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -745,9 +745,8 @@ do {
745745
// https://github.com/apple/swift/issues/68825
746746
do {
747747
func x(a: Any) {
748-
_ = a is a // expected-error {{cast expression expects a type on its right-hand side (got: 'a')}}
749-
_ = a is a? // expected-error {{cast expression expects a type on its right-hand side (got: 'a')}}
750-
_ = a as T // expected-error {{cast expression expects a type on its right-hand side (got: 'T')}}
748+
_ = a is a // expected-error {{type-casting operator expects a type on its right-hand side (got: 'a')}}
749+
_ = a as T // expected-error {{type-casting operator expects a type on its right-hand side (got: 'T')}}
751750
_ = a is String // OK
752751
}
753752
}

test/Parse/omit_return.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1710,7 +1710,7 @@ class CImplicitIdentityExpr { func gimme() -> CImplicitIdentityExpr { self } }
17101710
class CImplicitDotSelfExpr { func gimme() -> CImplicitDotSelfExpr { self.self } }
17111711

17121712
func badIs<T>(_ value: Any, anInstanceOf type: T.Type) -> Bool {
1713-
value is type // expected-error {{cast expression expects a type on its right-hand side (got: 'type')}}
1713+
value is type // expected-error {{type-casting operator expects a type on its right-hand side (got: 'type')}}
17141714
}
17151715

17161716

test/Parse/omit_return_fail.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %target-swift-frontend %s -typecheck -verify
22

33
func badIs<T>(_ value: Any, anInstanceOf type: T.Type) -> Bool {
4-
value is type // expected-error {{cast expression expects a type on its right-hand side (got: 'type')}}
4+
value is type // expected-error {{type-casting operator expects a type on its right-hand side (got: 'type')}}
55
}
66

77
func foo() -> Int {
@@ -10,7 +10,7 @@ func foo() -> Int {
1010

1111
func badIs_ifdecl<T>(_ value: Any, anInstanceOf type: T.Type) -> Bool {
1212
#if true
13-
value is type // expected-error {{cast expression expects a type on its right-hand side (got: 'type')}}
13+
value is type // expected-error {{type-casting operator expects a type on its right-hand side (got: 'type')}}
1414
#endif
1515
}
1616

test/Parse/omit_return_ifdecl.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2432,7 +2432,7 @@ class CImplicitDotSelfExpr { func gimme() -> CImplicitDotSelfExpr { self.self }
24322432

24332433
func badIs<T>(_ value: Any, anInstanceOf type: T.Type) -> Bool {
24342434
#if true
2435-
value is type // expected-error {{cast expression expects a type on its right-hand side (got: 'type')}}
2435+
value is type // expected-error {{type-casting operator expects a type on its right-hand side (got: 'type')}}
24362436
#endif
24372437
}
24382438

0 commit comments

Comments
 (0)