www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 18910] New: Non-compile-time-constant parameter default

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

          Issue ID: 18910
           Summary: Non-compile-time-constant parameter default values not
                    respected when passed as alias to a template function
                    (with some indirection)
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: dhasenan gmail.com

Test case:

---
import std.stdio;
int protoss(alias func)()
{
    return func(4);
}
int zerg(immutable int q)
{
    int getSecondArgument(int a, int b)
    {
        writefln("getSecondArgument of %s %s", a, b);
        return b;
    }
    return protoss!((int a, int b = q) => getSecondArgument(a, b))();
}
void main(string[] args)
{
    zerg(10).writeln;
}
---

Expected output:
getSecondArgument of 4 10
10

Actual output:
getSecondArgument of 4 0
0

Simplified cases of this do result in an error message, so it's probably just a
case of extending the current error check, or reordering an optimization or
something.

--
May 26 2018