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: Do not cast enum value to i32 if not specified. Fixes #194 #2703

merged 1 commit into from Jun 1, 2016
Changes from all commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.


Just for now

@@ -43,4 +43,9 @@ describe "Type inference: c enum" do
assert_error "lib LibFoo; enum Bar : Float32; X; end; end; LibFoo::Bar::X",
"enum base type must be an integer type"

it "errors if enum value is different from default (Int32) (#194)" do
assert_error "lib LibFoo; enum Bar; X = 0x00000001_u32; end; end; LibFoo::Bar::X",
"enum value must be an Int32"
@@ -564,6 +564,14 @@ module Crystal
if default_value = member.default_value
counter = interpret_enum_value(default_value, enum_base_type)

if default_value.is_a?(Crystal::NumberLiteral)
enum_base_kind = enum_base_type.kind
if (enum_base_kind == :i32) && (enum_base_kind != default_value.kind)
default_value.raise "enum value must be an Int32"

all_value |= counter
const_value =, enum_base_type.kind)
member.default_value = const_value
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.