Skip to content

Commit 7df08f8

Browse files
[Sema][test] Add SR-13899 test cases
1 parent 19727f2 commit 7df08f8

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1075,7 +1075,7 @@ bool MissingExplicitConversionFailure::diagnoseAsError() {
10751075
} else {
10761076
// Emit error diagnostic.
10771077
emitDiagnostic(diag::cannot_coerce_to_type, fromType, toType);
1078-
// Emit and return note suggesting as! where the fixit will be placed.
1078+
// Emit and return note suggesting as! where the fix-it will be placed.
10791079
return emitDiagnostic(diag::missing_forced_downcast);
10801080
}
10811081
};

test/expr/cast/as_coerce.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,16 @@ _ = sr6022 as! AnyObject // expected-warning {{forced cast from '() -> Any' to '
141141
_ = sr6022 as? AnyObject // expected-warning {{conditional cast from '() -> Any' to 'AnyObject' always succeeds}}
142142
_ = sr6022_1 as! Any // expected-warning {{forced cast from '() -> ()' to 'Any' always succeeds; did you mean to use 'as'?}}
143143
_ = sr6022_1 as? Any // expected-warning {{conditional cast from '() -> ()' to 'Any' always succeeds}}
144+
145+
// SR-13899
146+
let any: Any = 1
147+
if let int = any as Int { // expected-error {{'Any' is not convertible to 'Int'}}
148+
// expected-note@-1 {{did you mean to use 'as?' to conditionally downcast?}} {{18-20=as?}}
149+
}
150+
151+
let _ = any as Int // expected-error {{'Any' is not convertible to 'Int'}}
152+
// expected-note@-1 {{did you mean to use 'as!' to force downcast?}} {{13-15=as!}}
153+
let _: Int = any as Int // expected-error {{'Any' is not convertible to 'Int'}}
154+
// expected-note@-1 {{did you mean to use 'as!' to force downcast?}} {{18-20=as!}}
155+
let _: Int? = any as Int // expected-error {{'Any' is not convertible to 'Int'}}
156+
// expected-note@-1 {{did you mean to use 'as?' to conditionally downcast?}} {{19-21=as?}}

0 commit comments

Comments
 (0)