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,11 +1093,15 @@ private:
indents.push(current.type); indents.push(current.type);
} }
writeToken(); writeToken();
if (currentIs(tok!"(")) if (currentIs(tok!"("))
{ {
write(" "); write(" ");
writeParens(false); writeParens(false);
} }
if (hasCurrent)
{
if (currentIs(tok!"switch") || (currentIs(tok!"final") && peekIs(tok!"switch"))) if (currentIs(tok!"switch") || (currentIs(tok!"final") && peekIs(tok!"switch")))
write(" "); write(" ");
else if (currentIs(tok!"comment")) else if (currentIs(tok!"comment"))
@ -1107,7 +1111,7 @@ private:
if (!currentIs(tok!"{") && !currentIs(tok!";")) if (!currentIs(tok!"{") && !currentIs(tok!";"))
write(" "); write(" ");
} }
else if (!currentIs(tok!"{") && !currentIs(tok!";") && !currentIs(tok!"in") && else if (hasCurrent && !currentIs(tok!"{") && !currentIs(tok!";") && !currentIs(tok!"in") &&
!currentIs(tok!"out") && !currentIs(tok!"do") && current.text != "body") !currentIs(tok!"out") && !currentIs(tok!"do") && current.text != "body")
{ {
newline(); newline();
@ -1135,6 +1139,7 @@ private:
formatLeftBrace(); formatLeftBrace();
} }
} }
}
void formatElse() void formatElse()
{ {