google / flatbuffers

FlatBuffers: Memory Efficient Serialization Library
https://flatbuffers.dev/
Apache License 2.0
23.16k stars 3.23k forks source link

[Dart, master] Recursive imports are not respected #8379

Open insertjokehere opened 1 month ago

insertjokehere commented 1 month ago

Consider the following schemas:

table a { options: uint8; }

* `includes_b.fbs`:

include 'includes_a.fbs';

namespace a;

table b { my_a: a; }

* `includes_c.fbs`:

include 'includes_b.fbs';

namespace a;

table c { my_a: a; my_b: b; }



The docs (https://flatbuffers.dev/md__schemas.html) are vague on if this is valid, but as far as I can tell this is supposed to work - `c` imports `b`, which imports `a`, so `a` and `b` are in scope in `c`.

When generating Dart bindings (`flatc --dart --gen-object-api *.fbs`), this relationship is reflected in the Dart code - `includes_c_a_generated.dart` imports `includes_b_a_generated.dart`, which imports `includes_a_a_generated.dart` - however, this is not how imports in Dart work. Importing `b.dart` in `c.dart` does not bring the contents of `a.dart` into scope unless `b.dart` explicitly `export`s the file.

I've not taken a survey of other generators, but I suspect this affects other languages as well.