Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type-inference tests fail with inheritance test #2439

Open
floitsch opened this issue Jul 19, 2024 · 5 comments
Open

Type-inference tests fail with inheritance test #2439

floitsch opened this issue Jul 19, 2024 · 5 comments
Assignees

Comments

@floitsch
Copy link
Member

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
@floitsch
Copy link
Member Author

The test fails here:

finish-class := :

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.

@floitsch
Copy link
Member Author

Once fixed please change the code (master/PR) back to using a block.

@kasperl
Copy link
Member

kasperl commented Oct 7, 2024

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.

@kasperl
Copy link
Member

kasperl commented Oct 7, 2024

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.

@kasperl
Copy link
Member

kasperl commented Oct 22, 2024

Addressed by #2597.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants