From ee9b4758757e70804eec8352a98bb9fe8f2bf5eb Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Wed, 3 Jun 2026 13:14:55 +0100 Subject: [PATCH 1/3] [2024 edition] Deprecate method prefix type qualifiers --- compiler/src/dmd/parse.d | 13 ++++++++++++ compiler/test/fail_compilation/prefix_qual.d | 21 ++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 compiler/test/fail_compilation/prefix_qual.d diff --git a/compiler/src/dmd/parse.d b/compiler/src/dmd/parse.d index ef93b59e3414..5acff82f1d53 100644 --- a/compiler/src/dmd/parse.d +++ b/compiler/src/dmd/parse.d @@ -4287,6 +4287,19 @@ class Parser(AST, Lexer = dmd.lexer.Lexer) : Lexer } } + if (mod.edition >= Edition.v2024 && storageClass & STC.TYPECTOR) + { + auto stc = storageClass & STC.TYPECTOR; + auto qual = (AST.stcToString(stc) ~ '\0').ptr; + deprecation(token.loc, "function declaration `%s` has `%s` type qualifier in prefix position", + pident.toChars(), qual); + if (t) + deprecationSupplemental("either use return type `%s(%s)` instead or move qualifier after parameter list", + qual, t.toChars()); + else + deprecationSupplemental("add `auto` if necessary and move `%s` after parameter list", + qual); + } auto parameterList = parseParameterList(null); /* Parse const/immutable/shared/inout/nothrow/pure/return postfix diff --git a/compiler/test/fail_compilation/prefix_qual.d b/compiler/test/fail_compilation/prefix_qual.d new file mode 100644 index 000000000000..41aee4f2ded1 --- /dev/null +++ b/compiler/test/fail_compilation/prefix_qual.d @@ -0,0 +1,21 @@ +/* +REQUIRED_ARGS: -de +TEST_OUTPUT: +--- +fail_compilation/prefix_qual.d(17): Deprecation: function declaration `f` has `const` type qualifier in prefix position +fail_compilation/prefix_qual.d(17): either use return type `const(int)` instead or move qualifier after parameter list +fail_compilation/prefix_qual.d(18): Deprecation: function declaration `bar` has `const` type qualifier in prefix position +fail_compilation/prefix_qual.d(18): either use return type `const(Foo*)` instead or move qualifier after parameter list +fail_compilation/prefix_qual.d(20): Deprecation: function declaration `g` has `inout` type qualifier in prefix position +fail_compilation/prefix_qual.d(20): add `auto` if necessary and move `inout` after parameter list +--- +*/ + +module m 2024; + +struct Foo { + ref const int f(); + shared const Foo* bar(); + // inferred return type + inout g() => 2; +} From 301bfbdc3e00f4cfafb8ce56242fcaea28612f5e Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Wed, 3 Jun 2026 14:53:52 +0100 Subject: [PATCH 2/3] Test mass qualifiers still work --- compiler/test/fail_compilation/prefix_qual.d | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/compiler/test/fail_compilation/prefix_qual.d b/compiler/test/fail_compilation/prefix_qual.d index 41aee4f2ded1..e39a62cb5da9 100644 --- a/compiler/test/fail_compilation/prefix_qual.d +++ b/compiler/test/fail_compilation/prefix_qual.d @@ -18,4 +18,11 @@ struct Foo { shared const Foo* bar(); // inferred return type inout g() => 2; + +// OK +const { + void h(); +} +const: + void i(); } From b09c420780e6c963a0098003c5bcf61b9b6a914c Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Wed, 3 Jun 2026 15:24:30 +0100 Subject: [PATCH 3/3] Fix conflicting param type for astbase --- compiler/src/dmd/parse.d | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/dmd/parse.d b/compiler/src/dmd/parse.d index 5acff82f1d53..f9e7b63df5c5 100644 --- a/compiler/src/dmd/parse.d +++ b/compiler/src/dmd/parse.d @@ -4289,7 +4289,7 @@ class Parser(AST, Lexer = dmd.lexer.Lexer) : Lexer if (mod.edition >= Edition.v2024 && storageClass & STC.TYPECTOR) { - auto stc = storageClass & STC.TYPECTOR; + typeof(AST.Declaration.storage_class) stc = storageClass & STC.TYPECTOR; auto qual = (AST.stcToString(stc) ~ '\0').ptr; deprecation(token.loc, "function declaration `%s` has `%s` type qualifier in prefix position", pident.toChars(), qual);