From 354a5f905162cf5ae3bdfbfbc9d6c57411ec3404 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikkel=20Fahn=C3=B8e=20J=C3=B8rgensen?= Date: Sun, 26 Nov 2023 15:51:21 +0100 Subject: [PATCH] Fix incorrect compiler error msg when schema has union field with explicit id 1 --- CHANGELOG.md | 3 +++ src/compiler/semantics.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 881e7ff7..b5776923 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,9 @@ so returns null proper and not a small offset on alloc failure. Most platforms do not depend on this function (#269). Also fix equivalent FLATCC_ALIGNED_ALLOC that does not necesserily use malloc. +- Fix flatcc compiler error message when schema has a union as first table field + with explicit id attribute 1. Explict id must leave space for the hidden type + field, but id 1 is valid since id 0 is valid for the type field id. (#271). ## [0.6.1] diff --git a/src/compiler/semantics.c b/src/compiler/semantics.c index d0a766a6..6c56c37b 100644 --- a/src/compiler/semantics.c +++ b/src/compiler/semantics.c @@ -1256,7 +1256,7 @@ static int process_table(fb_parser_t *P, fb_compound_type_t *ct) field_marker[member->id] = normal_field; } if (!id_failed && type_sym && type_sym->kind == fb_is_union) { - if (member->id <= 1) { + if (member->id <= 0) { error_tok(P, m->ident, is_union_vector ? "id attribute value should be larger to accommodate hidden union vector type field" : "id attribute value should be larger to accommodate hidden union type field");