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
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.
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.