Skip to content

Commit 0a826dd

Browse files
committed
ensure that a block body is created even when the block is empty
1 parent d8b0641 commit 0a826dd

3 files changed

Lines changed: 68 additions & 2 deletions

File tree

lib/mirah/transform/helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ def transform_iter(node, parent)
406406
Mirah::AST::Block.new(parent, position(node)) do |block|
407407
[
408408
args ? transformer.transform(args, block) : Mirah::AST::Arguments.new(block, position(node)),
409-
body ? transformer.transform(body, block) : nil,
409+
body ? transformer.transform(body, block) : Mirah::AST::Body.new(block, position(node)),
410410
]
411411
end
412412
end

test/jvm/bytecode_test_helper.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def compile_ast ast
120120
compiler
121121
end
122122

123-
def compile(code, name = "script" + System.nano_time.to_s)
123+
def compile(code, name = tmp_script_name)
124124
clear_tmp_files
125125
reset_type_factory
126126

@@ -130,6 +130,10 @@ def compile(code, name = "script" + System.nano_time.to_s)
130130

131131
generate_classes compiler
132132
end
133+
134+
def tmp_script_name
135+
"script" + System.nano_time.to_s
136+
end
133137
end
134138

135139

test/jvm/test_blocks.rb

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
2+
# All contributing project authors may be found in the NOTICE file.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
class TestBlocks < Test::Unit::TestCase
17+
18+
def setup
19+
super
20+
clear_tmp_files
21+
reset_type_factory
22+
end
23+
24+
def parse_and_type code, name=tmp_script_name
25+
parse_and_resolve_types name, code
26+
end
27+
28+
#this should probably be a core test
29+
def test_empty_block_parses_and_types_without_error
30+
assert_nothing_raised do
31+
parse_and_type(<<-CODE)
32+
interface Bar do;def run:void;end;end
33+
34+
class Foo
35+
def foo(a:Bar)
36+
1
37+
end
38+
end
39+
Foo.new.foo do
40+
end
41+
CODE
42+
end
43+
end
44+
45+
def test_non_empty_block_parses_and_types_without_error
46+
assert_nothing_raised do
47+
parse_and_type(<<-CODE)
48+
interface Bar do;def run:void;end;end
49+
50+
class Foo
51+
def foo(a:Bar)
52+
1
53+
end
54+
end
55+
Foo.new.foo do
56+
1
57+
end
58+
CODE
59+
end
60+
end
61+
62+
end

0 commit comments

Comments
 (0)