-
Notifications
You must be signed in to change notification settings - Fork 1.1k
TreeMap doesn't traverse Template class #10931
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
Comments
@nicolasstucki If you need help (e.g., creating a PR for this), let me know because I'm a stakeholder of this metaprogramming feature. Looks like adding model classes for the Template node itself is not so difficult, but I'm not yet familiar with the entire code base of dotty, so I need some advice for the direction to go. |
@xerial, the fix should be done here https://github.com/lampepfl/dotty/blob/d0491025682da0c958c9b8e85ca356d76d550583/library/src-bootstrapped/scala/quoted/Quotes.scala#L4019 The cases above show how to transform the sub-trees. Tests can be added in |
@nicolasstucki I've tried to traverse ClassDef and found we can use ClassDef.parents to rewrite Template nodes of an anonymous class like An example code: https://github.com/lampepfl/dotty/compare/master...xerial:template-node-traversal?expand=1
Basically, what I need would be a support for generating an AnonClass from a given trait type (e.g., A). tpd.scala has such code only for compiler-internal use: For example: // I'd like to generate code to create an anonymous class from a given type A, like `new A {}`
def mk[A] = '{ newInstanceOf[A] } Can we expose this functionality to Scala macros? It would be great if you have any idea to support generating anonymous class with Scala macros. |
Traversing details of Template type definitions itself was possible, so this is not a lack of functionality. Let me close the issue. |
Uh oh!
There was an error while loading. Please reload this page.
Minimized code
Expectation
Scala 3 macro should support traversing nodes inside Template node (https://github.com/lampepfl/dotty/blob/M3/compiler/src/dotty/tools/dotc/ast/Trees.scala#L784-L794), which will be generated by the code like above. Currently, TreeMap.transformTree https://github.com/lampepfl/dotty/blob/M3/library/src/scala/quoted/Quotes.scala#L3989-L3991 has no such pattern so we cannot rewrite a tree if it contains Template node.
QuotesImpl in Scala 3.0.0-M3 also has no corresponding definition for Template node: https://github.com/lampepfl/dotty/blob/M3/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala
Related: lampepfl/dotty-feature-requests#153
The text was updated successfully, but these errors were encountered: