I found an interesting issue with wasm on 2.0.20
Lets say I have the following code
sealed 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.