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

Compiler raises exception for the specific expression of UInt32 enum value #7271

Closed
lugia-kun opened this issue Jan 5, 2019 · 4 comments
Closed
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:semantic

Comments

@lugia-kun
Copy link

For the following Crystal source code, the compiler will raise an exception:

module Tests
  enum Test : UInt32
    VAR = (1 << 31)
  end
end

puts Tests::Test::VAR.value

and backtrace is here:

Using compiled compiler at `.build/crystal'
Invalid UInt32: -2147483648 (ArgumentError)
  from crystal/src/string.cr:0:60 in 'to_u32'
  from crystal/src/compiler/crystal/codegen/codegen.cr:432:17 in 'visit'
  from crystal/src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from crystal/src/compiler/crystal/codegen/codegen.cr:2062:7 in 'accept'
  from crystal/src/compiler/crystal/codegen/const.cr:73:7 in 'initialize_simple_const'
  from crystal/src/compiler/crystal/codegen/codegen.cr:255:11 in 'initialize_simple_class_vars_and_constants'
  from crystal/src/compiler/crystal/codegen/codegen.cr:229:10 in 'initialize'
  from crystal/src/compiler/crystal/codegen/codegen.cr:145:5 in 'new:single_module:debug'
  from crystal/src/compiler/crystal/codegen/codegen.cr:63:7 in 'codegen'
  from crystal/src/compiler/crystal/codegen/codegen.cr:62:5 in 'codegen:debug:single_module'
  from crystal/src/compiler/crystal/compiler.cr:22:7 in 'codegen'
  from crystal/src/compiler/crystal/compiler.cr:153:16 in 'compile'
  from crystal/src/compiler/crystal/command.cr:258:7 in 'compile'
  from crystal/src/compiler/crystal/command.cr:177:14 in 'run_command'
  from crystal/src/compiler/crystal/command.cr:99:7 in 'run'
  from crystal/src/compiler/crystal/command.cr:46:5 in 'run'
  from crystal/src/compiler/crystal/command.cr:45:3 in 'run'
  from crystal/src/compiler/crystal.cr:8:1 in '__crystal_main'
  from crystal/src/crystal/main.cr:97:5 in 'main_user_code'
  from crystal/src/crystal/main.cr:86:7 in 'main'
  from crystal/src/crystal/main.cr:106:3 in 'main'
  from __libc_start_main
  from ../sysdeps/x86_64/start.S:122:0 in '_start'
  from ???
Error: you've found a bug in the Crystal compiler. Please open an issue, including source code that will allow us to reproduce the bug: https://github.com/crystal-lang/crystal/issues

It works fine if give the type explicitly, or, without parentheses:

module Tests
  enum Test : UInt32
    VAR = (1_u32 << 31)
  end
end

puts Tests::Test::VAR.value # => 2147483648
module Tests
  enum Test : UInt32
    VAR = 1 << 31
  end
end

puts Tests::Test::VAR.value # => 2147483648

The output of crystal version is here:

> crystal version
Using compiled compiler at `.build/crystal'
Crystal 0.27.1-dev [fcfb8f71d] (2019-01-04)

LLVM: 6.0.1
Default target: x86_64-unknown-linux-gnu
@bcardiff
Copy link
Member

bcardiff commented Jan 5, 2019

Probably related to #7268

@bew
Copy link
Contributor

bew commented Jan 5, 2019

If we want to fix it one day, I think it can be related to #3803

@RX14
Copy link
Contributor

RX14 commented Jan 5, 2019

@bew I don't follow.

@asterite asterite added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:semantic labels May 13, 2019
@asterite
Copy link
Member

This seems to have been fixed by #7776

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:semantic
Projects
None yet
Development

No branches or pull requests

5 participants