Skip to content

Commit

Permalink
Fix look-up-scope as macro defined type (#5354)
Browse files Browse the repository at this point in the history
  • Loading branch information
makenowjust authored and Serdar Dogruyol committed Jul 23, 2018
1 parent d1ac793 commit 2aea034
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
42 changes: 42 additions & 0 deletions spec/compiler/semantic/macro_spec.cr
Expand Up @@ -1238,6 +1238,48 @@ describe "Semantic: macro" do
)) { int32 }
end

it "can lookup type parameter when macro is called inside class (#5343)" do
assert_type(%(
class Foo(T)
macro foo
{{T}}
end
end
alias FooInt32 = Foo(Int32)
class Bar
def self.foo
FooInt32.foo
end
end
Bar.foo
)) { int32.metaclass }
end

it "cannot lookup type defined in caller class" do
assert_error %(
class Foo
macro foo
{{Baz}}
end
end
class Bar
def self.foo
Foo.foo
end
class Baz
end
end
Bar.foo
),
"undefined constant Baz"
end

it "clones default value before expanding" do
assert_type(%(
FOO = {} of String => String?
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/semantic/semantic_visitor.cr
Expand Up @@ -298,7 +298,7 @@ abstract class Crystal::SemanticVisitor < Crystal::Visitor
generated_nodes = expand_macro(the_macro, node) do
old_args = node.args
node.args = args
expanded = @program.expand_macro the_macro, node, expansion_scope, @path_lookup, @untyped_def
expanded = @program.expand_macro the_macro, node, expansion_scope, expansion_scope, @untyped_def
node.args = old_args
expanded
end
Expand Down

0 comments on commit 2aea034

Please sign in to comment.