[Issue 23537] New: immutable struct breaks type inference for const parameters
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Dec 3 17:49:04 UTC 2022
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 at puremagic.com
Reporter: andy.pj.hanson at 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) {});`.
--
More information about the Digitalmars-d-bugs
mailing list