[Issue 17871] New: Delegate type inference doesn't work

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Oct 1 22:34:09 UTC 2017


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 at puremagic.com
          Reporter: mathias.lang at 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.

--


More information about the Digitalmars-d-bugs mailing list