Skip to content

Commit

Permalink
Fix comment before contract
Browse files Browse the repository at this point in the history
  • Loading branch information
belka-ew committed Sep 7, 2021
1 parent 0e5615e commit e8bd41c
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/dfmt/formatter.d
Original file line number Diff line number Diff line change
Expand Up @@ -1192,11 +1192,13 @@ private:
writeParens(config.dfmt_space_after_cast == OptionalBoolean.t);
break;
case tok!"out":
if (!peekBackIs(tok!"}")
&& astInformation.contractLocations.canFindIndex(current.index))
newline();
else if (peekBackIsKeyword)
write(" ");
if (!peekBackIsSlashSlash) {
if (!peekBackIs(tok!"}")
&& astInformation.contractLocations.canFindIndex(current.index))
newline();
else if (peekBackIsKeyword)
write(" ");
}
writeToken();
if (!currentIs(tok!"{") && !currentIs(tok!"comment"))
write(" ");
Expand All @@ -1220,13 +1222,15 @@ private:
break;
case tok!"in":
immutable isContract = astInformation.contractLocations.canFindIndex(current.index);
if (isContract)
{
indents.popTempIndents();
newline();
if (!peekBackIsSlashSlash) {
if (isContract)
{
indents.popTempIndents();
newline();
}
else if (!peekBackIsOneOf(false, tok!"(", tok!",", tok!"!"))
write(" ");
}
else if (!peekBackIsOneOf(false, tok!"(", tok!",", tok!"!"))
write(" ");
writeToken();
immutable isFunctionLit = astInformation.funLitStartLocations.canFindIndex(
current.index);
Expand Down
40 changes: 40 additions & 0 deletions tests/allman/issue0451.d.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
class C
{
abstract void f1() //
in (true);

abstract void f2() /* */
in (true);

abstract bool f3() //
out (r; r);

abstract bool f4() /* */
out (r; r);

abstract void f5() //
do
{
}

abstract void f6() /* */
do
{
}

abstract bool f7() //
in (true) //
out (r; r) //
do //
{
return true;
}

abstract bool f8() /* */
in (true) /* */
out (r; r) /* */
do /* */
{
return true;
}
}
40 changes: 40 additions & 0 deletions tests/issue0451.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
class C
{
abstract void f1() //
in (true);

abstract void f2() /* */
in (true);

abstract bool f3() //
out (r; r);

abstract bool f4() /* */
out (r; r);

abstract void f5() //
do
{
}

abstract void f6() /* */
do
{
}

abstract bool f7() //
in (true) //
out (r; r) //
do //
{
return true;
}

abstract bool f8() /* */
in (true) /* */
out (r; r) /* */
do /* */
{
return true;
}
}
36 changes: 36 additions & 0 deletions tests/otbs/issue0451.d.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
class C {
abstract void f1() //
in (true);

abstract void f2() /* */
in (true);

abstract bool f3() //
out (r; r);

abstract bool f4() /* */
out (r; r);

abstract void f5() //
do {
}

abstract void f6() /* */
do {
}

abstract bool f7() //
in (true) //
out (r; r) //
do //
{
return true;
}

abstract bool f8() /* */
in (true) /* */
out (r; r) /* */
do /* */ {
return true;
}
}

0 comments on commit e8bd41c

Please sign in to comment.