Merge pull request #542 from belka-ew/comment-before-contract

Fix comment before contract
This commit is contained in:
Max Haughton 2021-09-07 16:46:42 +01:00 committed by GitHub
commit e5e11604f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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;
}
}