From a20c55bea56bcc955cecf1087778647346182cd6 Mon Sep 17 00:00:00 2001 From: Vladimir Glavnyy <31897320+vglavnyy@users.noreply.github.com> Date: Sat, 27 Jul 2019 07:56:41 +0700 Subject: [PATCH] Extend the error message if base type of parsed scalar not resolved (#5456) * Extend the error message if base type of parsed scalar not resolved #5447 * Resolve PR notes --- src/idl_parser.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/idl_parser.cpp b/src/idl_parser.cpp index 21443a4..31b315c 100644 --- a/src/idl_parser.cpp +++ b/src/idl_parser.cpp @@ -1639,8 +1639,9 @@ CheckedError Parser::ParseSingleValue(const std::string *name, Value &e, // An integer constant in string. TRY_ECHECK(kTokenStringOrIdent, IsInteger(in_type), BASE_TYPE_INT); // Unknown tokens will be interpreted as string type. + // An attribute value may be a scalar or string constant. FORCE_ECHECK(kTokenStringConstant, in_type == BASE_TYPE_STRING, - BASE_TYPE_STRING); + BASE_TYPE_STRING); } else { // Try a float number. TRY_ECHECK(kTokenFloatConstant, IsFloat(in_type), BASE_TYPE_FLOAT); @@ -1651,7 +1652,12 @@ CheckedError Parser::ParseSingleValue(const std::string *name, Value &e, #undef TRY_ECHECK #undef IF_ECHECK_ - if (!match) return TokenError(); + if (!match) { + std::string msg; + msg += "Cannot assign token starting with '" + TokenToStringId(token_) + + "' to value of <" + std::string(kTypeNames[in_type]) + "> type."; + return Error(msg); + } const auto match_type = e.type.base_type; // may differ from in_type // The check_now flag must be true when parse a fbs-schema. // This flag forces to check default scalar values or metadata of field. -- 2.7.4