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

Macro interpreter coerces to Int32 in arithmetic operations #5971

Closed
joatca opened this issue Apr 20, 2018 · 1 comment
Closed

Macro interpreter coerces to Int32 in arithmetic operations #5971

joatca opened this issue Apr 20, 2018 · 1 comment

Comments

@joatca
Copy link

joatca commented Apr 20, 2018

In the following code which attempts to do 64-bit unsigned arithmetic in a macro, values get coerced to Int32 resulting in:

in bug.cr:7: Invalid Int32: 4294967299

macro add
  {% x = 4294967297_u64 %}
  puts "{{ x }}: {{ x.kind }}"
  {% y = x + 2_u64 %}
  puts "{{ y }}: {{ y.kind }}"
  {% z = y + 2_u64 %}
 puts "{{ z }}: {{ z.kind }}"
end

add

Version:
Crystal 0.24.2 (2018-03-19)

LLVM: 6.0.0
Default target: x86_64-pc-linux-gnu

@straight-shoota
Copy link
Member

Reduced example:

{{ (1_u64 + 2_u64).kind }} # => :i32

The reason for this is that NumberLiteral#kind is :int32 by default and not appropriately set in the macro operation.

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

No branches or pull requests

2 participants