Skip to content

Commit

Permalink
closures in closures fixes: 155
Browse files Browse the repository at this point in the history
  • Loading branch information
baroquebobcat committed Feb 27, 2012
1 parent 77f110f commit 96a9074
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/mirah/ast/structure.rb
Expand Up @@ -145,7 +145,7 @@ def prepare(typer, method)
mirah = typer.transformer mirah = typer.transformer
interface = method.argument_types[-1] interface = method.argument_types[-1]
outer_class = scope.defining_class outer_class = scope.defining_class

binding = scope.binding_type(mirah) binding = scope.binding_type(mirah)


name = "#{outer_class.name}$#{mirah.tmp}" name = "#{outer_class.name}$#{mirah.tmp}"
Expand All @@ -157,6 +157,8 @@ def prepare(typer, method)
mirah.eval("@binding = binding", '-', c, 'binding') mirah.eval("@binding = binding", '-', c, 'binding')
end end


@defining_class = klass.static_scope.self_type

# TODO We need a special scope here that allows access to the # TODO We need a special scope here that allows access to the
# outer class. # outer class.
static_scope.self_type = typer.infer(klass, true) static_scope.self_type = typer.infer(klass, true)
Expand All @@ -174,6 +176,15 @@ def prepare(typer, method)
typer.infer(instance, true) typer.infer(instance, true)
end end


def defining_class
@defining_class
end

# TODO extract this & matching methods into a module
def binding_type(mirah=nil)
static_scope.binding_type(defining_class, mirah)
end

def add_methods(klass, binding, typer) def add_methods(klass, binding, typer)
method_definitions = body.select{ |node| node.kind_of? MethodDefinition } method_definitions = body.select{ |node| node.kind_of? MethodDefinition }


Expand All @@ -183,8 +194,10 @@ def add_methods(klass, binding, typer)
# TODO warn if there are non method definition nodes # TODO warn if there are non method definition nodes
# they won't be used at all currently--so it'd be nice to note that. # they won't be used at all currently--so it'd be nice to note that.
method_definitions.each do |node| method_definitions.each do |node|

node.static_scope = static_scope node.static_scope = static_scope
node.binding_type = binding node.binding_type = binding
# node.children.each {|child| child.instance_variable_set '@scope', nil }
klass.append_node(node) klass.append_node(node)
end end
end end
Expand Down
16 changes: 16 additions & 0 deletions test/jvm/blocks_test.rb
Expand Up @@ -243,4 +243,20 @@ def foo c:Callable
end end
end end


def test_closure_in_closure_doesnt_raise_error
parse_and_type(<<-CODE)
interface Bar do;def run:void;end;end
class Foo
def foo(a:Bar)
1
end
end
Foo.new.foo do
Foo.new.foo do
1
end
end
CODE
end
end end

0 comments on commit 96a9074

Please sign in to comment.