File tree 4 files changed +28
-1
lines changed
4 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,20 @@ describe "Semantic: uninitialized" do
41
41
" can't declare variable of generic non-instantiated type Foo"
42
42
end
43
43
44
+ it " errors if declaring generic type without type vars (with class var)" do
45
+ assert_error %(
46
+ class Foo(T)
47
+ end
48
+
49
+ class Bar
50
+ @@x = uninitialized Foo
51
+ end
52
+
53
+ Bar.new
54
+ ) ,
55
+ " can't declare variable of generic non-instantiated type Foo"
56
+ end
57
+
44
58
it " errors if declares var and then assigns other type" do
45
59
assert_error %(
46
60
x = uninitialized Int32
Original file line number Diff line number Diff line change @@ -128,4 +128,14 @@ describe "Semantic: var" do
128
128
) ,
129
129
" variable 'a' already declared"
130
130
end
131
+
132
+ it " errors if declaring generic type without type vars (with local var)" do
133
+ assert_error %(
134
+ class Foo(T)
135
+ end
136
+
137
+ x : Foo
138
+ ) ,
139
+ " can't declare variable of generic non-instantiated type Foo"
140
+ end
131
141
end
Original file line number Diff line number Diff line change @@ -363,7 +363,8 @@ module Crystal
363
363
check_not_a_constant(node.declared_type)
364
364
365
365
if declared_type = node.declared_type.type?
366
- meta_var.freeze_type = declared_type
366
+ var_type = check_declare_var_type node, declared_type, " a variable"
367
+ meta_var.freeze_type = var_type
367
368
else
368
369
node.raise " can't infer type of type declaration"
369
370
end
Original file line number Diff line number Diff line change @@ -1413,6 +1413,8 @@ module Crystal
1413
1413
var.name.size
1414
1414
when InstanceVar
1415
1415
var.name.size
1416
+ when ClassVar
1417
+ var.name.size
1416
1418
else
1417
1419
raise " can't happen"
1418
1420
end
You can’t perform that action at this time.
0 commit comments