You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The contents of the quote are much more clear in the second example.
37
37
38
38
### Avoid nested contexts
39
39
@@ -74,34 +74,29 @@ val leafSym: Symbol = leafTpe.typeSymbol
74
74
75
75
### Avoid `Symbol.tree`
76
76
77
-
On an object `sym: Symbol`, `sym.tree` returns the `Tree` associated to the
78
-
symbol. Be careful when using this method as the tree for a symbol might not be
79
-
defined. When the code associated to the symbol is defined in a different
80
-
moment than this access, if the `-Yretain-trees` compilation option is not
81
-
used, then the `tree` of the symbol will not be available. Symbols originated
82
-
from Java code do not have an associated `tree`.
77
+
On an object `sym: Symbol`, `sym.tree` returns the `Tree` associated with the symbol.
78
+
Be careful when using this method, as the tree for a symbol might not be defined.
79
+
When the code associated with a symbol is defined at a different time than this access, if the `-Yretain-trees` compilation option is not used, then the `tree` of the symbol will not be available.
80
+
Symbols originating from Java code do not have an associated `tree`.
83
81
84
82
### Obtaining a `TypeRepr` from a `Symbol`
85
83
86
-
In the previous paragraph we saw that `Symbol.tree` should be avoided and
87
-
therefore you should not use `sym.tree.tpe` on `sym: Symbol`. Thus to obtain
88
-
the `TypeRepr` corresponding to a `Symbol`, it is recommended to use
89
-
`tpe.memberType` on objects `tpe: TypeRepr`.
84
+
In the previous heading, we saw that `Symbol.tree` should be avoided and that therefore you should not use `sym.tree.tpe` on `sym: Symbol`.
85
+
Thus, to obtain the `TypeRepr` corresponding to a `Symbol`, it is recommended to use `tpe.memberType` on `tpe: TypeRepr` objects.
90
86
91
87
We can obtain the `TypeRepr` of `Leaf` in two ways:
92
88
1.`TypeRepr.of[Box.Leaf]`
93
-
2.`boxTpe.memberType(leafSym)`, in other words we request the `TypeRepr` of
94
-
the member of `Box` whose symbol is equal to the symbol of sym
89
+
2.`boxTpe.memberType(leafSym)`
90
+
(In other words, we request the `TypeRepr` of the member of `Box` whose symbol is equal to the symbol of `leafSym`.)
95
91
96
-
while the two approaches are equivalent, the first is possible only if you
97
-
already know that you are looking for `Box.Leaf`. The second approach allows
98
-
you to explore an uknown API.
92
+
While the two approaches are equivalent, the first is only possible if you already know that you are looking for the type `Box.Leaf`.
93
+
The second approach allows you to explore an unknown API.
99
94
100
95
### Use `Symbol`s to compare definitions
101
96
102
97
Read more about Symbols [here][symbol].
103
98
104
-
Symbols allow comparing definitions using `==`:
99
+
Symbols allow you to compare definitions using `==`:
105
100
```scala
106
101
leafSym == baseSym.children.head // Is true
107
102
```
@@ -113,7 +108,7 @@ boxTpe.memberType(baseSym.children.head) == leafTpe // Is false
113
108
114
109
### Obtaining a Symbol for a type
115
110
116
-
There is a handy shortcut to get the symbol of the definition of `T`.
111
+
There is a handy shortcut to get the symbol for the definition of `T`.
Copy file name to clipboardExpand all lines: _overviews/scala3-macros/tutorial/macros.md
+5-5Lines changed: 5 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -73,7 +73,7 @@ As a technicaly consequence, we cannot define and use a macro in the **same clas
73
73
However, it is possible to have the macro definition and its call in the **same project** as long as the implementation of the macro can be compiled first.
74
74
75
75
> ##### Suspended Files
76
-
> To allow defining and using macros in the same project, only those calls to macros are expanded, where the macro has already been compiled.
76
+
> To allow defining and using macros in the same project, only those calls to macros that have already been compiled are expanded.
77
77
> For all other (unknown) macro calls, the compilation of the file is _suspended_.
78
78
> Suspended files are only compiled after all non suspended files have been successfully compiled.
79
79
> In some cases, you will have _cyclic dependencies_ that will block the completion of the compilation.
0 commit comments