Skip to content

Optional shared value subscript to optional shared nested value #116

Answered by mbrandonw
Pomanks asked this question in Q&A
Discussion options

You must be logged in to vote

Ah I see, sorry I misread that.

What you are trying to do isn't really possible. Suppose you could get a bar: Shared<Bar?> from a foo: Shared<Foo?>, and suppose that the foo was currently nil. What would happen if you wrote a non-nil value to the bar? It would somehow need to construct a Foo and stick the bar into it, which can't happen generically. So it would have no choice but to discard that value and keep bar as nil.

It's worth mentioning that this is a bit different from the behavior of foo?.bar. Because clearly one can do foo?.bar = Bar() even with foo is nil, and the Bar() is just discarded. But at least at the call site you can plainly see foo? so you know an optional is involved…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@Pomanks
Comment options

@mbrandonw
Comment options

Answer selected by Pomanks
@Pomanks
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants