Bug 12166 – Template Argument Pattern Matching Fails for Struct With Multiple Nested Template Arguments
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-02-14T21:15:00Z
Last change time
2014-02-20T20:57:15Z
Assigned to
nobody
Creator
monkeyworks12
Comments
Comment #0 by monkeyworks12 — 2014-02-14T21:15:01Z
struct Zero {}
struct Succ(a) {}
struct Nil {}
struct Cons(a, b) {}
alias list1 = Cons!(Three, Cons!(Two, Cons!(Four, Cons!(One, Nil))));
alias numlHead(L: Cons!(a, b), a, b) = a;
alias numlTail(L: Cons!(a, b), a, b) = b;
void main()
{
//Error: template instance numlHead!(list1) does not
//match template declaration numlHead(L : Cons!(a, b), a, b)
pragma(msg, numlHead!list1);
}
Comment #1 by k.hara.pg — 2014-02-19T22:26:36Z
The test case lacks some symbols:
test.d(7): Error: undefined identifier Three
test.d(7): Error: undefined identifier Two
test.d(7): Error: undefined identifier Four
test.d(7): Error: undefined identifier One
Comment #2 by monkeyworks12 — 2014-02-19T23:18:39Z
(In reply to comment #1)
> The test case lacks some symbols:
>
> test.d(7): Error: undefined identifier Three
> test.d(7): Error: undefined identifier Two
> test.d(7): Error: undefined identifier Four
> test.d(7): Error: undefined identifier One
Sorry, add:
alias One = Succ!Zero;
alias Two = Succ!One;
alias Three = Succ!Two;
alias Four = Succ!Three;
Comment #3 by k.hara.pg — 2014-02-19T23:32:31Z
(In reply to comment #2)
> Sorry, add:
[snip]
So, what version do you use? The full test case:
struct Zero {}
struct Succ(a) {}
alias One = Succ!Zero;
alias Two = Succ!One;
alias Three = Succ!Two;
alias Four = Succ!Three;
struct Nil {}
struct Cons(a, b) {}
alias list1 = Cons!(Three, Cons!(Two, Cons!(Four, Cons!(One, Nil))));
alias numlHead(L: Cons!(a, b), a, b) = a;
alias numlTail(L: Cons!(a, b), a, b) = b;
void main()
{
pragma(msg, numlHead!list1);
}
compiles with 2.064 (2.063 and earlier does not support new alias syntax). I cannot see the issue.
Comment #4 by monkeyworks12 — 2014-02-20T04:31:48Z
(In reply to comment #3)
> (In reply to comment #2)
> > Sorry, add:
> [snip]
>
> So, what version do you use? The full test case:
>
> struct Zero {}
> struct Succ(a) {}
>
> alias One = Succ!Zero;
> alias Two = Succ!One;
> alias Three = Succ!Two;
> alias Four = Succ!Three;
>
> struct Nil {}
> struct Cons(a, b) {}
>
> alias list1 = Cons!(Three, Cons!(Two, Cons!(Four, Cons!(One, Nil))));
>
> alias numlHead(L: Cons!(a, b), a, b) = a;
>
> alias numlTail(L: Cons!(a, b), a, b) = b;
>
> void main()
> {
> pragma(msg, numlHead!list1);
> }
>
> compiles with 2.064 (2.063 and earlier does not support new alias syntax). I
> cannot see the issue.
It seems it was an error on my part. In the full code, I had some testing code in my main method. I accidentally named a variable list1 as well as having the list1 alias, so my code broke with this:
void main()
{
//assert(is(Four == Succ!(Succ!(Succ!(Succ!Zero)))));
auto list1 = list1(); //Problem
//assert(is(typeof(three) == Three));
//assert(numValue!(Number!Zero) == 0);
assert(numValue!(Number!Four) == 4);
pragma(msg, numlHead!list1);
//assert(is(numlHead!list1 == Three));
//assert(is(typeof(numlTail!list1) == Cons!(Two, Cons!Four, Cons!(One, Nil))));
}
However, it also seems this is bad behaviour. Should I open a separate report?
Comment #5 by k.hara.pg — 2014-02-20T20:55:38Z
(In reply to comment #4)
> However, it also seems this is bad behaviour.
Shadowing *module level* symbols by declared local symbols is legitimate. Currently there's no plan to disallow it, and I also think it should be continuously allowed.
> Should I open a separate report?
However of course, it's your free.