Skip to content

Commit

Permalink
add some missing hasCurrent checks
Browse files Browse the repository at this point in the history
  • Loading branch information
WebFreak001 committed Mar 1, 2023
1 parent dba8c87 commit a91f044
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/dfmt/formatter.d
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,9 @@ private:
else if (currentIs(tok!"return"))
{
writeToken();
if (!currentIs(tok!";") && !currentIs(tok!")") && !currentIs(tok!"{")
if (hasCurrent && (!currentIs(tok!";") && !currentIs(tok!")") && !currentIs(tok!"{")
&& !currentIs(tok!"in") && !currentIs(tok!"out") && !currentIs(tok!"do")
&& (hasCurrent && tokens[index].text != "body"))
&& tokens[index].text != "body"))
write(" ");
}
else if (currentIs(tok!"with"))
Expand All @@ -258,14 +258,14 @@ private:
indents.push(tok!"with");
writeToken();
write(" ");
if (currentIs(tok!"("))
if (hasCurrent && currentIs(tok!"("))
writeParens(false);
if (!currentIs(tok!"switch") && !currentIs(tok!"with")
if (hasCurrent && !currentIs(tok!"switch") && !currentIs(tok!"with")
&& !currentIs(tok!"{") && !(currentIs(tok!"final") && peekIs(tok!"switch")))
{
newline();
}
else if (!currentIs(tok!"{"))
else if (hasCurrent && !currentIs(tok!"{"))
write(" ");
}
else if (currentIs(tok!"switch"))
Expand Down Expand Up @@ -351,7 +351,7 @@ private:
else if (isBasicType(current.type))
{
writeToken();
if (currentIs(tok!"identifier") || isKeyword(current.type) || inAsm)
if (hasCurrent && (currentIs(tok!"identifier") || isKeyword(current.type) || inAsm))
write(" ");
}
else if (isOperator(current.type))
Expand Down Expand Up @@ -1233,7 +1233,7 @@ private:
break;
case tok!"cast":
writeToken();
if (currentIs(tok!"("))
if (hasCurrent && currentIs(tok!"("))
writeParens(config.dfmt_space_after_cast == OptionalBoolean.t);
break;
case tok!"out":
Expand All @@ -1245,14 +1245,14 @@ private:
write(" ");
}
writeToken();
if (!currentIs(tok!"{") && !currentIs(tok!"comment"))
if (hasCurrent && !currentIs(tok!"{") && !currentIs(tok!"comment"))
write(" ");
break;
case tok!"try":
case tok!"finally":
indents.push(current.type);
writeToken();
if (!currentIs(tok!"{"))
if (hasCurrent && !currentIs(tok!"{"))
newline();
break;
case tok!"identifier":
Expand All @@ -1277,6 +1277,8 @@ private:
write(" ");
}
writeToken();
if (!hasCurrent)
return;
immutable isFunctionLit = astInformation.funLitStartLocations.canFindIndex(
current.index);
if (isFunctionLit && config.dfmt_brace_style == BraceStyle.allman)
Expand All @@ -1289,12 +1291,12 @@ private:
tok!"}", tok!"=", tok!"&&", tok!"||") && !peekBackIsKeyword())
write(" ");
writeToken();
if (!currentIs(tok!"(") && !currentIs(tok!"{") && !currentIs(tok!"comment"))
if (hasCurrent && !currentIs(tok!"(") && !currentIs(tok!"{") && !currentIs(tok!"comment"))
write(" ");
break;
case tok!"case":
writeToken();
if (!currentIs(tok!";"))
if (hasCurrent && !currentIs(tok!";"))
write(" ");
break;
case tok!"enum":
Expand All @@ -1308,7 +1310,7 @@ private:
write(" ");
indents.push(tok!"enum");
writeToken();
if (!currentIs(tok!":") && !currentIs(tok!"{"))
if (hasCurrent && !currentIs(tok!":") && !currentIs(tok!"{"))
write(" ");
}
break;
Expand All @@ -1332,7 +1334,7 @@ private:
goto default;
case tok!"invariant":
writeToken();
if (currentIs(tok!"("))
if (hasCurrent && currentIs(tok!"("))
write(" ");
break;
default:
Expand Down
1 change: 1 addition & 0 deletions tests/allman/incomplete_alias.d.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alias u8 = ubyte
1 change: 1 addition & 0 deletions tests/incomplete_alias.d
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alias u8 = ubyte
1 change: 1 addition & 0 deletions tests/otbs/incomplete_alias.d.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alias u8 = ubyte

0 comments on commit a91f044

Please sign in to comment.