Dmitriy Tarasevich
11/27/2024, 6:26 PMsealed class FooBar {
object Foo : FooBar()
object Bar : FooBar()
}
fun takeFooBar(fooBar: FooBar) {
// TBD
}
fun main() {
// Wasm thinks this is an Any
val bar = if (true) {
FooBar.Foo
} else {
FooBar.Bar
}
takeFooBar(fooBar = bar)
}
ill get an error at runtime like the following
Uncaught (in promise) CompileError: WebAssembly.instantiateStreaming(): Compiling function #144978:"com.package..main..etc..." failed: call[2] expected type (ref null 37332), found local.get of type (ref null 2550) @+32891844
doing a wasm-objdump
i can see that type 2550 is of type Any
and 37332
is type FooBar
I have two ways of making this work by changing the code to either
val bar: FooBar = if (true) {
FooBar.Foo
} else {
FooBar.Bar
}
or
making the FooBar instances a class
sealed class FooBar {
class Foo : FooBar()
class Bar : FooBar()
}
fun takeFooBar(fooBar: FooBar) {
// TBD
}
fun main() {
// This works.
val bar = if (true) {
FooBar.Foo()
} else {
FooBar.Bar()
}
takeFooBar(fooBar = bar)
}
Is this a known issue? is there any work arounds as we use objects a lot in our code base and going through and adding types would be quite a chore.Artem Kobzar
11/27/2024, 6:28 PMDmitriy Tarasevich
11/27/2024, 6:28 PMArtem Kobzar
11/27/2024, 6:28 PMDmitriy Tarasevich
11/27/2024, 6:28 PMDmitriy Tarasevich
11/27/2024, 6:28 PMArtem Kobzar
11/27/2024, 6:28 PMDmitriy Tarasevich
11/27/2024, 7:33 PMkotlin.UninitializedPropertyAccessException: lateinit property body has not been initialized
at org.jetbrains.kotlin.ir.declarations.impl.IrAnonymousInitializerImpl.getBody(IrAnonymousInitializerImpl.kt:37)
ill test it out on a sample i suppose. Any ideas on this error?Artem Kobzar
11/28/2024, 8:29 AMDmitriy Tarasevich
11/28/2024, 12:00 PMArtem Kobzar
11/28/2024, 12:10 PMDmitriy Tarasevich
11/28/2024, 12:11 PM