Bug 20863 – Passing aggregate types into templates by alias drops qualifier

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-05-25T18:30:05Z
Last change time
2024-12-13T19:08:50Z
Keywords
pull
Assigned to
No Owner
Creator
Andrei Alexandrescu
Blocks
13343
See also
https://issues.dlang.org/show_bug.cgi?id=11577
Moved to GitHub: dmd#17959 →

Comments

Comment #0 by andrei — 2020-05-25T18:30:05Z
Took me a while to make this 100% self-contained. Both asserts should pass. The second fails. alias AliasSeq(Seq...) = Seq; template staticIndexOf(alias T, TList...) { static if (TList.length == 0) { enum int staticIndexOf = -1; } else static if (is(T == TList[0])) { enum int staticIndexOf = 0; } else { private enum int t = staticIndexOf!(T, TList[1 .. $]); enum int staticIndexOf = t < 0 ? t : t + 1; } } struct Foo {} static assert(staticIndexOf!(Foo, AliasSeq!(Foo)) == 0); // pass static assert(staticIndexOf!(immutable(Foo), AliasSeq!(immutable(Foo))) == 0); // fail
Comment #1 by moonlightsentinel — 2020-05-25T20:06:33Z
Even smaller: template staticFind(alias T, TList) { enum bool staticFind = is(T == TList); // true; } static assert(staticFind!(Object, Object)); // pass static assert(staticFind!(immutable Object, immutable Object)); // fail
Comment #2 by destructionator — 2020-05-25T23:07:21Z
I'm actually not sure if this is a bug or not. But I didn't even know literal values were allowed to be passed to aliases, so I'm apparently behind the times! But the spec isn't clear on if it takes built-in types at all, and is also underspecified on if it actually accepts a type or a symbol. My thought is if it takes a symbol, the immutable qualifier might get legitimately dropped because that's part of the local type instead of the global symbol. Of course it is more useful to just define it to take the whole type and be the same thing! But we should clarify the spec as well as the implementation to make it clear this is what is supposed to happen.
Comment #3 by maxsamukha — 2020-05-26T06:35:51Z
This is the same as or related to bug 2704.
Comment #4 by maxsamukha — 2020-05-26T07:05:06Z
(In reply to Max Samukha from comment #3) > This is the same as or related to bug 2704. Link: https://issues.dlang.org/show_bug.cgi?id=2704
Comment #5 by uplink.coder — 2020-05-26T07:45:33Z
The issue is not quite correct struct Foo {} template P(alias X) { pragma(msg, X); enum P = 1; } int y = P!(const int); int x = P!(immutable(double)); int z = P!(immutable(Foo)); int z2 = P!(immutable Foo); The output of this is const(int) immutable(double) Foo What happens is that the types which are not symbols are merely "losslessly cast" to a symbol. Therefore the STC is not dropped
Comment #6 by uplink.coder — 2020-05-26T07:51:18Z
struct Foo {} template P(alias X) { pragma(msg, X); enum P = 1; } int y = P!(const int); int x = P!(immutable(double)); int z = P!(immutable(Foo)); int z2 = P!(immutable Foo); The output of this is const(int) immutable(double) Foo What happens is that the types which are not symbols are merely "losslessly cast" to a symbol. Therefore the STC is not dropped. That means the new addition of types matching to alias behaves inconsistently. Not the other way around.
Comment #7 by boris2.9 — 2020-05-30T13:33:30Z
The issue 13343 is also related.
Comment #8 by nick — 2020-06-04T16:03:49Z
This bug is blocking the removal of template overloads in std.meta: https://github.com/dlang/phobos/pull/7513
Comment #9 by boris2.9 — 2020-06-06T17:50:14Z
*** Issue 20899 has been marked as a duplicate of this issue. ***
Comment #10 by dlang-bot — 2020-06-24T11:53:08Z
@ntrel created dlang/dmd pull request #11320 "Fix Issue 20863 - Passing aggregate types by alias parameter drops qualifier" fixing this issue: - Fix Issue 20863 - Passing aggregate types by alias param drops qualifier https://github.com/dlang/dmd/pull/11320
Comment #11 by dlang-bot — 2020-07-08T09:03:18Z
dlang/phobos pull request #7542 "std.meta: Fix wrong assert for Issue #20863" was merged into master: - af629b153b1eb93f201c6ef48dc5006b0e32882e by Nick Treleaven: std.meta: Comment out (fix) wrong assert for Issue #20863 Necessary for https://github.com/dlang/dmd/pull/11320 https://github.com/dlang/phobos/pull/7542
Comment #12 by robert.schadek — 2024-12-13T19:08:50Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17959 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB