Skip to content

Commit

Permalink
add test for nested closures, touch struct method where changes were …
Browse files Browse the repository at this point in the history
…added in master

I didn't reimplement nested closure support, because I'm not sure of where things need to be changed yet.

It looks like
  lib/mirah/ast/structure.rb
and
  src/org/mirah/typer/closures.mirah
need some changes for this to work.
  • Loading branch information
baroquebobcat committed Apr 23, 2012
1 parent fe53909 commit f396297
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/mirah/ast/structure.rb
Expand Up @@ -142,10 +142,11 @@ def prepare(typer, method)
interface = method.argument_types[-1]
outer_class = find_parent(MethodDefinition, Script).defining_class
name = "#{outer_class.name}$#{duby.tmp}"

klass = mirah.define_closure(position, name, outer_class)
klass.interfaces = [interface]

binding = typer.get_scope(self).binding_type(outer_class, duby)
binding = typer.get_scope(self).binding_type(outer_class, mirah)

klass.define_constructor(position,
['binding', binding]) do |c|
Expand Down
21 changes: 19 additions & 2 deletions test/jvm/blocks_test.rb
Expand Up @@ -255,7 +255,7 @@ def test_block_with_no_params_on_interface_with
interface Bar do
def run(a:string):void;end
end
class Foo
def foo(a:Bar)
1
Expand All @@ -274,7 +274,7 @@ def test_block_with_too_many_params
interface Bar do
def run(a:string):void;end
end
class Foo
def foo(a:Bar)
1
Expand All @@ -286,4 +286,21 @@ def foo(a:Bar)
CODE
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 f396297

Please sign in to comment.