Skip to content

Diagnose ambiguous uses of #require() with an argument of type Bool?.#276

Merged
grynspan merged 4 commits intomainfrom
jgrynspan/105727852-diagnose-ambiguous-require-bool
Mar 11, 2024
Merged

Diagnose ambiguous uses of #require() with an argument of type Bool?.#276
grynspan merged 4 commits intomainfrom
jgrynspan/105727852-diagnose-ambiguous-require-bool

Conversation

@grynspan
Copy link
Contributor

@grynspan grynspan commented Mar 8, 2024

This PR adds new diagnostics when #require() is passed an argument of type Bool? because such an argument may be ambiguously interpreted. If the test author writes:

try #require(love?.isFleeting)

Do they mean to unwrap the optional boolean value and return it, or do they mean to test if isFleeting is true or false?

With this change, an expression such as that one that returns a value of type Bool? will produce a diagnostic of the form:

Screenshot 2024-03-08 at 4 41 30 PM

(The diagnostics are presented as fix-its in Xcode.)

Resolves rdar://105727852.

Checklist:

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

…l?`.

This PR adds new diagnostics when `#require()` is passed an argument of type
`Bool?` because such an argument may be ambiguously interpreted. If the test
author writes:

```swift
try #require(love?.isFleeting)
```

Do they mean to unwrap the optional boolean value and return it, or do they mean
to test if `isFleeting` is true or false?

With this change, an expression such as that one that returns a value of type
`Bool?` will produce a diagnostic of the form:

<SCRN>

Resolves rdar://105727852.
@grynspan grynspan added enhancement New feature or request public-api Affects public API labels Mar 8, 2024
@grynspan grynspan self-assigned this Mar 8, 2024
@grynspan
Copy link
Contributor Author

grynspan commented Mar 8, 2024

@swift-ci please test

@grynspan
Copy link
Contributor Author

grynspan commented Mar 8, 2024

@swift-ci please test

@grynspan
Copy link
Contributor Author

grynspan commented Mar 8, 2024

@swift-ci please test

@grynspan
Copy link
Contributor Author

@swift-ci please test

@grynspan grynspan merged commit 3a77507 into main Mar 11, 2024
@grynspan grynspan deleted the jgrynspan/105727852-diagnose-ambiguous-require-bool branch March 11, 2024 17:57
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.

4 participants