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
Extensions on Array that are not referenced in the compile unit may fail to import skip.lib.Array, thus resulting in the wrong Array type being used
#134
Open
marcprux opened this issue
May 30, 2024
· 2 comments
If you have a Swift file with just a single extension on Array (or Collection):
publicextensionArray{func jsonString()->String?{
guard let data =try?JSONSerialization.data(withJSONObject:self, options:.fragmentsAllowed)else{returnnil}returnString(data: data, encoding:.utf8)??nil}}
The resulting Kotlin will not add the explicit import skip.lib.Array line, thus resulting in the extension being incorrectly added to the kotlin.Array, and thereby preventing the extension from being used in the correct way.
For example, the above code will result in the javap -c bytecode:
If the Array type is referenced anywhere in the file, then we will add the explicit import skip.lib.Array line to the transpiled Kotlin, thereby resulting in the expected compiled code:
The symptom will be that the extension will simply not be found in any code that references the extension. The workaround is to simply reference the Array type somewhere in the compile unit, which will trigger Skip to add the explicit skip.lib.Array import. E.g., this will be sufficient:
privatefunc doSomething(array:Array<Int>){}
The text was updated successfully, but these errors were encountered:
If you have a Swift file with just a single extension on
Array
(orCollection
):The resulting Kotlin will not add the explicit
import skip.lib.Array
line, thus resulting in the extension being incorrectly added to thekotlin.Array
, and thereby preventing the extension from being used in the correct way.For example, the above code will result in the
javap -c
bytecode:If the
Array
type is referenced anywhere in the file, then we will add the explicitimport skip.lib.Array
line to the transpiled Kotlin, thereby resulting in the expected compiled code:The symptom will be that the extension will simply not be found in any code that references the extension. The workaround is to simply reference the
Array
type somewhere in the compile unit, which will trigger Skip to add the explicitskip.lib.Array
import. E.g., this will be sufficient:The text was updated successfully, but these errors were encountered: