Forum | Documentation | Website | Blog

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

Fixed #91: bind fun pointer to its associated call

parent 8317fa41
Branches
Tags
No related merge requests found
......@@ -120,4 +120,27 @@ describe "Code gen: fun" do
c.call(pointerof(a))
").to_i.should eq(1)
end
it "binds function pointer to associated call" do
run("
class A
def initialize(@e : Int32)
end
def on_something
@e
end
end
def _on_(p : A*)
p.value.on_something
end
c = ->_on_(A*)
a = A.new(12)
a.on_something
c.call(pointerof(a))
").to_i.should eq(12)
end
end
......@@ -387,11 +387,10 @@ module Crystal
call = Call.new(obj, node.name)
prepare_call(call)
arg_types = node.args.map { |arg| arg.accept(self); arg.type.instance_type }
call.args = [] of ASTNode
arg_types.each_with_index do |arg_type, i|
call.args << Var.new("arg#{i}", arg_type)
call.args = Array(ASTNode).new(node.args.length)
node.args.each_with_index do |arg, i|
arg.accept(self)
call.args << Var.new("arg#{i}", arg.type.instance_type)
end
begin
......@@ -400,10 +399,9 @@ module Crystal
node.raise "error instantiating #{node}", ex
end
arg_types.push call.type
node.type = mod.fun_of(arg_types)
node.call = call
node.bind_to call
false
end
......
......@@ -326,6 +326,15 @@ module Crystal
class FunPointer
property! :call
def map_type(type)
return nil unless call.type?
arg_types = call.args.map &.type
arg_types.push call.type
call.type.program.fun_of(arg_types)
end
end
class IsA
......
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