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: weird NamedTuple behaviour produces incorrect values #12229

Closed
cyangle opened this issue Jul 9, 2022 · 1 comment · Fixed by #12239
Closed

Interpreter: weird NamedTuple behaviour produces incorrect values #12229

cyangle opened this issue Jul 9, 2022 · 1 comment · Fixed by #12239
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:interpreter

Comments

@cyangle
Copy link
Contributor

cyangle commented Jul 9, 2022

Add explicit type to NamedTuple variable causes issues with Time::Span:

span = 180.days
config = {max_age: span}
config2 : NamedTuple(max_age: Time::Span) = {max_age: span}
puts config.class
puts config[:max_age].to_f
puts config2.class
puts config2[:max_age].to_f

The interpreter produces incorrect max_age for config2.

NamedTuple(max_age: Time::Span)
15552000.0
NamedTuple(max_age: Time::Span)
0.0

The compiled binary produces correct output:

NamedTuple(max_age: Time::Span)
15552000.0
NamedTuple(max_age: Time::Span)
15552000.0

This is a weird bug.

@cyangle cyangle added the kind:bug A bug in the code. Does not apply to documentation, specs, etc. label Jul 9, 2022
@asterite
Copy link
Member

asterite commented Jul 9, 2022

Reduced:

x : Int32 = 1
puts x # prints 0

TypeDeclaration for local variables is completely ignored for the interpreter 🤦‍♂️ 😊

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 a pull request may close this issue.

3 participants