Skip to content

Commit

Permalink
Merge pull request #10693 from Geod24/deprecate-body
Browse files Browse the repository at this point in the history
Fix issue 19325 - Deprecate body keyword
  • Loading branch information
wilzbach committed Dec 23, 2019
2 parents 2634f16 + 3093244 commit f8d88eb
Show file tree
Hide file tree
Showing 32 changed files with 116 additions and 67 deletions.
10 changes: 10 additions & 0 deletions changelog/body-as-keyword.dd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
The keyword `body` is now deprecated

The keyword `body`, used when a function / method has contract,
has now been deprecated, and `do` should be used instead.
Using `do` in place of `body` has been supported since 2.075.0,
after DIP1003 was accepted.
At the same time, `body` was made a contextual keyword,
but kept being non-deprecated due to its prevalence.
According to the deprecation process, `body` will be removed
from the language in release 2.101.0 at the earliest.
2 changes: 1 addition & 1 deletion src/dmd/astbase.d
Original file line number Diff line number Diff line change
Expand Up @@ -6097,7 +6097,7 @@ struct ASTBase
{
assert(!!aggrfe ^ !!rangefe);
}
body
do
{
this.loc = loc;
this.aggrfe = aggrfe;
Expand Down
3 changes: 2 additions & 1 deletion src/dmd/compiler.d
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ private struct ModuleComponentRange
* True if the given module should be included in the compilation.
*/
private bool includeImportedModuleCheck(ModuleComponentRange components)
in { assert(includeImports); } body
in { assert(includeImports); }
do
{
createMatchNodes();
size_t nodeIndex = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/dmd/frontend.d
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ in
{
assert(diagnosticReporter !is null);
}
body
do
{
import dmd.root.file : File, FileBuffer;

Expand Down
4 changes: 2 additions & 2 deletions src/dmd/lexer.d
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ class Lexer
{
assert(diagnosticReporter !is null);
}
body
do
{
this.diagnosticReporter = diagnosticReporter;
scanloc = Loc(filename, 1, 1);
Expand Down Expand Up @@ -1185,7 +1185,7 @@ class Lexer
{
assert(handler !is null);
}
body
do
{
const(char)* p = sequence; // cache sequence reference on stack
scope(exit) sequence = p;
Expand Down
10 changes: 5 additions & 5 deletions src/dmd/objc.d
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ extern(C++) private final class Supported : Objc
{
assert(id.classKind == ClassKind.objc);
}
body
do
{
// don't report deprecations for the metaclass to avoid duplicated
// messages.
Expand Down Expand Up @@ -566,7 +566,7 @@ extern(C++) private final class Supported : Objc
assert(fd.selector);
assert(fd.isMember);
}
body
do
{
// * final member functions are kept virtual with Objective-C linkage
// because the Objective-C runtime always use dynamic dispatch.
Expand All @@ -581,7 +581,7 @@ extern(C++) private final class Supported : Objc
{
assert(metaclass);
}
body
do
{
if (cd.classKind == ClassKind.objc && fd.isStatic && !cd.objc.isMeta)
return cd.objc.metaclass;
Expand All @@ -594,7 +594,7 @@ extern(C++) private final class Supported : Objc
{
assert(fd.parent.isClassDeclaration);
}
body
do
{
if (cd.classKind != ClassKind.objc)
return;
Expand Down Expand Up @@ -632,7 +632,7 @@ extern(C++) private final class Supported : Objc
{
assert(fd.selectorParameter is null);
}
body
do
{
if (!fd.selector)
return null;
Expand Down
12 changes: 6 additions & 6 deletions src/dmd/objc_glue.d
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ extern(C++) final class Supported : ObjcGlue
assert(classDeclaration !is null);
assert(classDeclaration.classKind == ClassKind.objc);
}
body
do
{
if (!classDeclaration.objc.isMeta)
ObjcClassDeclaration(classDeclaration, false).toObjFile();
Expand All @@ -274,7 +274,7 @@ extern(C++) final class Supported : ObjcGlue
{
assert(fd);
}
body
do
{
if (!fd.selector)
return count;
Expand Down Expand Up @@ -619,7 +619,7 @@ static:
{
assert(classDeclaration !is null);
}
body
do
{
return getClassName(ObjcClassDeclaration(classDeclaration, isMeta));
}
Expand Down Expand Up @@ -715,7 +715,7 @@ static:
{
assert(type !is null);
}
body
do
{
enum assertMessage = "imaginary types are not supported by Objective-C";

Expand Down Expand Up @@ -914,7 +914,7 @@ struct ObjcClassDeclaration
{
assert(classDeclaration !is null);
}
body
do
{
this.classDeclaration = classDeclaration;
this.isMeta = isMeta;
Expand Down Expand Up @@ -1280,7 +1280,7 @@ out(result)
{
assert(str.length == result.strlen);
}
body
do
{
if (str.length == 0)
return "".ptr;
Expand Down
22 changes: 22 additions & 0 deletions src/dmd/parse.d
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,11 @@ final class Parser(AST) : Lexer
tk.value == TOK.out_ || tk.value == TOK.do_ ||
tk.value == TOK.identifier && tk.ident == Id._body))
{
// @@@DEPRECATED@@@
// https://github.com/dlang/DIPs/blob/1f5959abe482b1f9094f6484a7d0a3ade77fc2fc/DIPs/accepted/DIP1003.md
// Deprecated in 2.091 - Can be removed from 2.101
if (tk.value == TOK.identifier && tk.ident == Id._body)
deprecation("Usage of the `body` keyword is deprecated. Use `do` instead.");
a = parseDeclarations(true, pAttrs, pAttrs.comment);
if (a && a.dim)
*pLastDecl = (*a)[a.dim - 1];
Expand Down Expand Up @@ -4627,6 +4632,11 @@ final class Parser(AST) : Lexer
(tk.value == TOK.leftParentheses || tk.value == TOK.leftCurly || tk.value == TOK.in_ || tk.value == TOK.out_ ||
tk.value == TOK.do_ || tk.value == TOK.identifier && tk.ident == Id._body))
{
// @@@DEPRECATED@@@
// https://github.com/dlang/DIPs/blob/1f5959abe482b1f9094f6484a7d0a3ade77fc2fc/DIPs/accepted/DIP1003.md
// Deprecated in 2.091 - Can be removed from 2.101
if (tk.value == TOK.identifier && tk.ident == Id._body)
deprecation("Usage of the `body` keyword is deprecated. Use `do` instead.");
ts = null;
}
else
Expand Down Expand Up @@ -4991,7 +5001,13 @@ final class Parser(AST) : Lexer

case TOK.identifier:
if (token.ident == Id._body)
{
// @@@DEPRECATED@@@
// https://github.com/dlang/DIPs/blob/1f5959abe482b1f9094f6484a7d0a3ade77fc2fc/DIPs/accepted/DIP1003.md
// Deprecated in 2.091 - Can be removed from 2.101
deprecation("Usage of the `body` keyword is deprecated. Use `do` instead.");
goto case TOK.do_;
}
goto default;

case TOK.do_:
Expand Down Expand Up @@ -7182,7 +7198,13 @@ final class Parser(AST) : Lexer

case TOK.identifier:
if (t.ident == Id._body)
{
// @@@DEPRECATED@@@
// https://github.com/dlang/DIPs/blob/1f5959abe482b1f9094f6484a7d0a3ade77fc2fc/DIPs/accepted/DIP1003.md
// Deprecated in 2.091 - Can be removed from 2.101
deprecation("Usage of the `body` keyword is deprecated. Use `do` instead.");
goto case TOK.do_;
}
goto default;

case TOK.if_:
Expand Down
6 changes: 3 additions & 3 deletions src/dmd/root/man.d
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ version (Windows)
{
assert(strncmp(url, "http://", 7) == 0 || strncmp(url, "https://", 8) == 0);
}
body
do
{
ShellExecuteA(null, "open", url, null, null, SW_SHOWNORMAL);
}
Expand All @@ -38,7 +38,7 @@ else version (OSX)
{
assert(strncmp(url, "http://", 7) == 0 || strncmp(url, "https://", 8) == 0);
}
body
do
{
pid_t childpid;
const(char)*[5] args;
Expand Down Expand Up @@ -72,7 +72,7 @@ else version (Posix)
{
assert(strncmp(url, "http://", 7) == 0 || strncmp(url, "https://", 8) == 0);
}
body
do
{
pid_t childpid;
const(char)*[3] args;
Expand Down
4 changes: 2 additions & 2 deletions test/compilable/b16967.d
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* REQUIRED_ARGS: -c
* TEST_OUTPUT:
---
Expand Down Expand Up @@ -27,7 +27,7 @@ out(v)
break;
}
}
body
do
{
return 42;
}
4 changes: 2 additions & 2 deletions test/compilable/interpret3.d
Original file line number Diff line number Diff line change
Expand Up @@ -6440,7 +6440,7 @@ label:
break label; // doesn't work.
}
}
body
do
{
int x = 0;
label:
Expand Down Expand Up @@ -7772,7 +7772,7 @@ enum KindEnum
integer,
arrayOf
}

struct FullKind
{
KindEnum[] contents;
Expand Down
4 changes: 2 additions & 2 deletions test/fail_compilation/fail17502.d
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ class Foo
{
void foo()
out (res) { assert(res > 5); }
body {}
do {}

auto bar()
out (res) { assert (res > 5); }
body { return; }
do { return; }
}
2 changes: 1 addition & 1 deletion test/fail_compilation/fail2350.d
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ void test2350()
in
{
}
body
do
{
asm { naked; }
}
4 changes: 2 additions & 2 deletions test/fail_compilation/fail329.d
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class A
assert(x == 7);
result++;
}
body
do
{
return i;
}
Expand All @@ -49,7 +49,7 @@ class B : A
assert(result < 8);
assert(x == 7);
}
body
do
{
return i - 1;
}
Expand Down
2 changes: 1 addition & 1 deletion test/fail_compilation/fail330.d
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ fail_compilation/fail330.d(9): Error: variable `fail330.fun.result` cannot modif

int fun()
out(result) { result = 2; }
body { return 1; }
do { return 1; }
2 changes: 1 addition & 1 deletion test/fail_compilation/fail6242.d
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ fail_compilation/fail6242.d(9): Error: cannot implicitly override base class met
*/
class A { void fun(int) {} }

class B : A { void fun(int x) in { assert(x > 0); } body {} }
class B : A { void fun(int x) in { assert(x > 0); } do {} }
3 changes: 1 addition & 2 deletions test/fail_compilation/fail94.d
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class B : A
{
printf("B.clone()\n");
}
body { return ia; }
do { return ia; }
}

void main()
Expand Down Expand Up @@ -59,4 +59,3 @@ void main()
void bar(IA delegate() dg)
{
}

6 changes: 3 additions & 3 deletions test/fail_compilation/fail9413.d
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ in
s = 10; // err
a = 1; // OK
}
body
do
{
x = 10; // err
y = 1; // OK
Expand Down Expand Up @@ -68,7 +68,7 @@ out(r)
s = 10; // err
a = 1; // OK
}
body
do
{
x = 10; // err
r = 10; // err
Expand All @@ -79,7 +79,7 @@ out(r)
x = 10; // err
r = 10; // err
}
body
do
{
return 1;
}
6 changes: 3 additions & 3 deletions test/fail_compilation/fail9414a.d
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class C
s = 10; // err
a = 1; // OK
}
body
do
{
x = 10; // err
y = 1; // OK
Expand Down Expand Up @@ -70,7 +70,7 @@ class C
s = 10; // err
a = 1; // OK
}
body
do
{
x = 10; // err
r = 10; // err
Expand All @@ -81,7 +81,7 @@ class C
x = 10; // err
r = 10; // err
}
body
do
{
return 1;
}
Expand Down

0 comments on commit f8d88eb

Please sign in to comment.