Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Don't check call of non-self instance when computing read instance va…
…rs. Fixes #4830
  • Loading branch information
asterite committed Sep 7, 2017
1 parent 16be884 commit 19bb517
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
25 changes: 25 additions & 0 deletions spec/compiler/semantic/instance_var_spec.cr
Expand Up @@ -4707,4 +4707,29 @@ describe "Semantic: instance var" do
),
"can't use instance variables at the top level"
end

it "doesn't check call of non-self instance (#4830)" do
assert_type(%(
class Container
def initialize(other : Container, x)
initialize(other)
@foo = "x"
end
def initialize(other : Container)
@foo = other.foo
end
def initialize(@foo : String, bar)
end
def foo
@foo
end
end
container = Container.new("foo", nil)
Container.new(container, "foo2")
)) { types["Container"] }
end
end
5 changes: 5 additions & 0 deletions src/compiler/crystal/semantic/main_visitor.cr
Expand Up @@ -1578,6 +1578,11 @@ module Crystal
return false
end

if obj && !(obj.is_a?(Var) && obj.name == "self")
# not a self-instance method: only verify arguments
return true
end

visited = @visited

node.target_defs.try &.each do |target_def|
Expand Down

0 comments on commit 19bb517

Please sign in to comment.