Closed austinkline closed 22 minutes ago
I guess that makes sense. For example, Swift also supports unwrapping using casting:
let hello: String??? = "hello"
let something: Any = hello
something as! String // "hello" of type `String`
However, casting to Any
does not:
something as! Any // Optional(Optional(Optional("hello"))) of type `String???`
Then again, the behaviour does not seem to be about existential types, because those are also unwrapped:
protocol I {}
struct S: I {}
let hello: S???? = S()
let something: Any = hello
something as! any I // S() of type `S`, not `Optional(Optional(Optional(S())))` of type `S???`
Why / Impact
Developer convenience
Current Behavior
Dynamic casting (failable casting
as?
, and force castingas!
) an optional value (potentially type-erased to an existential) to a non-optional type currently fails (e.g. failable casting results innil
).Expected Behavior
I expected (but perhaps shouldn't have) that an optional value being casted into a subtype it conforms to would unwrap it. I'm really not sure if this is a bug or if it's expected though
Steps To Reproduce
I've made a repro contract/transactions to demonstrate
https://github.com/austinkline/cadence-burner-bug
Environment