Skip to content

Commit a2ffa05

Browse files
author
Ary Borenszweig
committedMar 2, 2017
Fixed #4054: "is not a type, it's a constant" error
1 parent 53c8b59 commit a2ffa05

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed
 

Diff for: ‎spec/compiler/semantic/instance_var_spec.cr

+15
Original file line numberDiff line numberDiff line change
@@ -4625,4 +4625,19 @@ describe "Semantic: instance var" do
46254625
),
46264626
"Can't infer the type of instance variable '@bar' of Foo"
46274627
end
4628+
4629+
it "can't infer type when using operation on const (#4054)" do
4630+
assert_error %(
4631+
class Foo
4632+
BAR = 5
4633+
4634+
def initialize
4635+
@baz = BAR + 5
4636+
end
4637+
end
4638+
4639+
Foo.new
4640+
),
4641+
"Can't infer the type of instance variable '@baz' of Foo"
4642+
end
46284643
end

Diff for: ‎src/compiler/crystal/semantic/type_lookup.cr

+5-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,11 @@ class Crystal::Type
8181

8282
case type_var
8383
when Const
84-
node.raise "#{type_var} is not a type, it's a constant"
84+
if @raise
85+
node.raise "#{type_var} is not a type, it's a constant"
86+
else
87+
return nil
88+
end
8589
when Type
8690
return type_var
8791
end

0 commit comments

Comments
 (0)
Please sign in to comment.