www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17871] New: Delegate type inference doesn't work

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

          Issue ID: 17871
           Summary: Delegate type inference doesn't work
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: mathias.lang sociomantic.com

I'm surprised that I couldn't find an issue about it, but this is probably a
duplicate. In any case, the following code:

```
struct Symbol
{
    public int opApply (scope int delegate (size_t, string) dg)
    {
        return 0;
    }

    public int opApply (scope int delegate (string) dg)
    {
        scope wrapper = (size_t, string v) { return dg(v); };
        return this.opApply(wrapper);
    }
}
```

Will trigger the following error:
```
bug.d(10): Error: variable bug.Symbol.opApply.wrapper type void is inferred
from initializer (size_t, string v)
{
return dg(v);
}
, and variables cannot be of type void
bug.d(10): Error: template lambda has no value
```

Using `auto` will provide the same result, same for the new delegate syntax.
It looks quite weird that the frontend is not able to infer this type.

--
Oct 01