www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12166] New: Template Argument Pattern Matching Fails for Struct With Multiple Nested Template Arguments

reply d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12166

           Summary: Template Argument Pattern Matching Fails for Struct
                    With Multiple Nested Template Arguments
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: monkeyworks12 hotmail.com


--- Comment #0 from monkeyworks12 hotmail.com 2014-02-14 21:15:01 PST ---
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);
}

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 14 2014
next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12166



--- Comment #1 from Kenji Hara <k.hara.pg gmail.com> 2014-02-19 22:26:36 PST ---
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

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 19 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12166



--- Comment #2 from monkeyworks12 hotmail.com 2014-02-19 23:18:39 PST ---
(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; -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 19 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12166



--- Comment #3 from Kenji Hara <k.hara.pg gmail.com> 2014-02-19 23:32:31 PST ---
(In reply to comment #2)
 Sorry, add:

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. -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 19 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12166



--- Comment #4 from monkeyworks12 hotmail.com 2014-02-20 04:31:48 PST ---
(In reply to comment #3)
 (In reply to comment #2)
 Sorry, add:

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? -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 20 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12166



--- Comment #5 from Kenji Hara <k.hara.pg gmail.com> 2014-02-20 20:55:38 PST ---
(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. -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 20 2014
prev sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12166


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID


-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 20 2014