Skip to content

[Diagnostics][Sema] Improving wording same type is check #40811

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -1108,7 +1108,7 @@ WARNING(conditional_downcast_same_type,none,
"bridging conversion; did you mean to use 'as'?}2",
(Type, Type, unsigned))
WARNING(is_expr_same_type,none,
"checking a value with optional type %0 against dynamic type %1 "
"checking a value with optional type %0 against type %1 "
"succeeds whenever the value is non-nil; did you mean to use "
"'!= nil'?", (Type, Type))
WARNING(downcast_to_unrelated,none,
Expand Down
2 changes: 1 addition & 1 deletion test/Constraints/bridging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ func SR15161_as(e: Error?) {
}

func SR15161_is(e: Error?) {
_ = e is NSError // expected-warning{{checking a value with optional type 'Error?' against dynamic type 'NSError' succeeds whenever the value is non-nil; did you mean to use '!= nil'?}}
_ = e is NSError // expected-warning{{checking a value with optional type 'Error?' against type 'NSError' succeeds whenever the value is non-nil; did you mean to use '!= nil'?}}
}

func SR15161_as_1(e: Error?) {
Expand Down
3 changes: 1 addition & 2 deletions test/decl/protocol/protocols.swift
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,7 @@ func h<T : C3>(_ x : T) {
}
func i<T : C3>(_ x : T?) -> Bool {
return x is P1
// FIXME: Bogus diagnostic. See SR-11920.
// expected-warning@-2 {{checking a value with optional type 'T?' against dynamic type 'P1' succeeds whenever the value is non-nil; did you mean to use '!= nil'?}}
// expected-warning@-1 {{checking a value with optional type 'T?' against type 'P1' succeeds whenever the value is non-nil; did you mean to use '!= nil'?}}
}
func j(_ x : C1) -> Bool {
return x is P1
Expand Down
4 changes: 2 additions & 2 deletions test/expr/cast/bridged.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ func testBridgeDowncastExact(_ obj: BridgedClass, objOpt: BridgedClass?,
_ = objImplicitOpt as! BridgedStruct // expected-warning{{forced cast from 'BridgedClass?' to 'BridgedStruct' only unwraps and bridges; did you mean to use '!' with 'as'?}}{{21-21=!}}{{22-25=as}}

_ = obj is BridgedStruct // expected-warning{{'is' test is always true}}
_ = objOpt is BridgedStruct // expected-warning{{checking a value with optional type 'BridgedClass?' against dynamic type 'BridgedStruct' succeeds whenever the value is non-nil; did you mean to use '!= nil'?}}{{14-30=!= nil}}
_ = objImplicitOpt is BridgedStruct // expected-warning{{checking a value with optional type 'BridgedClass?' against dynamic type 'BridgedStruct' succeeds whenever the value is non-nil; did you mean to use '!= nil'?}}{{22-38=!= nil}}
_ = objOpt is BridgedStruct // expected-warning{{checking a value with optional type 'BridgedClass?' against type 'BridgedStruct' succeeds whenever the value is non-nil; did you mean to use '!= nil'?}}{{14-30=!= nil}}
_ = objImplicitOpt is BridgedStruct // expected-warning{{checking a value with optional type 'BridgedClass?' against type 'BridgedStruct' succeeds whenever the value is non-nil; did you mean to use '!= nil'?}}{{22-38=!= nil}}
}

func testExplicitBridging(_ object: BridgedClass, value: BridgedStruct) {
Expand Down
4 changes: 2 additions & 2 deletions test/expr/cast/optional.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ func f1(i: Int?, ii: Int??, a: [Base]?, d: [Base : Base]?, de: Derived?) {
_ = de as? Base // expected-warning{{conditional downcast from 'Derived?' to 'Base' is equivalent to an implicit conversion to an optional 'Base'}}{{9-18=}}

// "is" checks
_ = i is Int // expected-warning{{checking a value with optional type 'Int?' against dynamic type 'Int' succeeds whenever the value is non-nil; did you mean to use '!= nil'?}}{{9-15=!= nil}}
_ = i..<1 is Int // expected-warning{{checking a value with optional type 'Int?' against dynamic type 'Int' succeeds whenever the value is non-nil; did you mean to use '!= nil'?}}{{7-7=(}}{{12-12=)}}{{13-19=!= nil}}
_ = i is Int // expected-warning{{checking a value with optional type 'Int?' against type 'Int' succeeds whenever the value is non-nil; did you mean to use '!= nil'?}}{{9-15=!= nil}}
_ = i..<1 is Int // expected-warning{{checking a value with optional type 'Int?' against type 'Int' succeeds whenever the value is non-nil; did you mean to use '!= nil'?}}{{7-7=(}}{{12-12=)}}{{13-19=!= nil}}
_ = ii is Int

_ = i..<1 is Bool // expected-warning{{cast from 'Int?' to unrelated type 'Bool' always fails}}
Expand Down