A small test program. This could be a base for a bug report/enhancement request, but I am not yet sure:

import std.range: iota;
import std.array: array;
import std.typecons: Nullable;
alias Foo = int[5];
Nullable!Foo bar1() {
    Foo r = 5.iota.array;
    return typeof(return)(r); // OK
}
Nullable!Foo bar2() {
    return typeof(return)(5.iota.array); // Error
}
Nullable!Foo bar3() {
    return typeof(return)(5.iota.array.idup); // Error
}
void main() {}


With dmd 2.066alpha gives:

test.d(10,26): Error: inout method std.typecons.Nullable!(int[5]).Nullable.this is not callable using a mutable object test.d(13,26): Error: inout method std.typecons.Nullable!(int[5]).Nullable.this is not callable using a mutable object

Are the error messages acceptable? In bar3 I have used an idup so the array is not mutable.

And is it possible to modify Phobos/D to accept bar2 function?

Bye,
bearophile

Reply via email to