www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21287] New: Delegate in global template can't call

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

          Issue ID: 21287
           Summary: Delegate in global template can't call non-anonymous
                    nested function passed as alias
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: snarwin+bugzilla gmail.com

---
struct A {}

alias canMatch(alias handler) = (A arg) => handler(arg);

struct StructuralSumType
{
        void opDispatch()
        {
                void fun(Value)(Value _) {}
                alias lambda = (_) {};

                alias ok = canMatch!lambda;
                alias err = canMatch!fun;
        }
}
---

Compiler output as of DMD 2.093.1:

---
sumtype.d(3): Error: delegate sumtype.canMatch(alias handler) cannot access
frame of function sumtype.StructuralSumType.opDispatch
sumtype.d(13): Error: template instance `sumtype.canMatch!(fun)` error
instantiating
---

Possibly a duplicate of issue 15298, though the error messages are different.

--
Sep 30 2020