From 14b46be866ae6b97930366b61d09639ca0455f66 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Thu, 2 May 2024 21:35:35 +0100 Subject: [PATCH 1/3] Fix Bugzilla 22189 - type qualifier not applied to type tuple --- compiler/src/dmd/mtype.d | 18 ++++++++++++++++++ compiler/test/compilable/type_seq_qual.d | 9 +++++++++ 2 files changed, 27 insertions(+) create mode 100644 compiler/test/compilable/type_seq_qual.d diff --git a/compiler/src/dmd/mtype.d b/compiler/src/dmd/mtype.d index 0f4f91d8473f..1baa5c12408a 100644 --- a/compiler/src/dmd/mtype.d +++ b/compiler/src/dmd/mtype.d @@ -4558,6 +4558,24 @@ extern (C++) final class TypeTuple : Type { v.visit(this); } + + override final Type makeImmutable() + { + if (mcache && mcache.ito) + { + assert(mcache.ito.isImmutable()); + return mcache.ito; + } + TypeTuple t = cast(TypeTuple) Type.makeImmutable(); + if (arguments) + { + foreach (ref arg; *t.arguments) + { + arg.type = arg.type.immutableOf(); + } + } + return t; + } } /*********************************************************** diff --git a/compiler/test/compilable/type_seq_qual.d b/compiler/test/compilable/type_seq_qual.d new file mode 100644 index 000000000000..b6ee110ba1e4 --- /dev/null +++ b/compiler/test/compilable/type_seq_qual.d @@ -0,0 +1,9 @@ +alias AliasSeq(Args...) = Args; + +immutable(AliasSeq!(int, float)) c; +immutable AliasSeq!(int, float) d; +static assert(is(typeof(c) == typeof(d))); + +alias TS = AliasSeq!(int, float); +static assert(is(typeof(c) == immutable TS)); +static assert(is(immutable(TS)[0] == immutable int)); From 115887859956f893ec853902975be2ff6be3e95e Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Fri, 3 May 2024 10:50:29 +0100 Subject: [PATCH 2/3] const(TypeQual) --- compiler/src/dmd/mtype.d | 18 ++++++++++++++++++ compiler/test/compilable/type_seq_qual.d | 8 ++++++++ 2 files changed, 26 insertions(+) diff --git a/compiler/src/dmd/mtype.d b/compiler/src/dmd/mtype.d index 1baa5c12408a..1aadac7e3924 100644 --- a/compiler/src/dmd/mtype.d +++ b/compiler/src/dmd/mtype.d @@ -4559,6 +4559,24 @@ extern (C++) final class TypeTuple : Type v.visit(this); } + override final Type makeConst() + { + if (mcache && mcache.cto) + { + assert(mcache.cto.isConst()); + return mcache.cto; + } + TypeTuple t = cast(TypeTuple) Type.makeConst(); + if (arguments) + { + foreach (ref arg; *t.arguments) + { + arg.type = arg.type.addSTC(STC.const_); + } + } + return t; + } + override final Type makeImmutable() { if (mcache && mcache.ito) diff --git a/compiler/test/compilable/type_seq_qual.d b/compiler/test/compilable/type_seq_qual.d index b6ee110ba1e4..2664a5ac2999 100644 --- a/compiler/test/compilable/type_seq_qual.d +++ b/compiler/test/compilable/type_seq_qual.d @@ -7,3 +7,11 @@ static assert(is(typeof(c) == typeof(d))); alias TS = AliasSeq!(int, float); static assert(is(typeof(c) == immutable TS)); static assert(is(immutable(TS)[0] == immutable int)); + +alias CT = const(TS); +static assert(is(const(TS) == const TS)); + +pragma(msg, CT[0]); // const(int) +static assert(is(CT[0] == const int)); // immutable(int) == const(int)!!! +pragma(msg, (const(TS)[0]).stringof); // const(int) +static assert(is(const(TS)[0] == const int)); // immutable(int) == const(int)!!! From a65144873bbe9786d6a1e5e7265bc021a87a87d5 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Sat, 4 May 2024 19:31:31 +0100 Subject: [PATCH 3/3] Duplicate new type's arguments array --- compiler/src/dmd/mtype.d | 12 ++++++++---- compiler/test/compilable/type_seq_qual.d | 9 ++++----- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/compiler/src/dmd/mtype.d b/compiler/src/dmd/mtype.d index 1aadac7e3924..0e961e9afa87 100644 --- a/compiler/src/dmd/mtype.d +++ b/compiler/src/dmd/mtype.d @@ -4569,9 +4569,11 @@ extern (C++) final class TypeTuple : Type TypeTuple t = cast(TypeTuple) Type.makeConst(); if (arguments) { - foreach (ref arg; *t.arguments) + t.arguments = new Parameters(arguments.length); + foreach (i, ref arg; *t.arguments) { - arg.type = arg.type.addSTC(STC.const_); + auto tsrc = (*arguments)[i].type; + arg = new Parameter(Loc.initial, 0, tsrc.addSTC(STC.const_), null, null, null); } } return t; @@ -4587,9 +4589,11 @@ extern (C++) final class TypeTuple : Type TypeTuple t = cast(TypeTuple) Type.makeImmutable(); if (arguments) { - foreach (ref arg; *t.arguments) + t.arguments = new Parameters(arguments.length); + foreach (i, ref arg; *t.arguments) { - arg.type = arg.type.immutableOf(); + auto tsrc = (*arguments)[i].type; + arg = new Parameter(Loc.initial, 0, tsrc.immutableOf(), null, null, null); } } return t; diff --git a/compiler/test/compilable/type_seq_qual.d b/compiler/test/compilable/type_seq_qual.d index 2664a5ac2999..8e6bfe4487a0 100644 --- a/compiler/test/compilable/type_seq_qual.d +++ b/compiler/test/compilable/type_seq_qual.d @@ -8,10 +8,9 @@ alias TS = AliasSeq!(int, float); static assert(is(typeof(c) == immutable TS)); static assert(is(immutable(TS)[0] == immutable int)); -alias CT = const(TS); static assert(is(const(TS) == const TS)); +static assert(is(const(AliasSeq!(int, float))[0] == const int)); // OK +static assert(is(const(TS)[0] == const int)); // fails -pragma(msg, CT[0]); // const(int) -static assert(is(CT[0] == const int)); // immutable(int) == const(int)!!! -pragma(msg, (const(TS)[0]).stringof); // const(int) -static assert(is(const(TS)[0] == const int)); // immutable(int) == const(int)!!! +alias CT = const(TS); +static assert(is(CT[0] == const int));