Skip to content

[SR-839][Sema] Better fixits for optional expressions #1504

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
Mar 5, 2016

Conversation

gregomni
Copy link
Contributor

@gregomni gregomni commented Mar 2, 2016

In member ref expressions, if the base is optional, and the expected expression result is either optional or unknown, suggest a fixit that makes it into an optional chain expr rather than force unwrapping.

Since in many cases the actual fixit is emitted during diagnosis, and thus, while type checking sub exprs with no contextual type specified (so nothing to check for preferring optionality), we also need an additional flag to pass down from FailureDiagnosis for whether we prefer to fix as force unwrapping or optional chaining.

I attempted to do this same job via providing a convert type but setting the ConvertTypeIsOnlyAHint flag on the type checker, but unfortunately there are a lot of other moving parts that look at that type, even if it is only supposed to be a hint, so an additional flag to the CS ended up being cleaner.

In member ref expressions, if the base is optional, and the expected
expression result is either optional or unknown, suggest a fixit that
makes it into an optional chain expr rather than force unwrapping.

Since in many cases the actual fixit is emitted during diagnosis, and
thus, while type checking sub exprs with no contextual type specified
(so nothing to check for preferring optionality), we also need an
additional flag to pass down from FailureDiagnosis for whether we
prefer to fix as force unwrapping or optional chaining.

I attempted to do this same job via providing a convert type but
setting the ConvertTypeIsOnlyAHint flag on the type checker, but
unfortunately there are a lot of other moving parts that look at that
type, even if it is only supposed to be a hint, so an additional flag
to the CS ended up being cleaner.
@gribozavr
Copy link
Contributor

@swift-ci Please test

gregomni added a commit that referenced this pull request Mar 5, 2016
[SR-839][Sema] Better fixits for optional expressions
@gregomni gregomni merged commit f6c5981 into swiftlang:master Mar 5, 2016
@gregomni gregomni deleted the sr-839 branch March 5, 2016 02:16
kateinoigakukun pushed a commit to kateinoigakukun/swift that referenced this pull request Sep 7, 2020
…xctest

Build Foundation/XCTest for the 5.3 branch
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.

2 participants