-
Notifications
You must be signed in to change notification settings - Fork 221
Description
In packages that use a language version lower than the current SDK, via SDK constraints in pubspec.yaml, I've noticed compilation errors that seem to indicate that they're instead compiled with a newer language version.
- Dart versions I tried, which reproduced the issue: 3.10.3, 3.9.0
- build_web_compilers versions affected: >4.4.0 (more info at the bottom of the issue)
For example, given the following reduced test case that has a package language version of 2.19:
-
pubspec.yaml
name: language_version_repro environment: # Lower bound sets a language version of 2.19 sdk: '>=2.19.0 <4.0.0' dev_dependencies: build_web_compilers: ^4.4.5
-
web/needs_less_than_3.0.dart
class MixinClass { foo() => 'foo'; } // 3.0 no longer allows mixing in classes: https://dart.dev/resources/language/evolution#dart-3-0 class B extends Object with MixinClass {} main() => print(B().foo());
-
web/needs_less_than_3.7.dart
// 3.7 no longer allows referencing `_`: https://dart.dev/resources/language/evolution#dart-3-7 void function(dynamic _) => print(_); void main() => function('foo');
The build fails with the following errors:
$ dart run build_runner build web
…
log output for build_web_compilers:ddc (lazy) on web/needs_less_than_3.0.ddc.module
E Error compiling dartdevc module:language_version_repro|web/needs_less_than_3.0.ddc.js
web/needs_less_than_3.0.dart:5:29: Error: The class 'MixinClass' can't be used as a mixin because it isn't a mixin class nor a mixin.
class B extends Object with MixinClass {}
^
…
log output for build_web_compilers:ddc (lazy) on web/needs_less_than_3.7.ddc.module
E Error compiling dartdevc module:language_version_repro|web/needs_less_than_3.7.ddc.js
web/needs_less_than_3.7.dart:1:35: Error: Undefined name '_'.
void function(dynamic _) => print(_);
^
…and it also fails with similar errors when compiling in dart2js, via --release.
Adding explicit language comments to each file (e.g., //@dart=2.19 and //@dart=3.6 respectively) works around the issue. So, it seems that those language versions are respected, but the one from pubspec.yaml is not.
I noticed that this issue did not occur in earlier versions of build_web_compilers. With these dependencies, the issue does not reproduce:
dev_dependencies:
build_web_compilers: 4.3.2
build_modules: 5.0.18 # need to pin this to avoid compile errorsAnd in the next versions of build_web_compilers/build_modules, the issue reproduces (as also reproduces in the latest version of build_web_compilers, as shown in the reduced test case above):
dev_dependencies:
build_web_compilers: 4.4.0
build_modules: 5.1.0 # need to pin this to avoid compile errors