Fix null dereference in using for directive when operator name is empty

This commit is contained in:
Matheus Aguiar
2023-04-18 14:23:58 -03:00
parent ee1b50d345
commit 64f57ac3c7
2 changed files with 14 additions and 1 deletions
+7 -1
View File
@@ -995,11 +995,17 @@ ASTPointer<UsingForDirective> Parser::parseUsingDirective()
Token operator_ = m_scanner->currentToken();
if (!util::contains(userDefinableOperators, operator_))
{
string operatorName;
if (!m_scanner->currentLiteral().empty())
operatorName = m_scanner->currentLiteral();
else if (char const* tokenString = TokenTraits::toString(operator_))
operatorName = string(tokenString);
parserError(
4403_error,
fmt::format(
"Not a user-definable operator: {}. Only the following operators can be user-defined: {}",
(!m_scanner->currentLiteral().empty() ? m_scanner->currentLiteral() : string(TokenTraits::toString(operator_))),
operatorName,
util::joinHumanReadable(userDefinableOperators | ranges::views::transform([](Token _t) { return string{TokenTraits::toString(_t)}; }))
)
);