> On Dec 5, 2017, at 1:13 PM, Thorsten Seitz via swift-evolution 
> <swift-evolution@swift.org> wrote:
> 
> let result = dynamic x.foo.bar  // will crash if foo or bar are not present
> 
> let result = dynamic? x.foo.bar // will return nil if foo or bar are not 
> present
> 
> // will crash if foo or bar are not present
> let result = dynamic {
>       let y = x.foo.bar
>       let z = y.baz(42)
>       return z.zork()
> }
> 
> // will return nil if foo or bar are not present
> let result = dynamic? {
>       let y = x.foo.bar
>       let z = y.baz(42)
>       return z.zork()
> } 

As other people have pointed out, the behavior of something conforming to these 
protocols in no way implies that they crash if lookup fails. That is up to the 
implementer, and I assume most, if not all, will choose sane defaults 
(optional/throws) rather than just crashing.

But I think the main thing missing from this is where `x` came from. As I think 
Chris pointed out before, these values have to come from somewhere. If you have 
no idea what the type of the variable you're dealing with is and what its 
intended behavior might be, then I don't understand how you could even write 
this code in the first place.
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to