mirror of
https://github.com/google/flatbuffers.git
synced 2026-07-01 17:33:57 +00:00
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
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
d7c2b388ef
commit
a20c55bea5
@@ -1639,8 +1639,9 @@ CheckedError Parser::ParseSingleValue(const std::string *name, Value &e,
|
|||||||
// An integer constant in string.
|
// An integer constant in string.
|
||||||
TRY_ECHECK(kTokenStringOrIdent, IsInteger(in_type), BASE_TYPE_INT);
|
TRY_ECHECK(kTokenStringOrIdent, IsInteger(in_type), BASE_TYPE_INT);
|
||||||
// Unknown tokens will be interpreted as string type.
|
// 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,
|
FORCE_ECHECK(kTokenStringConstant, in_type == BASE_TYPE_STRING,
|
||||||
BASE_TYPE_STRING);
|
BASE_TYPE_STRING);
|
||||||
} else {
|
} else {
|
||||||
// Try a float number.
|
// Try a float number.
|
||||||
TRY_ECHECK(kTokenFloatConstant, IsFloat(in_type), BASE_TYPE_FLOAT);
|
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 TRY_ECHECK
|
||||||
#undef IF_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
|
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.
|
// The check_now flag must be true when parse a fbs-schema.
|
||||||
// This flag forces to check default scalar values or metadata of field.
|
// This flag forces to check default scalar values or metadata of field.
|
||||||
|
|||||||
Reference in New Issue
Block a user