Skip to content

Commit 7f91150

Browse files
committed
[2024 edition] Disallow alias ... ident; syntax
1 parent 7c43411 commit 7f91150

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

compiler/src/dmd/parse.d

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4637,9 +4637,11 @@ class Parser(AST, Lexer = dmd.lexer.Lexer) : Lexer
46374637

46384638
if (isAliasDeclaration)
46394639
{
4640-
AST.Declaration v;
4641-
AST.Initializer _init = null;
4642-
4640+
if (mod.edition >= Edition.v2024)
4641+
{
4642+
eSink.error(token.loc, "use `alias %s = ...;` syntax instead of `alias ... %s;`",
4643+
ident.toChars(), ident.toChars());
4644+
}
46434645
/* Aliases can no longer have multiple declarators, storage classes,
46444646
* linkages, or auto declarations.
46454647
* These never made any sense, anyway.
@@ -4650,6 +4652,7 @@ class Parser(AST, Lexer = dmd.lexer.Lexer) : Lexer
46504652
if (udas)
46514653
error("user-defined attributes not allowed for `alias` declarations");
46524654

4655+
AST.Initializer _init = null;
46534656
if (token.value == TOK.assign)
46544657
{
46554658
nextToken();
@@ -4659,7 +4662,7 @@ class Parser(AST, Lexer = dmd.lexer.Lexer) : Lexer
46594662
{
46604663
error("alias cannot have initializer");
46614664
}
4662-
v = new AST.AliasDeclaration(aliasLoc, ident, t);
4665+
AST.Declaration v = new AST.AliasDeclaration(aliasLoc, ident, t);
46634666

46644667
v.storage_class = storage_class;
46654668
if (pAttrs)

compiler/test/fail_compilation/obsolete_body.d

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
TEST_OUTPUT:
33
---
44
fail_compilation/obsolete_body.d(11): Error: usage of identifer `body` as a keyword is obsolete. Use `do` instead.
5+
fail_compilation/obsolete_body.d(13): Error: use `alias i32 = ...;` syntax instead of `alias ... i32;`
56
---
67
*/
7-
@__edition_latest_do_not_use
8-
module m;
8+
module m 2024;
99

1010
void test()
1111
in { } body { }
12+
13+
alias int i32;

0 commit comments

Comments
 (0)