Skip to content

Commit

Permalink
Prevent empty statements at the end of --eval or --loop code
Browse files Browse the repository at this point in the history
This patch replaces the old ad-hoc generation of `--eval` or `--loop`
program code with calls to the new `makeEvalCode` function.  Besides
improving separation of concerns, this also ensures that the generated
code will never have a trailing blank statement (i.e. two `;` separated
at most by whitespace).  This should prevent issues when using `--eval`
or `--loop` with a `--compiler` choice that is fussy about such things;
see dlang#297 (comment) for
an example.
  • Loading branch information
WebDrake authored and wilzbach committed Feb 7, 2018
1 parent 6c80c32 commit 2744fa5
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions rdmd.d
Original file line number Diff line number Diff line change
Expand Up @@ -180,18 +180,14 @@ int main(string[] args)
{
enforce(programPos == args.length, "Cannot have both --loop and a " ~
"program file ('" ~ args[programPos] ~ "').");
root = makeEvalFile(importWorld ~ "void main(char[][] args) { "
~ "foreach (line; std.stdio.stdin.byLine()) {\n"
~ std.string.join(loop, "\n")
~ ";\n} }");
root = makeEvalFile(makeEvalCode(loop, Yes.loop));
argsBeforeProgram ~= "-d";
}
else if (eval.ptr)
{
enforce(programPos == args.length, "Cannot have both --eval and a " ~
"program file ('" ~ args[programPos] ~ "').");
root = makeEvalFile(importWorld ~ "void main(char[][] args) {\n"
~ std.string.join(eval, "\n") ~ ";\n}");
root = makeEvalFile(makeEvalCode(eval, No.loop));
argsBeforeProgram ~= "-d";
}
else if (programPos < args.length)
Expand Down

0 comments on commit 2744fa5

Please sign in to comment.