www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22693] New: Lambda accepts auto parameter but fails on

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

          Issue ID: 22693
           Summary: Lambda accepts auto parameter but fails on
                    instantiation
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: contact lsferreira.net

The compiler accepts the following:

```
alias func = (auto c) {};
```

But when instantiation `func` with some value it fails:

```
func(4);
```

Producing the following error:
```
onlineapp.d(4): Error: `auto` can only be used as part of `auto ref` for
template function parameters
onlineapp.d(5): Error: template `D main.__lambda1` cannot deduce function from
argument types `!()(int)`
onlineapp.d(4):        Candidate is: `__lambda1`
```

We should either fail when declaring lambdas with auto or add support for it.
If we want to add support for this, templates should also cover it, to make it
consistent with all the language semantics.

--
Jan 20 2022