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

Interpreter (repl): migrate types even if their size remains the same #12581

Merged
merged 3 commits into from
Oct 11, 2022

Conversation

asterite
Copy link
Member

@asterite asterite commented Oct 9, 2022

This is a small fix to the repl. Hopefully we can include it for 1.6.1.

Here's the problem:

$ crystal i
icr:1:0> a = [1, 2, 3]
=> [1, 2, 3]
icr:2:0> a = "hello"
BUG: can't change type of local variable a from Array(Int32) to (Array(Int32) | String) yet (Exception)

The problem is that the repl will migrate the type of local variables if their "codegen" size changes. However, here the type changes from a reference type to a union of reference types, but that union representation's size is the same (it's just a pointer.) But the types should still be migrated (the old type must be changed to the new type.)

This PR fixes that. It now works like this:

$ bin/crystal i
Using compiled compiler at .build/crystal
icr:1:0> a = [1, 2, 3]
=> [1, 2, 3]
icr:2:0> a = "hello"
=> "hello"
icr:3:0> a
=> "hello"
icr:4:0> exit

@asterite asterite added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:interpreter labels Oct 9, 2022
@straight-shoota straight-shoota added this to the 1.6.1 milestone Oct 10, 2022
@straight-shoota straight-shoota merged commit e22a23e into master Oct 11, 2022
@straight-shoota straight-shoota deleted the bug/repl-change-type-same-size branch October 11, 2022 22:52
lbguilherme pushed a commit to lbguilherme/crystal that referenced this pull request Oct 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:interpreter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants