Permalink
Browse files

Generate missing arguments for blocks

  • Loading branch information...
1 parent f0792db commit d72cbe066ea32cec42e7d70bc2799e1c2742beae @ribrdb ribrdb committed Oct 6, 2012
Showing with 11 additions and 6 deletions.
  1. +4 −0 src/org/mirah/typer/closures.mirah
  2. +7 −6 test/jvm/blocks_test.rb
@@ -114,6 +114,10 @@ class ClosureBuilder
else
Arguments.new(block.position, Collections.emptyList, Collections.emptyList, nil, Collections.emptyList, nil)
end
+ while args.required.size < mtype.parameterTypes.size
+ arg = RequiredArgument.new(block.position, SimpleString.new("arg#{args.required.size}"), nil)
+ args.required.add(arg)
+ end
return_type = makeTypeName(block.position, mtype.returnType)
method = MethodDefinition.new(block.position, name, args, return_type, nil, nil)
method.body = NodeList(block.body.clone)
View
@@ -261,23 +261,24 @@ def foo(a:Bar)
end
end
- def test_block_with_no_params_on_interface_with
- assert_raises Mirah::MirahError do
- parse_and_type(<<-CODE)
+ def test_block_with_missing_params
+ cls, = compile(<<-CODE)
interface Bar do
def run(a:string):void;end
end
class Foo
def foo(a:Bar)
- 1
+ a.run("x")
end
end
Foo.new.foo do
- 1
+ puts "hi"
end
CODE
- end
+ assert_output "hi\n" do
+ cls.main(nil)
+ end
end
def test_block_with_too_many_params

1 comment on commit d72cbe0

Owner

Cool. Thanks.

Please sign in to comment.