Check for token before access, fix #474

This commit is contained in:
Jan Jurzitza 2020-04-02 13:39:29 +02:00
parent 7b955c18d1
commit cb1dfe091f
1 changed files with 38 additions and 33 deletions

View File

@ -1093,46 +1093,51 @@ private:
indents.push(current.type); indents.push(current.type);
} }
writeToken(); writeToken();
if (currentIs(tok!"(")) if (currentIs(tok!"("))
{ {
write(" "); write(" ");
writeParens(false); writeParens(false);
} }
if (currentIs(tok!"switch") || (currentIs(tok!"final") && peekIs(tok!"switch")))
write(" "); if (hasCurrent)
else if (currentIs(tok!"comment"))
formatStep();
else if (!shouldPushIndent)
{ {
if (!currentIs(tok!"{") && !currentIs(tok!";")) if (currentIs(tok!"switch") || (currentIs(tok!"final") && peekIs(tok!"switch")))
write(" "); write(" ");
} else if (currentIs(tok!"comment"))
else if (!currentIs(tok!"{") && !currentIs(tok!";") && !currentIs(tok!"in") && formatStep();
!currentIs(tok!"out") && !currentIs(tok!"do") && current.text != "body") else if (!shouldPushIndent)
{ {
newline(); if (!currentIs(tok!"{") && !currentIs(tok!";"))
} write(" ");
else if (currentIs(tok!"{") && indents.topAre(tok!"static", tok!"if")) }
{ else if (hasCurrent && !currentIs(tok!"{") && !currentIs(tok!";") && !currentIs(tok!"in") &&
// Hacks to format braced vs non-braced static if declarations. !currentIs(tok!"out") && !currentIs(tok!"do") && current.text != "body")
indents.pop(); {
indents.pop(); newline();
indents.push(tok!"if"); }
formatLeftBrace(); else if (currentIs(tok!"{") && indents.topAre(tok!"static", tok!"if"))
} {
else if (currentIs(tok!"{") && indents.topAre(tok!"static", tok!"foreach")) // Hacks to format braced vs non-braced static if declarations.
{ indents.pop();
indents.pop(); indents.pop();
indents.pop(); indents.push(tok!"if");
indents.push(tok!"foreach"); formatLeftBrace();
formatLeftBrace(); }
} else if (currentIs(tok!"{") && indents.topAre(tok!"static", tok!"foreach"))
else if (currentIs(tok!"{") && indents.topAre(tok!"static", tok!"foreach_reverse")) {
{ indents.pop();
indents.pop(); indents.pop();
indents.pop(); indents.push(tok!"foreach");
indents.push(tok!"foreach_reverse"); formatLeftBrace();
formatLeftBrace(); }
else if (currentIs(tok!"{") && indents.topAre(tok!"static", tok!"foreach_reverse"))
{
indents.pop();
indents.pop();
indents.push(tok!"foreach_reverse");
formatLeftBrace();
}
} }
} }