Skip to content

Commit 7a933f3

Browse files
committed
raise an inference error when method has same name as macro. fixes #123
1 parent 6517a90 commit 7a933f3

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

lib/mirah/ast/method.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,11 +264,16 @@ def infer(typer, expression)
264264
inferred_type = body ? typer.infer(body, body_is_expression) : typer.no_type
265265

266266
if inferred_type && arguments.inferred_type.all?
267-
actual_type = if forced_type.nil?
268-
inferred_type
269-
else
267+
actual_type = if forced_type
270268
forced_type
269+
else
270+
inferred_type
271+
end
272+
273+
if actual_type.kind_of? Mirah::AST::InlineCode
274+
raise Mirah::Typer::InferenceError.new("Method %s has the same signature as macro of the same name." % name,self)
271275
end
276+
272277
if actual_type.unreachable?
273278
actual_type = typer.no_type
274279
end

test/jvm/test_macros.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,17 @@ def test_block_parameter_uses_outer_scope
144144
end
145145
end
146146

147+
def test_method_def_after_macro_def_with_same_name_raises_error
148+
assert_raises Mirah::InferenceError do
149+
compile(<<-EOF)
150+
macro def foo
151+
quote { puts :z }
152+
end
153+
def foo
154+
:bar
155+
end
156+
EOF
157+
end
158+
159+
end
147160
end

0 commit comments

Comments
 (0)