Skip to content

[Diagnostics] Port contextual mismatches involving nil to new frame… #26751

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
Aug 20, 2019

Conversation

xedin
Copy link
Contributor

@xedin xedin commented Aug 20, 2019

…work

Detect and diagnose contextual failures originating in an attempt
to convert nil to some other non-optional type e.g.

let _: Int = nil // can't initialize `Int` with `nil`

func foo() -> Int {
  return nil // can't return `nil` from `foo`
}

_ = 1 + nil // there is no `+` overload which accepts `Int` and optional

@xedin xedin requested a review from hborla August 20, 2019 20:11
@xedin
Copy link
Contributor Author

xedin commented Aug 20, 2019

@swift-ci please smoke test

@xedin
Copy link
Contributor Author

xedin commented Aug 20, 2019

Only CTP_YieldByReference and CTP_ThrowStmt are left.

dict[nil] = a // expected-error {{ambiguous subscript with base type 'NSMutableDictionary' and index type '_'}}
let q = dict[nil] // expected-error {{ambiguous subscript}}
dict[nil] = a // expected-error {{'nil' is not compatible with expected argument type 'NSCopying'}}
let q = dict[nil] // expected-error {{'nil' is not compatible with expected argument type 'NSCopying'}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@@ -2,5 +2,5 @@

func test(_ x: Int) -> Int {
return x + nil
// expected-error@-1 {{type of expression is ambiguous without more context}}
// expected-error@-1 {{'nil' is not compatible with expected argument type 'Int'}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent!

…work

Detect and diagnose contextual failures originating in an attempt
to convert `nil` to some other non-optional type e.g.

```swift
let _: Int = nil // can't initialize `Int` with `nil`

func foo() -> Int {
  return nil // can't return `nil` from `foo`
}

_ = 1 + nil // there is no `+` overload which accepts `Int` and optional
```
@xedin xedin force-pushed the nil-contextual-failures branch from cdcb656 to 0a8f596 Compare August 20, 2019 21:24
@xedin
Copy link
Contributor Author

xedin commented Aug 20, 2019

@swift-ci please smoke test

@xedin xedin merged commit 84d7b60 into swiftlang:master Aug 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants