Bug 23554 – Can break immutable with delegate

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2022-12-14T04:48:01Z
Last change time
2024-12-13T19:26:23Z
Assigned to
No Owner
Creator
andy-hanson
Moved to GitHub: dmd#20205 →

Comments

Comment #0 by andy-hanson — 2022-12-14T04:48:01Z
This code is able to mutate an `immutable int[][]`: ``` @safe: import std.stdio : writeln; void main() { immutable int[][] xs = [[1]]; writeln("xs[0][0] is ", xs[0][0]); // 1 f(xs); writeln("xs[0][0] is ", xs[0][0]); // 2 } void f(immutable int[][] xs) { each(xs, (ref immutable(int)[] x) { x = [2]; }); } void each(immutable int[][] xs, void delegate(ref immutable int[]) @safe pure nothrow cb) { foreach (ref x; xs) cb(x); } ``` The provided delegate `ref immutable(int)[] x` should not be allowed, since it should take a `ref immutable int[]` instead.
Comment #1 by robert.schadek — 2024-12-13T19:26:23Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20205 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB