Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions spec/compiler/semantic/enum_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,14 @@ describe "Semantic: enum" do
CRYSTAL
end

it "reports arithmetic overflow in enum value expression (#11746)" do
assert_error <<-CRYSTAL, "Arithmetic overflow", inject_primitives: true
enum Foo : UInt64
A = 0_u64 - 1_u64
end
CRYSTAL
end

it "errors if using instance var inside enum (#991)" do
assert_error <<-CRYSTAL, "can't use instance variables inside enums (at enum Foo)"
enum Foo
Expand Down
7 changes: 7 additions & 0 deletions spec/compiler/semantic/static_array_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,11 @@ describe "Semantic: static array" do
alias BadArray = Int32[offsetof(Foo, @foo)]
CRYSTAL
end

it "reports arithmetic overflow in static array size argument (#11746)" do
assert_error <<-CRYSTAL, "Arithmetic overflow", inject_primitives: true
A = 0_u64 - 1_u64
b = StaticArray(Int32, A).new
CRYSTAL
end
end
2 changes: 2 additions & 0 deletions src/compiler/crystal/semantic/math_interpreter.cr
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ struct Crystal::MathInterpreter
else
interpret_call_macro(node)
end
rescue ex : OverflowError | DivisionByZeroError
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: We should really have a common parent type for these arithmetic error type (cf. #11639).

node.raise ex.message
end

def interpret_call_macro(node : Call)
Expand Down
Loading