Bug 21572 – Implicit conversion from `immutable(T)[][]` to `scope const(T)[][]` is missing
Status
RESOLVED
Resolution
INVALID
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-01-22T11:22:27Z
Last change time
2021-01-22T14:17:42Z
Assigned to
No Owner
Creator
Per Nordlöw
Comments
Comment #0 by per.nordlow — 2021-01-22T11:22:27Z
In
@safe:
void f(scope const(char)[]) {}
void g(scope const(char)[][]) {}
unittest
{
string x;
f(x);
string[] y;
g(y);
}
g() should be allowed. Instead it currently fails
function `foo.g(scope const(char)[][] _param_0)` is not callable using argument types `(string[])` (d-dmd)
cannot pass argument `y` of type `string[]` to parameter `scope const(char)[][] _param_0` (d-dmd)
Perhaps conversion should be allowed in `g()` without `scope` qualifier as long as `f()` allows it.
Comment #1 by ag0aep6g — 2021-01-22T14:17:42Z
Conversion from `immutable(char)[][]` to `const(char)[][]` is not sound. Consider:
immutable(char)[][] i = [""];
const(char)[][] c = i;
char[] m = ['x'];
c[0] = m;
`i[0][0]` would have the same address as `m[0]`. You'd have a `char` that is both immutable and mutable.
`scope` is irrelevant, as far as I see.
Closing as invalid. Please reopen if I'm missing something. In particular, if you think `scope` is relevant, please describe how it makes the conversion valid.