Skip to content

Commit 6d50316

Browse files
authored
Update arguments spec to allow TypeAnnotations instead of Identifiers (#3146)
The real intention of allowing Identifiers was to allow types, but we also want to allow type arguments. This removes the ability to have arbitrary Identifier arguments and replaces that with TypeAnnotation arguments. We might want to add Identifier arguments also, to handle non-type identifiers, but I don't really have a use case.
1 parent af93327 commit 6d50316

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

working/macros/feature-specification.md

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ more of the macro interfaces, then the annotation is treated as an application
142142
of the `myCoolMacro` macro to the class MyClass.
143143

144144
Macro applications can also be passed arguments, either in the form of
145-
[Code][] expressions, [Identifier][]s, or certain types of literal values. See
146-
[Macro Arguments](#Macro-arguments) for more information on how these arguments
147-
are handled when executing macros.
145+
[Code][] expressions, [TypeAnnotation][]s, or certain
146+
types of literal values. See [Macro Arguments](#Macro-arguments) for more
147+
information on how these arguments are handled when executing macros.
148148

149149
### Code Arguments
150150

@@ -176,9 +176,9 @@ Most of the time, like here, a macro takes the arguments you pass it and
176176
interpolates them back into code that it generates, so passing the arguments as
177177
code is what you want.
178178

179-
### Identifier arguments
179+
### Type annotation arguments
180180

181-
If you want to be able to introspect on an identifier passed in to you, you can
181+
If you want to be able to introspect on a type passed in as an argument, you can
182182
do that as well, consider the following:
183183

184184
```dart
@@ -861,6 +861,7 @@ that top level declaration and insert that into the generated code.
861861
**TODO: Define this API. See [here](https://github.com/dart-lang/language/pull/1779#discussion_r683843130).**
862862

863863
[Identifier]: https://github.com/dart-lang/sdk/blob/main/pkg/_fe_analyzer_shared/lib/src/macros/api/introspection.dart#L15
864+
[TypeAnnotation]: https://github.com/dart-lang/sdk/blob/main/pkg/_fe_analyzer_shared/lib/src/macros/api/introspection.dart#L22
864865

865866
### Generating macro applications
866867

@@ -1104,8 +1105,9 @@ it specifies through parameter types:
11041105
expression is automatically converted to a corresponding `Code` instance.
11051106
These provided code expressions may contain identifiers.
11061107

1107-
* If the parameter type is `Identifier` then a single identifier must be
1108-
passed, and it will be converted to a corresponding `Identifier` instance.
1108+
* If the parameter type is `TypeAnnotation` then a literal type must be
1109+
passed, and it will be converted to a corresponding `TypeAnnotation`
1110+
instance.
11091111

11101112
Note that this implicit lifting of the argument expression only happens when
11111113
the macro constructor is invoked through a macro application. If a macro
@@ -1115,19 +1117,18 @@ macro), then the caller is responsible for creating the Code object.
11151117
As usual, it is a compile-time error if the type of any argument value (which
11161118
may be a Code object) is not a subtype of the corresponding parameter type.
11171119

1118-
It is a compile-time error if an macro class constructor invoked by a macro
1119-
application has a parameter whose type is not Code (or any subtype of it) or
1120-
one of the aforementioned primitive types (or a nullable type of any of those).
1120+
It is a compile-time error if a macro class constructor invoked by a macro
1121+
application has a parameter whose type is not Code, TypeAnnotation, or one of
1122+
the aforementioned primitive types (or a nullable type of any of those).
11211123

11221124
#### Identifier Scope
11231125

11241126
The following rules apply to any `Identifier` passed as an argument to a macro
1125-
application, whether as a part of a `Code` expression or directly as an
1126-
`Identifier` instance.
1127+
application, whether as a part of a `Code` expression or `TypeAnnotation`.
11271128

1128-
The scope of any `Identifier` argument is the same as the scope in which the
1129-
identifier appears in the source code, which is the same as the argument scope
1130-
for a metadata annotation on a declaration. This means:
1129+
The scope of any `Identifier` is the same as the scope in which the identifier
1130+
appears in the source code, which is the same as the argument scope for a
1131+
metadata annotation on a declaration. This means:
11311132

11321133
* Identifiers in macro application arguments may only refer to static and top
11331134
level members.

0 commit comments

Comments
 (0)