From e9f1f4d9b7fb41f9f66a24ef03ccbea1780d2674 Mon Sep 17 00:00:00 2001 From: Wouter van Oortmerssen Date: Fri, 2 Jun 2017 15:55:02 -0700 Subject: [PATCH] Disallowing field name same as table name. Change-Id: I4b5d822cc4eda975949d1b7cf33674c5bbf9d4b1 Tested: on Linux. --- src/idl_parser.cpp | 4 ++++ tests/test.cpp | 1 + 2 files changed, 5 insertions(+) diff --git a/src/idl_parser.cpp b/src/idl_parser.cpp index a3a72f6..5c7a69f 100644 --- a/src/idl_parser.cpp +++ b/src/idl_parser.cpp @@ -601,6 +601,10 @@ 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) + return Error("field name can not be the same as table/struct name"); + std::vector dc = doc_comment_; EXPECT(kTokenIdentifier); EXPECT(':'); diff --git a/tests/test.cpp b/tests/test.cpp index 732806d..26181d2 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -1038,6 +1038,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("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 }", -- 2.7.4