Type-inference tests fail with inheritance test
I get the following error:
1/2 Test #738: tests/negative/inheritance-test.toit ... Passed 0.07 sec
1137: fatal: didn't expect 24 at 3238
The test fails here: https://github.com/toitlang/toit/blob/a8a5a92a23abbc9db6cd09df7959f1700e1c9237/tests/toitdoc/inheritance.toit#L46
Run with:
git checkout type-inference-test-failure
rm -rf build/host--ctp
LOCAL_CXXFLAGS="-O0" make HOST=host-ctp TOOLCHAIN=host TOIT_CHECK_PROPAGATED_TYPES=1 sdk
ctest --test-dir build/host-ctp --verbose -C slow -R toitdoc/inheritance-test
The LOCAL_CXXFLAGS="-O0" is optional.
Once fixed please change the code (master/PR) back to using a block.
Looking into this now.
Running:
$ build/host/sdk/bin/toit.compile -w snapshot -Xpropagate tests/toitdoc/inheritance-test.toit
$ build/host-ctp/sdk/bin/toit.run snapshot
leads to the fatal: didn't expect 24 at 3238 message. Digging into the snapshot, we see that class 24 is String_:
$ build/host/sdk/bin/toit.run tools/toitp.toit -c snapshot
Classes[63]:
0: Object /Users/kasper/Toit/toitlang.org/toit/build/host/sdk/lib/core/objects.toit:14:7
...
24: String_ /Users/kasper/Toit/toitlang.org/toit/build/host/sdk/lib/core/string.toit:1368:7
...
The bytecode at 3238 is loading an outer local in a block from within parse-module:
$ build/host/sdk/bin/toit.run tools/toitp.toit -bc snapshot
...
3233: [block] in parse-module tests/toitdoc/inheritance.toit:46:19
0/3237 [016] - load local 2
1/3238 [005] - load outer S4
3/3240 [083] - branch if false T139
...
The corresponding source code is:
finish-class := :
if current-class-name:
So we infer that current-class-name cannot be a string, but yet it is. The propagated types confirm this:
$ build/host/sdk/bin/toit.compile -w snapshot -Xpropagate tests/toitdoc/inheritance-test.toit > types.txt
$ build/host/sdk/bin/toit.run tools/dump_types.toit --snapshot snapshot --types types.txt
...
[block] in parse-module tests/toitdoc/inheritance.toit
- argument 0: [block]
0[016] - load local 2
1[005] - load outer S4 // {Null_}
3[083] - branch if false T139
...
Now looking into what may cause us to not see the assignment to the local -- or to not reanalyze the block after the type information has been extended.
This smaller example illustrates the problem:
main:
x := null
b := : if x: print "hello"
x = 1
b.call
The assignment to x does not force us to re-analyze the b block, but it really should.
Addressed by #2597.