Skip to content

Commit

Permalink
Showing 2 changed files with 20 additions and 1 deletion.
15 changes: 15 additions & 0 deletions spec/compiler/semantic/instance_var_spec.cr
Original file line number Diff line number Diff line change
@@ -4625,4 +4625,19 @@ describe "Semantic: instance var" do
),
"Can't infer the type of instance variable '@bar' of Foo"
end

it "can't infer type when using operation on const (#4054)" do
assert_error %(
class Foo
BAR = 5
def initialize
@baz = BAR + 5
end
end
Foo.new
),
"Can't infer the type of instance variable '@baz' of Foo"
end
end
6 changes: 5 additions & 1 deletion src/compiler/crystal/semantic/type_lookup.cr
Original file line number Diff line number Diff line change
@@ -81,7 +81,11 @@ class Crystal::Type

case type_var
when Const
node.raise "#{type_var} is not a type, it's a constant"
if @raise
node.raise "#{type_var} is not a type, it's a constant"
else
return nil
end
when Type
return type_var
end

0 comments on commit a2ffa05

Please sign in to comment.