www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17635] New: [REG 2.066.0] cannot convert unique


          Issue ID: 17635
           Summary: [REG 2.066.0] cannot convert unique immutable(int)**
                    to immutable
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Keywords: rejects-valid
          Severity: regression
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: ag0aep6g gmail.com

Lifted the forum:
http://forum.dlang.org/post/ok04kr$28dl$1 digitalmars.com

This code should be accepted:

alias T = immutable int;

T** f(const T** input) pure
    T** output;
    return output;

void main()
    T i;
    T* p = &i;
    immutable T** r = f(&p);
        /* Error: cannot implicitly convert expression f(& p) of type
        immutable(int)** to immutable(int**) */

I can't say that I'm 100% sure about this. Maybe there's a good reason why the
code must be rejected. But I don't see it. And if I read the spec right, it
says that the code should compile.

Per the spec [1], `f` is a "pure factory function". That means the compiler
"may assume that all mutable memory returned by the call [...] is newly
allocated by the function". As far as I understand, the spec also calls this

The spec also says [2]: "An expression may be converted from mutable [...] to
immutable if the expression is unique and all expressions it transitively
refers to are either unique or immutable."

Since all parts of `f`'s return value are either unique or immutable, it should
be convertible to immutable.

The code compiles with 2.065.0. Fails since 2.066.0.

[1] https://dlang.org/spec/function.html#pure-functions
[2] https://dlang.org/spec/const3.html#implicit_qualifier_conversions

Jul 11