dvidelabs / flatcc

FlatBuffers Compiler and Library in C for C
Apache License 2.0
631 stars 180 forks source link

Error compiling nested structs with empty namespace #265

Closed cym-Asaf closed 10 months ago

cym-Asaf commented 10 months ago

Platform

Result of lsb_release -a:

Distributor ID: Ubuntu
Description:    Ubuntu 20.04.6 LTS
Release:    20.04
Codename:   focal

running on x86_64 vm

Result of flatcc --version:

flatcc FlatBuffers schema compiler for C by dvide.com
version: 0.6.2

Error case:

When using empty namespace (namespace ;), error on attempting to compile nested struct/tables.

Contents of t.fbs, which was the output of flatc --proto:

// Generated from t.proto

namespace ;

table t {
  a:uint;
}

table u {
  b:t;
}

output of ./flatcc -a t.fbs:

temp.fbs:10:5: error: '': unknown type reference used with table field: temp.fbs:10:3: 'b'
output failed

No files generated.

With the exact same input .fbs file, flatc successfully compiles where flatcc does not.

Replicated with replacement of tables with structs (all combinations), though the error does correctly identify when u is a struct rather than a table.

Does not give this error on removing the namespace declaration altogether, does not give this error when a non-empty namespace is given.

mikkelfj commented 10 months ago

Thanks for reporting, I can reproduce on latest. I believe I have ad-hoc testet empty namespace before, though it clearly fails here. The case might seem obscure, but it is actually important in order to revert back to a top-level namespace after using another namespace.

mikkelfj commented 10 months ago

Fixed in 05295db

Apparently conventions changed from having a null pointer as root scope to an actual scope object. Parsing empty namespace would attempt to set root scope using null by design, but is now updated to set the actual root scope object. Parser consequently now tracks the root_scope object.