From 7f07be7f0d172f1bf67901ca8683d11cfc3f73a5 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Sat, 20 Jul 2024 15:01:45 +0100 Subject: [PATCH] [.di generation] Show TypeCtor method attributes after parameters (#16732) * [.di generation] Show TypeCtor method attributes after parameters Follow up to https://github.com/dlang/dmd/pull/16708. * Add changelog --- changelog/dmd.postfix-this-attributes.dd | 13 +++++++++++++ compiler/src/dmd/hdrgen.d | 6 +++--- compiler/test/compilable/extra-files/header1.di | 12 ++++++------ compiler/test/compilable/extra-files/header1i.di | 12 ++++++------ compiler/test/compilable/header18365.d | 2 +- 5 files changed, 29 insertions(+), 16 deletions(-) create mode 100644 changelog/dmd.postfix-this-attributes.dd diff --git a/changelog/dmd.postfix-this-attributes.dd b/changelog/dmd.postfix-this-attributes.dd new file mode 100644 index 000000000000..1a299d1aea6c --- /dev/null +++ b/changelog/dmd.postfix-this-attributes.dd @@ -0,0 +1,13 @@ +Postfix type qualifier method attributes for `-H` and `-D` + +`.di` interface file generation and Ddoc output will now have type qualifier +attributes placed after the parameter list for methods (and constructors). +This avoids confusion with the return type. + +--- +struct S +{ + const int f(); // before + int f() const; // now +} +--- diff --git a/compiler/src/dmd/hdrgen.d b/compiler/src/dmd/hdrgen.d index 7b355e8a5270..203cfe35806d 100644 --- a/compiler/src/dmd/hdrgen.d +++ b/compiler/src/dmd/hdrgen.d @@ -3927,7 +3927,7 @@ private void visitFuncIdentWithPrefix(TypeFunction t, const Identifier ident, Te /* Use 'storage class' (prefix) style for attributes */ - if (t.mod && !hgs.ddoc) + if (t.mod && !(hgs.ddoc || hgs.hdrgen)) { MODtoBuffer(buf, t.mod); buf.writeByte(' '); @@ -3977,8 +3977,8 @@ private void visitFuncIdentWithPrefix(TypeFunction t, const Identifier ident, Te buf.writeByte(')'); } parametersToBuffer(t.parameterList, buf, hgs); - // postfix TypeCtor attributes are more readable - if (t.mod && hgs.ddoc) + // postfix this attributes are more readable + if (t.mod && (hgs.ddoc || hgs.hdrgen)) { buf.writeByte(' '); MODtoBuffer(buf, t.mod); diff --git a/compiler/test/compilable/extra-files/header1.di b/compiler/test/compilable/extra-files/header1.di index 91422fed8ab4..a894d0847b5e 100644 --- a/compiler/test/compilable/extra-files/header1.di +++ b/compiler/test/compilable/extra-files/header1.di @@ -359,8 +359,8 @@ int bar11(T)() } struct S6360 { - const pure nothrow @property long weeks1(); - const pure nothrow @property long weeks2(); + pure nothrow @property long weeks1() const; + pure nothrow @property long weeks2() const; } struct S12 { @@ -369,10 +369,10 @@ struct S12 } struct T12 { - immutable this()(int args) + this()(int args) immutable { } - immutable this(A...)(A args) + this(A...)(A args) immutable { } } @@ -502,7 +502,7 @@ size_t magic(); class Foo2A { immutable(FooA) Dummy = new immutable(FooA); - private immutable pure nothrow @nogc @safe this(); + private pure nothrow @nogc @safe this() immutable; } struct Foo3A(T) { @@ -560,4 +560,4 @@ interface I12344 assert(result > 0); } ; -} +} \ No newline at end of file diff --git a/compiler/test/compilable/extra-files/header1i.di b/compiler/test/compilable/extra-files/header1i.di index a77f3cb0945c..754c7ac80b6f 100644 --- a/compiler/test/compilable/extra-files/header1i.di +++ b/compiler/test/compilable/extra-files/header1i.di @@ -452,11 +452,11 @@ int bar11(T)() } struct S6360 { - const pure nothrow @property long weeks1() + pure nothrow @property long weeks1() const { return 0; } - const pure nothrow @property long weeks2() + pure nothrow @property long weeks2() const { return 0; } @@ -472,10 +472,10 @@ struct S12 } struct T12 { - immutable this()(int args) + this()(int args) immutable { } - immutable this(A...)(A args) + this(A...)(A args) immutable { } } @@ -624,7 +624,7 @@ size_t magic() class Foo2A { immutable(FooA) Dummy = new immutable(FooA); - private immutable pure nothrow @nogc @safe this() + private pure nothrow @nogc @safe this() immutable { } } @@ -715,4 +715,4 @@ interface I12344 assert(result > 0); } ; -} +} \ No newline at end of file diff --git a/compiler/test/compilable/header18365.d b/compiler/test/compilable/header18365.d index 7e51fb26cc77..8846c86c445f 100644 --- a/compiler/test/compilable/header18365.d +++ b/compiler/test/compilable/header18365.d @@ -13,7 +13,7 @@ struct FullCaseEntry ubyte n; ubyte size; ubyte entry_len; - auto const pure nothrow @nogc @property @trusted value() return + auto pure nothrow @nogc @property @trusted value() const return { return seq[0..entry_len]; }