-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Closed as not planned
Labels
Description
The new flatc 23.1.4 generates broken Rust code when a field with a union type contains a number.
namespace test;
table FieldTable {}
union FieldUnion {
f :FieldTable (id: 0),
}
table RootTable {
field42 :FieldUnion (id: 1);
}
root_type RootTable;
This produces references to field_42_type()
in the generated code, but the method is correctly called field42_type()
.
$ grep -i -B3 -A3 field_42_type src/test_generated.rs
#[inline]
#[allow(non_snake_case)]
pub fn field42_as_f(&self) -> Option<FieldTable<'a>> {
if self.field_42_type() == FieldUnion::f {
self.field42().map(|t| {
// Safety:
// Created from a valid Table for this object
--
use self::flatbuffers::Verifiable;
v.visit_table(pos)?
.visit_union::<FieldUnion, _>(
"field_42_type",
Self::VT_FIELD42_TYPE,
"field42",
Self::VT_FIELD42,
--
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let mut ds = f.debug_struct("RootTable");
ds.field("field42_type", &self.field42_type());
match self.field_42_type() {
FieldUnion::f => {
if let Some(x) = self.field42_as_f() {
ds.field("field42", &x)
I pinpointed this to commit a078130 from #7659. flatc built from parent commit produces correct code.