google / flatbuffers

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

Expected behavior for circular includes in .fbs files? [all languages, flatc version 23.5.26, Ubuntu 24.04] #8302

Closed andrew-otiv closed 1 month ago

andrew-otiv commented 1 month ago

Are circular imports valid flatbuffer schema? Since other similar schemas seem to support it, IMO this should be specified somewhere in the flatbuffer documentation; in the absence of a formal spec, it could go here in the section on "Includes".

https://flatbuffers.dev/flatbuffers_guide_writing_schema.html

Whether or not circular imports are supported, here's a minimized example that I think should ether throw an error about the circular dependency, or successfully generate code, depending on the intended flatc behavior.

Minimized example:

// a.fbs 
include "b.fbs";
namespace a;

enum A : int {
  a = 0,
  b = 1,
  c = 2,
}
// b.fbs
include "a.fbs";
namespace b;

table B {
  some_a:a.A;
}
$ flatc --rust a.fbs

error:
  /home/andrew-otiv/otiv3/otiv3/middleware_types/minimized_example/a.fbs:9: 0: error: type referenced but not defined (check namespace): a.A, originally at: b.fbs:5

(The wider context) The .fbs files were generated from .proto files containting the same circular import. The .proto files were generated from .xsd files containing the same circular import. This original circularity wasn't intentional and I'll try to resolve it at the source.

andrew-otiv commented 1 month ago

Closing because our situation is changed. Thanks!