Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion compiler/src/dmd/dmodule.d
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ extern (C++) final class Module : Package
if (doHdrGen)
hdrfile = setOutfilename(global.params.dihdr.name, global.params.dihdr.dir, arg, hdr_ext);

this.edition = Edition.min;
this.edition = global.params.edition;
}

extern (D) this(const(char)[] filename, Identifier ident, int doDocComment, int doHdrGen)
Expand Down
2 changes: 2 additions & 0 deletions compiler/src/dmd/mars.d
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,8 @@ bool parseCommandLine(const ref Strings arguments, const size_t argc, out Param
auto filename = p + 1+7+1+4;
files.push(filename);
params.editionFiles[filename] = params.edition;
// FIXME: params.edition should not be set when there's a filename
error("`-edition` is not supported with a filename yet");
}
}
else if (arg == "-fIBT")
Expand Down
4 changes: 3 additions & 1 deletion compiler/src/dmd/parse.d
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ class Parser(AST, Lexer = dmd.lexer.Lexer) : Lexer
error("module edition %lld must be in the range %d ... %d", edition, Edition.min, Edition.max);
edition = edition.min;
}
mod.edition = cast(Edition)edition;
// ModuleDeclaration edition can't lower -edition flag's edition
if (edition > mod.edition)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it can lower it.

The edition switch is only for overriding the default edition (D2/legacy).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This DIP also recommends a -E switch that allows the user to specify a default target edition for all imported modules in a given path. This target overrides the default edition and the -edition flag, if present, for modules in the given path. An example:

The purpose of the switch is for build managers like dub.

mod.edition = cast(Edition)edition;
nextToken();
}

Expand Down
13 changes: 13 additions & 0 deletions compiler/test/fail_compilation/edition_switch.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
REQUIRED_ARGS: -edition=2024
TEST_OUTPUT:
---
fail_compilation/edition_switch.d(13): Error: usage of identifer `body` as a keyword is obsolete. Use `do` instead.
---
*/

// test -edition can override a lower module declaration
module m 2023;

void test()
in { } body { }
Loading