Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add macro methods for Metaclass nodes #11375

Merged

Conversation

HertzDevil
Copy link
Contributor

c.f. #3274

Every Metaclass node can be reconstituted via:

macro foo(x)
  ({{ x.instance }}).class
end

Passing a T.class to a macro directly would produce a Call node instead of a Metaclass node, because macro arguments are interpreted as non-type expressions. Nonetheless, Metaclass nodes may appear in def restrictions or TypeDeclarations; since they are valid type names, they also have the #resolve and #resolve? methods.

@oprypin oprypin self-requested a review November 3, 2021 17:58
@@ -2247,6 +2247,29 @@ module Crystal
end
end

describe "metaclass methods" do
node = Metaclass.new(Path.new("Int32"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instantiating this node is cheap. I'd prefer to do that in every example to keep them self-contained.

@straight-shoota straight-shoota added this to the 1.3.0 milestone Nov 26, 2021
@straight-shoota straight-shoota merged commit 98a450b into crystal-lang:master Nov 30, 2021
@HertzDevil HertzDevil deleted the feature/metaclass-macro-methods branch December 1, 2021 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants