Lifting an Option with to_option returns it unchanged - #56
Merged
Conversation
to_option lifts a value that may be nil, and an Option is already lifted. Wrapping it again produced Some(Some(x)), which still answers some? and unwraps to an Option, so the nesting surfaced somewhere far from the lift. It shows up wherever a wrapped and an unwrapped source meet — an association that returns nil today, lifted and then reached through for an attribute that is already an Option.
allizad
approved these changes
Aug 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Independent of the #53 → #54 → #55 stack; reviewable on its own.
Lifting an Option nested it
to_optionlifts a value that may be nil. An Option is already lifted, so a second lift producedSome(Some(x)), which still answerssome?and unwraps to an Option. Nothing raised at the lift; the mistake surfaced wherever something later reached for the inner value.Where it shows up
Wherever a wrapped source meets an unwrapped one, which is every partially converted application. The idiom that hits it is lifting an association that returns nil today and then reaching through it for an attribute that is already an Option:
If
widget_snapshotis a plain record that reads fine. Once the model on the other side converts, the same line double-wraps andand_thenhandsSome(record)to a block that expects the record —Errgonomic::UnwrappedAccessError, far from the lift that caused it. The second test in this PR is exactly that shape, and it fails without the fix.Testing
rake— 26 tests, 68 assertions, and 118 doctests, all passing.