Skip to content

Commit

Permalink
Showing 2 changed files with 43 additions and 1 deletion.
42 changes: 42 additions & 0 deletions spec/compiler/semantic/macro_spec.cr
Original file line number Diff line number Diff line change
@@ -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?
2 changes: 1 addition & 1 deletion src/compiler/crystal/semantic/semantic_visitor.cr
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2aea034

Please sign in to comment.