From dca92a75b79ff1209af0f906615e29c2272f1019 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Thu, 18 Apr 2024 08:26:20 +0100 Subject: [PATCH] [editions] Make `body` after contract an error (#16382) * [editions] Make `body` after contract an error * Mention --help in build.d module comment * Add ASTBase.Module.edition property, always Edition.legacy for now --- compiler/src/build.d | 2 ++ compiler/src/dmd/astbase.d | 1 + compiler/src/dmd/mars.d | 3 ++- compiler/src/dmd/parse.d | 4 ++-- compiler/test/fail_compilation/obsolete_body.d | 11 +++++++++++ 5 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 compiler/test/fail_compilation/obsolete_body.d diff --git a/compiler/src/build.d b/compiler/src/build.d index 2575637b51..8396c3877a 100755 --- a/compiler/src/build.d +++ b/compiler/src/build.d @@ -5,6 +5,8 @@ DMD builder Usage: ./build.d dmd +See `--help` for targets. + detab, tolf, install targets - require the D Language Tools (detab.exe, tolf.exe) https://github.com/dlang/tools. diff --git a/compiler/src/dmd/astbase.d b/compiler/src/dmd/astbase.d index 978847270b..0748c48446 100644 --- a/compiler/src/dmd/astbase.d +++ b/compiler/src/dmd/astbase.d @@ -1397,6 +1397,7 @@ struct ASTBase const FileName srcfile; const(char)[] arg; + Edition edition = Edition.legacy; extern (D) this(const ref Loc loc, const(char)[] filename, Identifier ident, int doDocComment, int doHdrGen) { diff --git a/compiler/src/dmd/mars.d b/compiler/src/dmd/mars.d index 6d4af13dda..767d16ffc0 100644 --- a/compiler/src/dmd/mars.d +++ b/compiler/src/dmd/mars.d @@ -1212,9 +1212,10 @@ bool parseCommandLine(const ref Strings arguments, const size_t argc, ref Param params.warnings = DiagnosticReporting.inform; else if (arg == "-wo") // https://dlang.org/dmd.html#switch-wo { - // Obsolete features has been obsoleted until a DIP for "additions" + // Obsolete features has been obsoleted until a DIP for "editions" // has been drafted and ratified in the language spec. // Rather, these old features will just be accepted without warning. + // See also: @__edition_latest_do_not_use } else if (arg == "-O") // https://dlang.org/dmd.html#switch-O driverParams.optimize = true; diff --git a/compiler/src/dmd/parse.d b/compiler/src/dmd/parse.d index f3a844dff2..a459b89e52 100644 --- a/compiler/src/dmd/parse.d +++ b/compiler/src/dmd/parse.d @@ -9589,9 +9589,9 @@ class Parser(AST, Lexer = dmd.lexer.Lexer) : Lexer void usageOfBodyKeyword() { - version (none) // disable obsolete warning + if (mod.edition >= Edition.v2024) { - eSink.warning(token.loc, "usage of identifer `body` as a keyword is obsolete. Use `do` instead."); + eSink.error(token.loc, "usage of identifer `body` as a keyword is obsolete. Use `do` instead."); } } } diff --git a/compiler/test/fail_compilation/obsolete_body.d b/compiler/test/fail_compilation/obsolete_body.d new file mode 100644 index 0000000000..86d8bbc5d3 --- /dev/null +++ b/compiler/test/fail_compilation/obsolete_body.d @@ -0,0 +1,11 @@ +/* +TEST_OUTPUT: +--- +fail_compilation/obsolete_body.d(11): Error: usage of identifer `body` as a keyword is obsolete. Use `do` instead. +--- +*/ +@__edition_latest_do_not_use +module m; + +void test() +in { } body { }