diff --git a/src/dfmt/formatter.d b/src/dfmt/formatter.d index 248b82b..b29677e 100644 --- a/src/dfmt/formatter.d +++ b/src/dfmt/formatter.d @@ -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(); } diff --git a/tests/allman/issue0601.d.ref b/tests/allman/issue0601.d.ref index ef93926..671f2fe 100644 --- a/tests/allman/issue0601.d.ref +++ b/tests/allman/issue0601.d.ref @@ -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(); } diff --git a/tests/issue0601.d b/tests/issue0601.d index ef93926..9a00dc9 100644 --- a/tests/issue0601.d +++ b/tests/issue0601.d @@ -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(); } diff --git a/tests/knr/issue0601.d.ref b/tests/knr/issue0601.d.ref index 8000432..bbe3992 100644 --- a/tests/knr/issue0601.d.ref +++ b/tests/knr/issue0601.d.ref @@ -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(); } diff --git a/tests/otbs/issue0601.d.ref b/tests/otbs/issue0601.d.ref index 420bebb..d912969 100644 --- a/tests/otbs/issue0601.d.ref +++ b/tests/otbs/issue0601.d.ref @@ -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(); }