Skip to content

Warn when passing a non-optional value to try #require(T?). #620

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

Conversation

grynspan
Copy link
Contributor

@grynspan grynspan commented Aug 20, 2024

This PR adds an overload of try #require() that warns the developer if they pass a non-optional, non-Bool value For example, this code:

let x = 0
let y = try #require(x)

Will produce the diagnostic:

⚠️ '#require(_:_:)' is redundant because 'x' never equals 'nil'

Checklist:

  • Code and documentation should follow the style of the Style Guide.
  • If public symbols are renamed or modified, DocC references should be updated.

This PR adds an overload of `try #require()` that warns the developer if they
pass a non-optional, non-`Bool` value For example, this code:

```swift
let x = 0
let y = try #require(x)
```

Will produce the diagnostic:

> ⚠️ '#require(_:_:)' is redundant because 'x' never equals 'nil'
@grynspan grynspan added enhancement New feature or request public-api Affects public API labels Aug 20, 2024
@grynspan grynspan self-assigned this Aug 20, 2024
@grynspan
Copy link
Contributor Author

@swift-ci please test

@grynspan grynspan changed the base branch from main to main-next August 21, 2024 00:17
@grynspan grynspan merged commit 097db6c into main-next Aug 21, 2024
3 checks passed
@grynspan grynspan deleted the jgrynspan/warn-when-using-require-with-nonoptional-value branch August 21, 2024 00:18
@grynspan grynspan added this to the Swift 6.1 milestone Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request public-api Affects public API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants