Skip to content

Commit 59f3aa3

Browse files
committed
Update MacroAnnotation documentation
1 parent 5fcb869 commit 59f3aa3

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

library/src/scala/annotation/MacroAnnotation.scala

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,21 @@ trait MacroAnnotation extends StaticAnnotation:
1414
* It returns a non-empty list containing the modified version of the annotated definition.
1515
* The new tree for the definition must use the original symbol.
1616
* New definitions can be added to the list before or after the transformed definitions, this order
17-
* will be retained.
18-
*
19-
* All definitions in the result must have the same owner. The owner can be recovered from `tree.symbol.owner`.
20-
*
21-
* The result cannot add new `class`, `object` or `type` definition. This limitation will be relaxed in the future.
17+
* will be retained. New definitions will not be visible from outside the macro expansion.
18+
*
19+
* Restrictions:
20+
* - All definitions in the result must have the same owner. The owner can be recovered from `Symbol.spliceOwner`.
21+
* - Special case: an annotated top-level `def`, `val`, `var`, `lazy val` can return a `class`/`object`
22+
definition that is owned by the package or package object.
23+
* - Can not return a `type`.
24+
* - Annotated top-level `class`/`object` can not return top-level `def`, `val`, `var`, `lazy val`.
25+
* - Can not see new definition in user written code.
26+
*
27+
* Good practices:
28+
* - Make your new definitions private if you can.
29+
* - New definitions added as class members should use a fresh name (`Symbol.freshName`) to avoid collisions.
30+
* - New top-level definitions should use a fresh name (`Symbol.freshName`) that includes the name of the annotated
31+
* member as a prefix to avoid collisions definitions added in other files.
2232
*
2333
* IMPORTANT: When developing and testing a macro annotation, you must enable `-Xcheck-macros` and `-Ycheck:all`.
2434
*
@@ -184,5 +194,7 @@ trait MacroAnnotation extends StaticAnnotation:
184194
*
185195
* @param Quotes Implicit instance of Quotes used for tree reflection
186196
* @param tree Tree that will be transformed
197+
*
198+
* @syntax markdown
187199
*/
188200
def transform(using Quotes)(tree: quotes.reflect.Definition): List[quotes.reflect.Definition]

0 commit comments

Comments
 (0)