You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[pigeon] Remove most use of safe casting in Swift and Kotlin generators #116999
Currently we have a lot of deserialization casts that are using as?, such as (from the AllTypes Swift code):
let aBool = list[0] as? Bool
let anInt = list[1] as? Int32
let aDouble = list[2] as? Double
...
Because that wouldn't compile for non-nullable fields (since as? returns nil/null on failure), the non-nullable version looks like:
let aBool = list[0] as! Bool
let anInt = list[1] as! Int32
let aDouble = list[2] as! Double
(Similar for Kotlin, but with as.)
The former isn't right though; if a field is supposed to be a Bool?, but we somehow send, say, a Double, we shouldn't treat it as a null Bool?, we should explode because something has gone terribly wrong.
This should let us eliminate a lot of branching in the generators for this part of the code, since we should always do as! (or as) with the full type. I.e., the nullable AllTypes code in Swift should be:
let aBool = list[0] as! Bool?
let anInt = list[1] as! Int32?
let aDouble = list[2] as! Double?
...
See also #116972, but this is distinct because we are actually actually silently masking any error that happens here, rather than just doing extra work.
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.
Activity
github-actions commentedon Mar 14, 2023
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.