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 (!peekBackIs(tok!"}") if (!peekBackIsSlashSlash) {
&& astInformation.contractLocations.canFindIndex(current.index)) if (!peekBackIs(tok!"}")
newline(); && astInformation.contractLocations.canFindIndex(current.index))
else if (peekBackIsKeyword) newline();
write(" "); else if (peekBackIsKeyword)
write(" ");
}
writeToken(); writeToken();
if (!currentIs(tok!"{") && !currentIs(tok!"comment")) if (!currentIs(tok!"{") && !currentIs(tok!"comment"))
write(" "); write(" ");
@ -1220,13 +1222,15 @@ private:
break; break;
case tok!"in": case tok!"in":
immutable isContract = astInformation.contractLocations.canFindIndex(current.index); immutable isContract = astInformation.contractLocations.canFindIndex(current.index);
if (isContract) if (!peekBackIsSlashSlash) {
{ if (isContract)
indents.popTempIndents(); {
newline(); indents.popTempIndents();
newline();
}
else if (!peekBackIsOneOf(false, tok!"(", tok!",", tok!"!"))
write(" ");
} }
else if (!peekBackIsOneOf(false, tok!"(", tok!",", tok!"!"))
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;
}
}