From 8a58aafda12bd1b9f7f228dc5f0583cf4f4afe87 Mon Sep 17 00:00:00 2001 From: Wouter van Oortmerssen Date: Thu, 10 Aug 2017 14:22:03 -0700 Subject: [PATCH] Make it an error if a field has the same name as a table. Change-Id: Ie5a3bb5a3643cd48e1cc75fe170a7b8a7c2cc8ed Tested: on Linux. --- src/idl_parser.cpp | 2 +- tests/test.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/idl_parser.cpp b/src/idl_parser.cpp index b27493945..fc3f97b59 100644 --- a/src/idl_parser.cpp +++ b/src/idl_parser.cpp @@ -608,7 +608,7 @@ CheckedError Parser::AddField(StructDef &struct_def, const std::string &name, CheckedError Parser::ParseField(StructDef &struct_def) { std::string name = attribute_; - if (name == struct_def.name) + if (structs_.Lookup(name)) return Error("field name can not be the same as table/struct name"); std::vector dc = doc_comment_; diff --git a/tests/test.cpp b/tests/test.cpp index a8c6faa9e..4b9923904 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -1101,7 +1101,7 @@ void ErrorTest() { TestError("table X { Y:[[int]]; }", "nested vector"); TestError("table X { Y:1; }", "illegal type"); TestError("table X { Y:int; Y:int; }", "field already"); - TestError("table X { X:int; }", "same as table"); + TestError("table Y {} table X { Y:int; }", "same as table"); TestError("struct X { Y:string; }", "only scalar"); TestError("struct X { Y:int (deprecated); }", "deprecate"); TestError("union Z { X } table X { Y:Z; } root_type X; { Y: {}, A:1 }",