Skip to content

Silence a warning on the latest 6.2-dev toolchain when building a test. #969

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
Feb 20, 2025

Conversation

grynspan
Copy link
Contributor

@grynspan grynspan commented Feb 20, 2025

We are getting a (sort of spurious but also not really) warning when building a test where we have a particularly weird bit of code:

func f() -> Never? { nil }
try #require(f()) // ⚠️ warning: will never be executed

The code in question will be executed, but will always throw an ExpectationFailedError. The compiler's getting a bit confused because the expansion of the macro includes a call to a function that returns T, where T is the type of the expression being unwrapped. Since T is Never in this context, the compiler infers that that function does not return. The compiler's inference is correct, but it's unclear what exactly it thinks will never be executed here.

In any event, the warning is spurious and does not indicate a problem with the test, so I'm changing the return type of the problematic function from Never? to Int? to make the compiler happy.

Checklist:

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

We are getting a (sort of spurious but also not really) warning when building a
test where we have a particularly weird bit of code:

```swift
func f() -> Never? { nil }
try #require(f()) // ⚠️ warning: will never be executed
```

The code in question _will_ be executed, but will always throw an
`ExpectationFailedError`. The compiler's getting a bit confused because the
expansion of the macro includes a call to a function that returns `T`, where
`T` is the type of the expression being unwrapped. Since `T` is `Never` in this
context, the compiler infers that that function does not return. The compiler's
inference is correct, but it's unclear what exactly it thinks will never be
executed here.

In any event, the warning is spurious and does not indicate a problem with the
test, so I'm changing the return type of the problematic function from `Never?`
to `Int?` to make the compiler happy.
@grynspan grynspan added bug 🪲 Something isn't working workaround Workaround for an issue in another component (may need to revert later) labels Feb 20, 2025
@grynspan grynspan added this to the Swift 6.x milestone Feb 20, 2025
@grynspan grynspan self-assigned this Feb 20, 2025
@grynspan
Copy link
Contributor Author

@swift-ci test

@grynspan grynspan merged commit e76a44f into main Feb 20, 2025
3 checks passed
@grynspan grynspan deleted the jgrynspan/silence-optional-never-warning branch February 20, 2025 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🪲 Something isn't working workaround Workaround for an issue in another component (may need to revert later)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants