dvidelabs / flatcc

FlatBuffers Compiler and Library in C for C
Apache License 2.0
646 stars 182 forks source link

Unexpected error of "id attribute value should be larger to accommodate hidden union type field" #271

Closed hehaoqian closed 10 months ago

hehaoqian commented 10 months ago

The following flatbuffer schema does not compile with flatcc, but is okay with flatc

table Alice {

}

table Bob {

}

union Bar {
    a:Alice,
    b:Bob,
}

table Foo {
  bar:Bar (id: 1);
}

Error message:

test.fbs:16:12: error: 'id': id attribute value should be larger to accommodate hidden union type field
output failed

This issue only happens if union id is set to 1. Set to other id works.

table Alice {

}

table Bob {

}

union Bar {
    a:Alice,
    b:Bob,
}

table Foo {
  a:uint64 (id: 0);
  bar:Bar (id: 2);
}
mikkelfj commented 10 months ago

Thanks. The union logic assumed 1 was the smallest id, when in fact 0 is a valid id. Fixed in https://github.com/dvidelabs/flatcc/commit/354a5f905162cf5ae3bdfbfbc9d6c57411ec3404