Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/dfmt/formatter.d
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,9 @@ private:
else
formatBlockHeader();
}
else if ((current.text == "body" || current == tok!"do") && peekBackIsFunctionDeclarationEnding())
else if ((current.text == "body" || current == tok!"do") && peekBackIsFunctionDeclarationEnding()
|| current == tok!"do" && peekBackIs(tok!"identifier")
|| current.text == "body" && peekBackIs(tok!"identifier") && peekIs(tok!"{"))
{
formatKeyword();
}
Expand Down
36 changes: 36 additions & 0 deletions tests/allman/issue0601.d.ref
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,40 @@ struct S
void h() @nogc @trusted return
{
}

void i() @system return
{
}

void j() pure @safe return
{
}

void k() @nogc return
{
}

void l() @trusted
do
{
}

void m() @safe
do
{
}

void n() @nogc @system
do
{
}

void o() pure @safe
do
{
}

// Regression: 'body' as variable name must not be treated as contract keyword
@custom body = 3;
SomeStruct body = foo();
}
32 changes: 32 additions & 0 deletions tests/issue0601.d
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,36 @@ struct S
void h() @nogc @trusted return
{
}

void i() @system return
{
}

void j() pure @safe return
{
}

void k() @nogc return
{
}

void l() @trusted do
{
}

void m() @safe do
{
}

void n() @nogc @system do
{
}

void o() pure @safe do
{
}

// Regression: 'body' as variable name must not be treated as contract keyword
@custom body = 3;
SomeStruct body = foo();
}
32 changes: 32 additions & 0 deletions tests/knr/issue0601.d.ref
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,36 @@ struct S {
void h() @nogc @trusted return
{
}

void i() @system return
{
}

void j() pure @safe return
{
}

void k() @nogc return
{
}

void l() @trusted
do {
}

void m() @safe
do {
}

void n() @nogc @system
do {
}

void o() pure @safe
do {
}

// Regression: 'body' as variable name must not be treated as contract keyword
@custom body = 3;
SomeStruct body = foo();
}
29 changes: 29 additions & 0 deletions tests/otbs/issue0601.d.ref
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,33 @@ struct S {

void h() @nogc @trusted return {
}

void i() @system return {
}

void j() pure @safe return {
}

void k() @nogc return {
}

void l() @trusted
do {
}

void m() @safe
do {
}

void n() @nogc @system
do {
}

void o() pure @safe
do {
}

// Regression: 'body' as variable name must not be treated as contract keyword
@custom body = 3;
SomeStruct body = foo();
}
Loading