www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 23537] New: immutable struct breaks type inference for const

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

          Issue ID: 23537
           Summary: immutable struct breaks type inference for const
                    parameters
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: andy.pj.hanson gmail.com

The below fails to compile:

```
void main() {
        S s;
        f(s, (S x) {});
}

immutable struct S {}

void f(T)(const T x, scope void delegate(const T) cb) {
        cb(x);
}
```

The error is:
```
a.d(3): Error: none of the overloads of template `a.f` are callable using
argument types `!()(immutable(S), void function(immutable(S) x) pure nothrow
 nogc  safe)`
a.d(8):        Candidate is: `f(T)(const T x, scope void delegate(const(T))
cb)`
```

It works if I specify `f!S`. It also works if I remove `immutable` from the
struct definition and change the call to `f(s, (const S x) {});`.

--
Dec 03 2022