Skip to content

Commit

Permalink
Fixed #230: must include original def owner in mangled name for corre…
Browse files Browse the repository at this point in the history
…ct results
  • Loading branch information
Ary Borenszweig committed Oct 14, 2014
1 parent 0b9e42c commit d877401
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 1 deletion.
27 changes: 27 additions & 0 deletions spec/compiler/codegen/def_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -494,4 +494,31 @@ describe "Code gen: def" do
method(foo)
").to_i.should eq(1)
end

it "fixes #230: include original owner in mangled def" do
run(%(
class Base
def some(other : self)
false
end
def some(other)
false
end
end
class Foo(T) < Base
def some(other : Foo)
true
end
end
a = Foo(Int32).new
b = Foo(Int32).new || Foo(Int32 | Nil).new || true
a.some(b)
c = Foo(Int32).new
c.some(c)
)).to_b.should be_true
end
end
4 changes: 4 additions & 0 deletions src/compiler/crystal/codegen/ast.cr
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ module Crystal
str << "::"
elsif !owner.is_a?(Crystal::Program)
owner.llvm_name(str)
if original_owner != self_type
str << "@"
original_owner.llvm_name(str)
end
str << "#"
end
end
Expand Down
1 change: 1 addition & 0 deletions src/compiler/crystal/semantic/call.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1158,6 +1158,7 @@ module Crystal

typed_def = untyped_def.clone
typed_def.owner = owner
typed_def.original_owner = untyped_def.owner

if body = typed_def.body
typed_def.bind_to body
Expand Down
2 changes: 2 additions & 0 deletions src/compiler/crystal/semantic/def.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ require "../syntax/ast"
module Crystal
class Def
property! :owner
property! :original_owner
property :vars
property :raises

Expand Down Expand Up @@ -98,6 +99,7 @@ module Crystal
expansion.uses_block_arg = uses_block_arg
expansion.yields = yields
expansion.location = location
expansion.owner = owner?

if retain_body
new_body = [] of ASTNode
Expand Down
6 changes: 5 additions & 1 deletion src/compiler/crystal/types.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1891,7 +1891,11 @@ module Crystal
end

def tuple_indexer(index)
@tuple_indexers[index] ||= Def.new("[]", [Arg.new("index")], TupleIndexer.new(index))
@tuple_indexers[index] ||= begin
indexer = Def.new("[]", [Arg.new("index")], TupleIndexer.new(index))
indexer.owner = self
indexer
end
end

def var
Expand Down

0 comments on commit d877401

Please sign in to comment.