-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[pigeon] removes safe casting from nullables in kotlin and swift #3284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1f893d7
4331ba1
2772e95
a6fe0b3
1ac0aee
8d4cba5
307128f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
// | ||
// Autogenerated from Pigeon (v9.0.1), do not edit directly. | ||
// Autogenerated from Pigeon (v9.0.2), do not edit directly. | ||
// See also: https://pub.dev/packages/pigeon | ||
|
||
package com.example.test_plugin | ||
|
@@ -109,22 +109,22 @@ data class AllNullableTypes ( | |
companion object { | ||
@Suppress("UNCHECKED_CAST") | ||
fun fromList(list: List<Any?>): AllNullableTypes { | ||
val aNullableBool = list[0] as? Boolean | ||
val aNullableInt = list[1].let { if (it is Int) it.toLong() else it as? Long } | ||
val aNullableDouble = list[2] as? Double | ||
val aNullableByteArray = list[3] as? ByteArray | ||
val aNullable4ByteArray = list[4] as? IntArray | ||
val aNullable8ByteArray = list[5] as? LongArray | ||
val aNullableFloatArray = list[6] as? DoubleArray | ||
val aNullableList = list[7] as? List<Any?> | ||
val aNullableMap = list[8] as? Map<Any, Any?> | ||
val nullableNestedList = list[9] as? List<List<Boolean?>?> | ||
val nullableMapWithAnnotations = list[10] as? Map<String?, String?> | ||
val nullableMapWithObject = list[11] as? Map<String?, Any?> | ||
val aNullableEnum: AnEnum? = (list[12] as? Int)?.let { | ||
val aNullableBool = list[0] as Boolean? | ||
val aNullableInt = list[1].let { if (it is Int) it.toLong() else it as Long? } | ||
val aNullableDouble = list[2] as Double? | ||
val aNullableByteArray = list[3] as ByteArray? | ||
val aNullable4ByteArray = list[4] as IntArray? | ||
val aNullable8ByteArray = list[5] as LongArray? | ||
val aNullableFloatArray = list[6] as DoubleArray? | ||
val aNullableList = list[7] as List<Any?>? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i'm curious - in Kotlin, can There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nope |
||
val aNullableMap = list[8] as Map<Any, Any?>? | ||
val nullableNestedList = list[9] as List<List<Boolean?>?>? | ||
val nullableMapWithAnnotations = list[10] as Map<String?, String?>? | ||
val nullableMapWithObject = list[11] as Map<String?, Any?>? | ||
val aNullableEnum: AnEnum? = (list[12] as Int?)?.let { | ||
AnEnum.ofRaw(it) | ||
} | ||
val aNullableString = list[13] as? String | ||
val aNullableString = list[13] as String? | ||
return AllNullableTypes(aNullableBool, aNullableInt, aNullableDouble, aNullableByteArray, aNullable4ByteArray, aNullable8ByteArray, aNullableFloatArray, aNullableList, aNullableMap, nullableNestedList, nullableMapWithAnnotations, nullableMapWithObject, aNullableEnum, aNullableString) | ||
} | ||
} | ||
|
@@ -179,7 +179,7 @@ data class TestMessage ( | |
companion object { | ||
@Suppress("UNCHECKED_CAST") | ||
fun fromList(list: List<Any?>): TestMessage { | ||
val testList = list[0] as? List<Any?> | ||
val testList = list[0] as List<Any?>? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The kotlin version is still There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Swift optional Any causes issues with force casting into optional types when the data is nil. Kotlin doesn't have that problem. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Not sure if I follow this. Can you share a short code snippet when it fails? Are you talking about this following scenario?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is the scenario that was happening before. The only difference now is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting. This scenario actually did not crash when I try it on the playground. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The core answer here is that This Kotlin code:
prints
but this Swift code:
prints
We're generating different code because the expression of "any type, including nullable types" is different in the two languages. (I wasn't aware of this difference when reviewing the initial generator code, so didn't catch the incorrect use of |
||
return TestMessage(testList) | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,7 @@ class AllDatatypesTests: XCTestCase { | |
|
||
func testAllEquals() throws { | ||
let everything = AllNullableTypes( | ||
aNullableBool: false, | ||
aNullableBool: true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. were you able to resolve the Bool type issue the other day? What was the fix? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. switching from Any? to Any There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you provide more details? Not sure which There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's the same decode issue as the other comments I've replied to |
||
aNullableInt: 1, | ||
aNullableDouble: 2.0, | ||
aNullableByteArray: FlutterStandardTypedData(bytes: "1234".data(using: .utf8)!), | ||
|
Uh oh!
There was an error while loading. Please reload this page.