dart-lang / dart-lang/language

[Spec] <declaration> production seems to be missing some types of modifiers

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

Description

This code can be compiled by the Dart compiler, but it can't be parse with the given rules in the Spec:
```
abstract class StreamController {
final int i1 = 0;
abstract int i2; // Can't parse
abstract final int i3; // Can't parse
}
```
It fails to parse the declaration for i2 and i3 because of the modifier "abstract".

From the Spec, the rule for [declaration](https://github.com/dart-lang/language/blob/812f939ec0130da119ad2cbe5f9a4121e31b0831/specification/dartLangSpec.tex#L2423) allows for a number of cases, but does not allow for a declaration that begins with `abstract`.

Note, for a class member declaration, the parser itself seems to recognize [three groups of modifiers](https://github.com/dart-lang/sdk/blob/81584f5d031fc12049f954b8510de7c36f1e56ea/pkg/_fe_analyzer_shared/lib/src/parser/parser_impl.dart#L3918-L3977) followed by a [list of modifiers](), roughly as ('external'|'augment'|'abstract')? ('static'|'covariant')? ('final'|'var'|'const'|('late' 'final'?)? [classMemberModifiers](https://github.com/dart-lang/sdk/blob/81584f5d031fc12049f954b8510de7c36f1e56ea/pkg/_fe_analyzer_shared/lib/src/parser/parser_impl.dart#L3965)?; [classMemberModifiers](https://github.com/dart-lang/sdk/blob/81584f5d031fc12049f954b8510de7c36f1e56ea/pkg/_fe_analyzer_shared/lib/src/parser/modifier_context.dart#L96) : [modifiers](https://github.com/dart-lang/sdk/blob/81584f5d031fc12049f954b8510de7c36f1e56ea/pkg/_fe_analyzer_shared/lib/src/parser/modifier_context.dart#L97); [modifiers](https://github.com/dart-lang/sdk/blob/81584f5d031fc12049f954b8510de7c36f1e56ea/pkg/_fe_analyzer_shared/lib/src/parser/modifier_context.dart#L245) : (abstract|augment|const|covariant|external|final|late|required|static|var)*. Anyway, the CFG in the Spec needs alts to allow `abstract` members of a class

Contributor guide

Open the contributing guide

Research direction

Start with the declaration production in specification/dartLangSpec.tex around line 2423 and compare it with the abstract member examples in the issue. Review the referenced parser modifier handling in pkg/_fe_analyzer_shared/lib/src/parser/parser_impl.dart and modifier_context.dart. Done means the specification grammar accepts the shown abstract fields and the relevant specification checks pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
47/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.