-
Notifications
You must be signed in to change notification settings - Fork 220
Closed
Labels
small-featureA small feature which is relatively cheap to implement.A small feature which is relatively cheap to implement.

Description
Feature specification: https://github.com/dart-lang/language/blob/master/accepted/2.14/small-features-21Q1/feature-specification.md
Annotations (metadata) aren't allowed to use type arguments, but it is allowed to make annotations using a const of a type that takes a type argument:
class MyAnnotation<T> {
const MyAnnotation();
}
const MA = MyAnnotation<String Function(int)>();
@MA // <- Works.
random(int weather) => '7';
@MyAnnotation<String Function(int)>() // <- Fails.
alsoRandom(int lucky) => '7';
main() => random(0) + alsoRandom(13);
Gives:
../../annotation_type_generic.dart:10:14: Error: An annotation (metadata) can't use type arguments.
@MyAnnotation<String Function(int)>()
^
See also: dart-lang/sdk#44120
greglittlefield-wf, kevmoo, jodinathan, ykmnkmi, hunter-kaan and 8 morerockyoung
Metadata
Metadata
Assignees
Labels
small-featureA small feature which is relatively cheap to implement.A small feature which is relatively cheap to implement.
Type
Projects
Status
Done
Milestone
Relationships
Development
Select code repository
Activity
ghost commentedon Nov 9, 2020
+CC: @mkustermann, @lrhn
eernstg commentedon Nov 9, 2020
This would certainly make sense, and we've discussed it already a long time ago. I'll move this issue to the language repository where it fits better.
mkustermann commentedon Nov 9, 2020
@eernstg @lrhn It might be really helpful if we could get this soon due to a use case in the VM. The constant evaluator is now in the CFE and shared across backends, so it might not be very hard to support this.
eernstg commentedon Nov 9, 2020
Maybe you could say a bit more about that use case in the VM and why it is important?
mkustermann commentedon Nov 9, 2020
Sure. We currently have VM-specific syntax in Dart files for specifying natives. That looks e.g. like this:
This uses our old, heavy weight runtime call mechanism.
Now we would like to make it possible to use the new Dart FFI for such natives instead. Possibly even replacing all of our old native calls with faster FFI natives.
Ideally we would do this in a declarative way, just as our natives before.
Though we will need to have a way to specify not only the name of the C function (as above) but also it's signature in C code. One option would be to make them look like this:
That would remove the VM-specific
native "foo"
-syntax as well as allowing us to use declaratively specific FFI natives with the corresponding C function signature.eernstg commentedon Nov 9, 2020
OK, thanks! It would still be possible to use
but it is obviously more convenient to avoid the intermediate constant variable, and the need to invent a name for it.
johnniwinther commentedon Nov 10, 2020
From the CFE point of view it seems we can support this by just not emitting the error, i.e. by removing one 3-line if-statement. This would also remove the error from the analyzer, but I don't know if more work is needed on the analyzer side. @scheglov Do you if more work is needed on the analyzer side?
scheglov commentedon Nov 14, 2020
Yes, it will require some work in the analyzer. The class Annotation does not have
typeArguments
yet, onlyarguments
that does not have type arguments in it (in contrast to kernel'sArguments
). Then evaluation will require some changes. Nothing hard though.mkustermann commentedon Nov 19, 2020
@leafpetersen @munificent @lrhn Could you discuss this in next language meeting? Making this small change would get us unblocked.
leafpetersen commentedon Nov 19, 2020
This seems fine by me. I think this would be a good candidate for the small and useful features release - it would be good to have it guarded by a language version to avoid breaking on old SDKs.
ghost commentedon Nov 30, 2020
What kind of timeline are we roughly looking at for this to land?
mit-mit commentedon Dec 9, 2020
@cskau-g @mkustermann is the workaround Erik described sufficient to get you started?
22 remaining items