Forum | Documentation | Website | Blog

Skip to content
Snippets Groups Projects
Commit 81e70f7f authored by Ary Borenszweig's avatar Ary Borenszweig
Browse files

Fixed another issue with declaring instance vars in initialize

parent 26486a39
No related merge requests found
......@@ -709,4 +709,21 @@ describe "Type inference: class" do
),
"type vars must be A, B, not C"
end
it "allows declaring a variable in an initialize and using it" do
assert_type(%(
class Foo
def initialize
@x :: Int32
@x + 1
end
def x
@x
end
end
Foo.new.x
)) { int32 }
end
end
......@@ -238,7 +238,12 @@ module Crystal
ivar = lookup_instance_var var
ivar.bind_to node
var.bind_to node
if @is_initialize
@vars[var.name] = MetaVar.new(var.name, node.type)
end
end
case type
when NonGenericClassType
node.declared_type.accept self
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment