Skip to content

Commit

Permalink
Fixed #4054: "is not a type, it's a constant" error
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite committed Mar 2, 2017
1 parent 53c8b59 commit a2ffa05
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
15 changes: 15 additions & 0 deletions spec/compiler/semantic/instance_var_spec.cr
Expand Up @@ -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
Expand Up @@ -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
Expand Down

0 comments on commit a2ffa05

Please sign in to comment.