Bug 23537 – immutable struct breaks type inference for const parameters

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2022-12-03T17:49:04Z
Last change time
2024-12-13T19:26:14Z
Assigned to
No Owner
Creator
andy-hanson
Moved to GitHub: dmd#20200 →

Comments

Comment #0 by andy-hanson — 2022-12-03T17:49:04Z
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) {});`.
Comment #1 by robert.schadek — 2024-12-13T19:26:14Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20200 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB