sdk icon indicating copy to clipboard operation
sdk copied to clipboard

Part file can contain imports

Open munificent opened this issue 6 years ago • 4 comments

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.

munificent avatar Nov 19 '19 22:11 munificent

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 |

munificent avatar Nov 20 '19 00:11 munificent

The import is ignored (imported names are not available in either part or main library), so it's no actual use of the "feature".

lrhn avatar Nov 21 '19 07:11 lrhn

so it's no actual use of the "feature".

True, but it should still be an error. :)

munificent avatar Nov 22 '19 01:11 munificent

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?

DanTup avatar Aug 28 '24 10:08 DanTup

Even with the new feature, the import needs to be after the part of, though. :wink:

lrhn avatar Aug 28 '24 12:08 lrhn