Fix comment before contract

Fixes #451.
This commit is contained in:
Eugen Wissner 2021-09-07 14:29:45 +02:00
parent 0e5615e13e
commit e8bd41c70d
No known key found for this signature in database
GPG Key ID: A27FDC1E8EE902C0
4 changed files with 131 additions and 11 deletions

View File

@ -1192,11 +1192,13 @@ private:
writeParens(config.dfmt_space_after_cast == OptionalBoolean.t); writeParens(config.dfmt_space_after_cast == OptionalBoolean.t);
break; break;
case tok!"out": case tok!"out":
if (!peekBackIsSlashSlash) {
if (!peekBackIs(tok!"}") if (!peekBackIs(tok!"}")
&& astInformation.contractLocations.canFindIndex(current.index)) && astInformation.contractLocations.canFindIndex(current.index))
newline(); newline();
else if (peekBackIsKeyword) else if (peekBackIsKeyword)
write(" "); write(" ");
}
writeToken(); writeToken();
if (!currentIs(tok!"{") && !currentIs(tok!"comment")) if (!currentIs(tok!"{") && !currentIs(tok!"comment"))
write(" "); write(" ");
@ -1220,6 +1222,7 @@ private:
break; break;
case tok!"in": case tok!"in":
immutable isContract = astInformation.contractLocations.canFindIndex(current.index); immutable isContract = astInformation.contractLocations.canFindIndex(current.index);
if (!peekBackIsSlashSlash) {
if (isContract) if (isContract)
{ {
indents.popTempIndents(); indents.popTempIndents();
@ -1227,6 +1230,7 @@ private:
} }
else if (!peekBackIsOneOf(false, tok!"(", tok!",", tok!"!")) else if (!peekBackIsOneOf(false, tok!"(", tok!",", tok!"!"))
write(" "); write(" ");
}
writeToken(); writeToken();
immutable isFunctionLit = astInformation.funLitStartLocations.canFindIndex( immutable isFunctionLit = astInformation.funLitStartLocations.canFindIndex(
current.index); current.index);

View File

@ -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
tests/issue0451.d Normal file
View File

@ -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;
}
}

View File

@ -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;
}
}