Comments (9)
What make me worry is using TypeAnnotationArgument
for something that might be not a type. If it is just an opaque identifier, then it would be clean to use such kind of Argument
. OTOH, if it is definitely a named type like List<int>
, we should use TypeAnnotationArgument
.
What to do if (after the types phase) it turned out to be a type literal, is an open question. AFAIK in the analyzer we don't rewrite final x = int;
from SimpleIdentifier
to TypeLiteral(SimpleIdentifier)
, but that does not mean that this is a good example to follow :-)
@goderbauer Yes, currently the analyzer complains about any use of an identifier as an argument. We are trying to decide what should be done with such identifiers.
from sdk.
cc @scheglov @johnniwinther this feature would be nice for the stateful widget case (or in general when you want to generate a new class, and run macros on it which want to introspect on the original class).
It would be nice to prioritize it somewhat highly (but behind anything json macro related), to unblock experiments in this area for flutter.
from sdk.
What kind of Argument
should it be?
from sdk.
Oh, I thought we supported just Identifier, but it looks like not (and they aren't in the spec either).
For this case, a TypeAnnotationArgument would work too though. @goderbauer can you try that, using NamedTypeAnnotation
as the field type?
Or, you could just do ExpressionCode
, and then assert that you are given an expression with exactly one identifier (var identifier = code.parts.single as Identifier;
, maybe with some error handling). But, the type annotation is probably better.
from sdk.
Well, the specification says:
Here the macro takes an Identifier argument, and introspects on it to know how to generate the desired serialization and deserialization classes.
from sdk.
There is a complication with identifiers. At least in the analyzer. This is related to the moment when we instantiate macros. We do this right after parsing a file, so all we have is unresolved AST. And without types built and resolved, we don't know if Foo
in @MyMacro(Foo)
is a type literal, or a function name.
We could disposeMacro()
after the types phase, and re-instantiate with different arguments. Is this what you would expect?
Note, that people asked to arguments that are references to functions as well.
from sdk.
The macro does not see any details of the Identifier, so what I would do is create an opaque Identifier, which gets its true information filled in after the types phase?
Technically though, it is possible that a regular declaration could be added in the declarations phase, which shadows the identifier for the type....
from sdk.
And of course, it also isn't clear what the identifier should look like in the augmentation code from the first phase (what should the compiler say when asked to resolve the identifier to a URI by the augmentation library code?)
from sdk.
For this case, a TypeAnnotationArgument would work too though. @goderbauer can you try that, using NamedTypeAnnotation as the field type?
I tried both NamedTypeAnnotation
and ExpressionCode
as the type for the field in the macro without changing anything at the instantiation side (still @Foo(String)
). I continue to get the same error.
from sdk.
Related Issues (20)
- [breaking change] Consider NEL (U+0085) not whitespace for trim, trimLeft, trimRight HOT 2
- bug: Class constructor <class_name> cannot be invoked without 'new' HOT 6
- [breaking change] Change parameter type of `importModule` from `String` to `JSAny` HOT 6
- [CP] Update with DevTools that does not fail heap snapshotting. HOT 6
- [frontend_server] Ability to change `output-dill`
- [doc/ffi] `NativeFinalizer` shutdown guarantees HOT 2
- What if VScode would suggest the `~/` operator if the `/` operator does not exist? HOT 2
- [Wasm] illegal cast exception when trying to use Firebase Auth with Flutter HOT 3
- "Exception:: Missing implementation of visitAugmentedExpression" HOT 1
- Semantics of `dart:js_interop`s `Function.toJS` extension HOT 2
- Make `dart compile wasm -O4` not omit explicit type checks HOT 3
- Implement the macros feature in the analyzer HOT 4
- [vm] Optimizer can keep object longer alive due to CSE/Store-to-Load of WeakReference.target HOT 6
- [vm/ffi] Native assets dylib handles should be cached
- Dart fix not working with `--code` and part of HOT 6
- [vm/ffi] Native asset dynamic libraries should be `dlclose`d on isolate (group) shutdown
- Improve VM's JSON decoder HOT 4
- [vm/ffi] Native asset resolution via embedder HOT 1
- dart fix with both --dry-run and --apply
- `Can't use 'super' as an expression` error should appear in analyzer HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sdk.