dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.26k stars 1.58k forks source link

'augment class A {}' cannot be parsed #48541

Open scheglov opened 2 years ago

scheglov commented 2 years ago
  Invalid argument(s): Content produced diagnostics when parsed:
    MISSING_CONST_FINAL_VAR_OR_TYPE: Variables must be declared using the keywords 'const', 'final', 'var' or a type name. - 1:1
    EXPECTED_TOKEN: Expected to find ';'. - 1:1

But macro class A {} can.

johnniwinther commented 2 years ago

That is as intended(-ish). The support for augment class was originally added like the support macro class, but further development showed that augment class (for now) is only need in augmentation libraries. For this reason, augment class is now only supported when the scanner is configured for augmentation libraries, in which augment is treated as a modifier, whereas macro class is supported when the macros experimental flag is enabled.

scheglov commented 2 years ago

OK, thank you.

This is inconvenient with the way analyzer works - we can parse a file not knowing initially how it will be referenced later. And it feels inconsistent with the way language version works, which allows you to set @dart = x.y in parts, but will check that it is the same as in the library.

So, for now in the analyzer I will enable augment anywhere when the macros feature is enabled. https://dart-review.googlesource.com/c/sdk/+/242660

bwilkerson commented 2 years ago

... augment class (for now) is only need in augmentation libraries.

How do we know that an arbitrary file is an augmentation library? Is there a file naming convention?

johnniwinther commented 2 years ago

Currently we only read these files knowing that they are augmentation libraries.

The general discussion of how to identify these is in https://github.com/dart-lang/language/issues/2120

scheglov commented 2 years ago

Thank you for the pointer.