konsoletyper / teavm

Compiles Java bytecode to JavaScript, WebAssembly and C
https://teavm.org
Apache License 2.0
2.64k stars 264 forks source link

Inliner mixes up execution order #330

Closed belowm closed 6 years ago

belowm commented 6 years ago

This java code

final boolean value = dataIn.readBoolean();
final boolean expected = dataIn.readBoolean();
final Path path = readPath( dataIn );
return new BooleanUpdateCommand( path, value, expected );

...yields this javascript code, where the order of the method calls is not preserved

return cancc_BooleanUpdateCommand__init_(cancc_CommandReaderV1_readPath($this, $dataIn), caui_BitInputStream_readBoolean($dataIn), caui_BitInputStream_readBoolean($dataIn));

Unfortunately, I wasn't able to reproduce this in a trivial example.

konsoletyper commented 6 years ago

Can you build TeaVM from latest master and verify the provided fix?

belowm commented 6 years ago

Hello Alexey, thank you very much for looking into this so fast. Unfortunately, the change didn't seem to fix the issue.

I was able to reproduce it in isolation: https://gist.github.com/belowm/379718a5d772fcbb5c32ab9f34ffd2d8

When running this in a JVM , it correctly outputs [0, 1, 2], whereas the emitted JavaScript produces [2, 0, 1].

konsoletyper commented 6 years ago

I commited another fix, it works with your example. Please, try again

belowm commented 6 years ago

Thanks! That fixed the issue.