dart-lang / dart-lang/language

Allow functions to be used directly as metadata annotations

Open
#3,210 5 comments 11 reactions 0 assignees View on GitHub
request
Dominant language
TeX
Stars
2.9k
Forks
239
Avg merge
2d 18h
Merged PRs (30d)
14

Description

I haven't actually looked at the language spec to know for sure whether this is considered a bug or not, but this definitely seems like some unwanted behavior. Filing here instead of `sdk` since I'm guessing it is due to the language specification.

```dart
void foo() {}
const bar = foo;

class Metadata {
const Metadata(this.f);
final void Function() f;
}

// @foo // fails to compile, but this seems like it should
@bar // ok, despite just being = foo
@Metadata(foo) // ok
void foobar() {}
```

Using functions as metadata annotations will be useful for when static metaprogramming roles around.

Contributor guide

Open the contributing guide

Research direction

Start with the Dart language specification rules for metadata annotations and the reproducer in the issue, comparing direct `@foo` with `@bar` and `@Metadata(foo)`. Determine the intended specification change and confirm that the accepted behavior consistently allows functions to be used directly as metadata annotations.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.