fix fuzzer failure in tupleElement formatting

This commit is contained in:
Alexander Kuzmenkov 2021-03-19 02:28:13 +03:00
parent 1b2ed51ff5
commit 46e4134deb

View File

@ -324,10 +324,14 @@ void ASTFunction::formatImplWithoutAlias(const FormatSettings & settings, Format
if (!written && 0 == strcmp(name.c_str(), "tupleElement"))
{
/// It can be printed in a form of 'x.1' only if right hand side is unsigned integer literal.
// It can be printed in a form of 'x.1' only if right hand side
// is an unsigned integer lineral. We also allow nonnegative
// signed integer literals, because the fuzzer sometimes inserts
// them, and we want to have consistent formatting.
if (const auto * lit = arguments->children[1]->as<ASTLiteral>())
{
if (lit->value.getType() == Field::Types::UInt64)
if (isInt64FieldType(lit->value.getType())
&& lit->value.get<Int64>() >= 0)
{
if (frame.need_parens)
settings.ostr << '(';