File tree 2 files changed +20
-1
lines changed
src/compiler/crystal/semantic
2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -4625,4 +4625,19 @@ describe "Semantic: instance var" do
4625
4625
) ,
4626
4626
" Can't infer the type of instance variable '@bar' of Foo"
4627
4627
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
4628
4643
end
Original file line number Diff line number Diff line change @@ -81,7 +81,11 @@ class Crystal::Type
81
81
82
82
case type_var
83
83
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
85
89
when Type
86
90
return type_var
87
91
end
You can’t perform that action at this time.
0 commit comments