Part file can contain imports
Create:
test.dart
part "part.dart";
main() {
print(fromPart());
}
part.dart
import "lib.dart"; // <-- !
part of "test.dart";
fromPart() => "from part";
lib.dart
void fromLib() {}
Then run:
$ dart test.dart
Expected: A compile-time error that a part file cannot contain imports.
Actual: Runs without error and prints "from part". Analyzer does report an error.
Based on the trybots, it looks like this behavior is incorrect on:
| dart2js-minified-strong-linux-x64-d8/ | language_2/script2_test | Pass | CompileTimeError |
| dart2js-minified-strong-linux-x64-d8/production | language_2/script2_test | Pass | CompileTimeError |
| dart2js-strong-hostasserts-linux-ia32-d8 | language_2/script2_test | Pass | CompileTimeError |
| dart2js-strong-linux-x64-chrome | language_2/script2_test | Pass | CompileTimeError |
| ddc-linux-release-chrome/dartdevk-checked | language_2/script2_test | Pass | CompileTimeError |
| front-end-linux-release-x64/fasta | language_2/script2_test | Pass | CompileTimeError |
| vm-kernel-linux-product-x64 | language_2/script2_test | Pass | CompileTimeError |
| vm-kernel-linux-release-x64 | language_2/script2_test | Pass | CompileTimeError |
The import is ignored (imported names are not available in either part or main library), so it's no actual use of the "feature".
so it's no actual use of the "feature".
True, but it should still be an error. :)
Looks like someone was getting a head-start on https://github.com/dart-lang/language/blob/main/working/augmentation-libraries/parts_with_imports.md? 😄 Probably this issue can be closed if that goes ahead?
Even with the new feature, the import needs to be after the part of, though. :wink: