Tensegritics / ClojureDart

Clojure dialect for Flutter and Dart
1.38k stars 88 forks source link

Resolution of types across conditional import/export #305

Open cgrand opened 3 months ago

cgrand commented 3 months ago

Context: https://dart.dev/guides/libraries/create-packages#conditionally-importing-and-exporting-library-files

file_picker uses cross_file.

The CLJD compiler resolves XFile classes to the one in the stub types/interface.dart and add explicit import to this file from the compiled ns while it should not "see through" the conditional export and stops at least at src/x_file.dart (or maybe better at package:cross_file/cross_file.dart which is the last public export of XFile).

So we need to come up with a rule to determine the canonical lib when a conditional export (what would be the cases with an import?) is met.

Regarding stopping at the last public export for canonical resolution (see stroke-through text above) I think it's a bad idea. Here's why: one private lib can be re-exported from multiple public libs and the Dart compiler will be able to tell it's the same type. If we stop at the last public for canonical lib we won't be able to identify two exports of the same class as identical. I'm confident that we added canonical libs to fix this exact issue.

Thus conditional imports are a special twist and should not change the way we resolve regular libs.