Skip to content

Commit

Permalink
raise an inference error when method has same name as macro. fixes #123
Browse files Browse the repository at this point in the history
  • Loading branch information
baroquebobcat committed Oct 16, 2011
1 parent 6517a90 commit 7a933f3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/mirah/ast/method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,16 @@ def infer(typer, expression)
inferred_type = body ? typer.infer(body, body_is_expression) : typer.no_type

if inferred_type && arguments.inferred_type.all?
actual_type = if forced_type.nil?
inferred_type
else
actual_type = if forced_type
forced_type
else
inferred_type
end

if actual_type.kind_of? Mirah::AST::InlineCode
raise Mirah::Typer::InferenceError.new("Method %s has the same signature as macro of the same name." % name,self)
end

if actual_type.unreachable?
actual_type = typer.no_type
end
Expand Down
13 changes: 13 additions & 0 deletions test/jvm/test_macros.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,17 @@ def test_block_parameter_uses_outer_scope
end
end

def test_method_def_after_macro_def_with_same_name_raises_error
assert_raises Mirah::InferenceError do
compile(<<-EOF)
macro def foo
quote { puts :z }
end
def foo
:bar
end
EOF
end

end
end

0 comments on commit 7a933f3

Please sign in to comment.