Skip to content
Permalink
Browse files
closures in closures fixes: 155
  • 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.
@@ -145,7 +145,7 @@ def prepare(typer, method)
mirah = typer.transformer
interface = method.argument_types[-1]
outer_class = scope.defining_class

binding = scope.binding_type(mirah)

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

@defining_class = klass.static_scope.self_type

# TODO We need a special scope here that allows access to the
# outer class.
static_scope.self_type = typer.infer(klass, true)
@@ -174,6 +176,15 @@ def prepare(typer, method)
typer.infer(instance, true)
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)
method_definitions = body.select{ |node| node.kind_of? MethodDefinition }

@@ -183,8 +194,10 @@ def add_methods(klass, binding, typer)
# 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.
method_definitions.each do |node|

node.static_scope = static_scope
node.binding_type = binding
# node.children.each {|child| child.instance_variable_set '@scope', nil }
klass.append_node(node)
end
end
@@ -243,4 +243,20 @@ def foo c:Callable
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

0 comments on commit 96a9074

Please sign in to comment.