D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 1659 - template alias parameters are chosen over all but exact matches.
Summary: template alias parameters are chosen over all but exact matches.
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords: pull, wrong-code
: 3137 4431 (view as issue list)
Depends on:
Blocks: 3109
  Show dependency treegraph
 
Reported: 2007-11-10 13:27 UTC by Robert DaSilva
Modified: 2016-03-18 12:24 UTC (History)
5 users (show)

See Also:


Attachments
an example (591 bytes, text/plain)
2007-11-10 13:28 UTC, Robert DaSilva
Details

Note You need to log in before you can comment on or make changes to this issue.
Description Robert DaSilva 2007-11-10 13:27:34 UTC
For example say I have a class foo and a class diverged from foo called bar, and I have a template specialization for foo and a template by the same name that takes an alias. I instantiate that template with bar and get the alias version. The spec say that the most specialized version is chosen, but isn't an alias template the least specialized type of template, even more so than a unspecialized template that takes a generic type?
Comment 1 Robert DaSilva 2007-11-10 13:28:50 UTC
Created attachment 208 [details]
an example
Comment 2 Gide Nwawudu 2009-04-03 16:04:30 UTC
Including original attachment in this comments. Issue looks similar to BUG 918.

import std.stdio;

typedef char ctd;
class Foo { }
class Bar : Foo { }

void main()
{
    Baz!(char)(); /* regular template version used only because
                   * template alias parameters reject basic types. */
    Baz!(ctd)(); // alias version used
    Baz!(Foo)(); // Foo version used
    Baz!(Bar)(); // alias version used
}

void Baz(T)()
{
    writefln("regular template version called with ", T.stringof);
}

void Baz(T : Foo)()
{
    writefln("foo specialization called with ", T.stringof);
}

void Baz(alias T)()
{
    writefln("alias version called with ", T.stringof);
}
Comment 3 Witold Baryluk 2010-01-24 21:09:54 UTC
This problem is still present in DMD 2.039.
It looks that from unknown reasons bug918 is solved (nobody comented what was source of regression and dissapiring of it). Probably it is different aspect here of template matching.
Comment 4 Vladimir Panteleev 2014-02-03 14:32:36 UTC
Still happens with 2.064. The typedef part is no longer relevant as the language feature is going away, but the class hierarchy part remains.

Shorter test case:

class Foo { }
class Bar : Foo { }

void f(T : Foo)() { }
void f(alias T)() { assert(false); }

void main()
{
    f!Bar();
}
Comment 5 Vladimir Panteleev 2014-02-03 14:34:49 UTC
*** Issue 3137 has been marked as a duplicate of this issue. ***
Comment 8 Kenji Hara 2016-03-18 12:24:56 UTC
*** Issue 4431 has been marked as a duplicate of this issue. ***