Skip to content

[SR-184] Better diagnose error via unwrapping optional before initialized. #418

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
Dec 11, 2015

Conversation

gregomni
Copy link
Contributor

Added a check for whether the escape use is due to an UncheckedTakeEnumDataAddrInst, which accesses the memory to grab the .Some part of an Optional during “?.” or “!”. In that case, use the
generic used-before-initialized diagnostic, since it isn’t actually because of closure capture.

Added test cases, including specifically testing that capturing in a closure in order to unwrap the optional is still ok.

…zed.

Added a check for whether the escape use is due to an
UncheckedTakeEnumDataAddrInst, which accesses the memory to grab the
.Some part of an Optional during “?.” or “!”. In that case, use the
generic used-before-initialized diagnostic, since it isn’t actually
because of closure capture.

Added test cases, including specifically testing that capturing in a
closure in order to unwrap the optional is still ok.
@gregomni
Copy link
Contributor Author

Tests pass! I initially thought that the last-resort else here might just be mistaken, and should be the generic used-before-initialized diagnostic instead, but that fails definite_init_diagnostics.swift:65 (capturing an Int to increment it before initialization). So added the more specific check for unchecked_take_enum_data_addr instead.

@gregomni
Copy link
Contributor Author

Oh, and would be happy to add a more specific "optional unwrapped before initialized" diagnostic if that sounds like a good idea. The existing "used before being initialized" seems accurate, if inexact, and I think is quite clear enough.

@slavapestov
Copy link
Contributor

@rudkx Looks good to me.

slavapestov added a commit that referenced this pull request Dec 11, 2015
[SR-184] Better diagnose error via unwrapping optional before initialized.
@slavapestov slavapestov merged commit cdaff82 into swiftlang:master Dec 11, 2015
@lattner
Copy link
Contributor

lattner commented Dec 11, 2015

Nice!

@gregomni gregomni deleted the sr-184 branch May 30, 2016 01:12
kateinoigakukun pushed a commit to kateinoigakukun/swift that referenced this pull request Mar 20, 2020
freak4pc pushed a commit to freak4pc/swift that referenced this pull request Sep 28, 2022
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.

3 participants