www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22540] New: Instantiation modifies dependant type of value /

https://issues.dlang.org/show_bug.cgi?id=22540

          Issue ID: 22540
           Summary: Instantiation modifies dependant type of value / alias
                    template parameters
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: critical
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: moonlightsentinel disroot.org

Template instantiation can modify the type of value / alias parameters when it
depends on a previous template parameters. This causes invalid errors for
further instantiations.

===========================================================
// Example for value parameters

template Value(T = int, T* ptr = (T*).init)
{
    pragma(msg, T, ": ", typeof(ptr), " => ", ptr);
}


alias v1 = Value!(double); // OK

alias v2 = Value!(int);
// Error: template instance `Value!int` does not match template declaration
`Value(T = int, double* ptr = (T*).init)`
//
// Notice the `double* ptr` instead of `T* ptr`
===========================================================

===========================================================
// Example for alias parameters

template Alias(T = int, alias T* ptr = (T*).init)
{
    pragma(msg, T, ": ", typeof(ptr), " => ", ptr);
}

alias a1 = Alias!(double);
// Error: template instance `Alias!double` does not match template declaration
`Alias(T = int, alias T* ptr = (double*).init)`

alias a2 = Alias!(int);
// Error: template instance `Alias!int` does not match template declaration
`Alias(T = int, alias T* ptr = (double*).init)`
===========================================================

--
Nov 23 2021