Skip to content

[5.3][CSGen] Check whether parent has a contextual type before diagnosing nil use #34060

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
Sep 25, 2020

Conversation

xedin
Copy link
Contributor

@xedin xedin commented Sep 24, 2020

Cherry-pick of #34046


  • Explanation

Before considering nil to be used without a context, let's
check whether parent expression (semantic significance of
which is not important) has a contextual type associated with it,
otherwise it's possible to misdiagnose cases like:

func test() -> Int? {
  return (nil)
}
  • Scope: Limited to nil literals wrapped into parens or other non-semantic expressions e.g. await, try used return statements.

  • Resolves: rdar://problem/69454410

  • Risk: Low

  • Testing: Added regression tests

  • Reviewer: @hborla, @CodaFi

Resolves: rdar://problem/69454410

(cherry picked from commit 90e6fd4)

…`nil` use

Before considering `nil` to be used without a context, let's
check whether parent expression (semantic significance of
which is not important) has a contextual type associated with it,
otherwise it's possible to misdiagnose cases like:

```swift
func test() -> Int? {
  return (nil)
}
```

(cherry picked from commit 90e6fd4)
@xedin xedin requested a review from a team as a code owner September 24, 2020 17:48
@xedin
Copy link
Contributor Author

xedin commented Sep 24, 2020

@swift-ci please test

@xedin
Copy link
Contributor Author

xedin commented Sep 25, 2020

@swift-ci please test Linux platform

@xedin
Copy link
Contributor Author

xedin commented Sep 25, 2020

@swift-ci please test macOS platform

@xedin xedin merged commit 9348907 into swiftlang:release/5.3 Sep 25, 2020
@AnthonyLatsis AnthonyLatsis added swift 5.3 🍒 release cherry pick Flag: Release branch cherry picks and removed r5.3 labels Jan 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍒 release cherry pick Flag: Release branch cherry picks swift 5.3
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants