Bug 13364 – Template instance isInstanceOf itself

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2014-08-22T22:11:44Z
Last change time
2020-03-21T03:56:33Z
Assigned to
No Owner
Creator
Ali Cehreli

Comments

Comment #0 by acehreli — 2014-08-22T22:11:44Z
The following code passes both checks with dmd v2.067-devel-c6cf84f. I would expect the second one to fail: import std.traits; struct Foo(T) {} void main() { static assert(isInstanceOf!(Foo, Foo!int)); // OK static assert(isInstanceOf!(Foo!int, Foo!int)); // ? } After debugging this issue I think that this is actually a dmd bug because variadic template argument deduction seems to be making an error. Here is the implementation of isInstanceOf: enum bool isInstanceOf(alias S, T) = is(T == S!Args, Args...); When both S and T are Foo!int, then (T == S!Args, Args...) should fail. (Actually, it could succeed only if Args... were resolved to be empty, which is not the case.) The following code demonstrates that Args is non-empty when the S and T template arguments are both Foo!int. struct Foo(T) {} bool dumpInformation(alias S, T, Args)() { import std.string; pragma(msg, S); // prints: Foo!int pragma(msg, T); // prints: Foo!int pragma(msg, Args); // prints: int return true; } // Copy of std.traits.isInstanceOf with the addition of dumpInformation() enum bool myIsInstanceOf(alias S, T) = is(T == S!Args, Args...) && dumpInformation!(S, T, Args)(); void main() { static assert(myIsInstanceOf!(Foo!int, Foo!int)); } Ali
Comment #1 by b2.temp — 2015-12-07T01:46:11Z
It fails now