dart-lang / language

Design of the Dart language
Other
2.65k stars 203 forks source link

[modules] keep library privacy #3639

Open cedvdb opened 7 months ago

cedvdb commented 7 months ago

In the module feature spec privacy is achieved by using _ like you would for a library and it's extended to module.

I would like to keep some level of library privacy, that is I want A._b not to be accessible from C, despite both being in the same module, when those are declared in different files. Since it seems like adding a private / # access modifier is not on the table (or is it ?), I'm proposing using the file name instead for module privacy.

Such that:

lrhn commented 7 months ago

Not sure what "only accessible inside the nodule" means for a declaration in a _a.dart file.

If we simply make it an error to import a file starting with _ from another nodule, then that's directly inaccessible. If another library in the same module exports the declaration, then it shouldn't matter where that name comes from. We should either disallow exporting such libraries, or accept that it's possible. I expect a use for module private libraries to be declaring functions intended to be module private and public together in one library, so they can access the library private names of ready other, and only exporting the public ones.

Or we could just make importing a library starting with _, or from a directory starting with _, frowned upon, like importing from inside src/. No strong protection, so if modules need that, it's not enough.