D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 21572 - Implicit conversion from `immutable(T)[][]` to `scope const(T)[][]` is missing
Summary: Implicit conversion from `immutable(T)[][]` to `scope const(T)[][]` is missing
Status: RESOLVED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 major
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-01-22 11:22 UTC by Per Nordlöw
Modified: 2021-01-22 14:17 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Per Nordlöw 2021-01-22 11:22:27 UTC
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 ag0aep6g 2021-01-22 14:17:42 UTC
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.