www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Nullable, inout, and more

reply "bearophile" <bearophileHUGS lycos.com> writes:
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
Mar 08 2014
parent reply "Kagamin" <spam here.lot> writes:
It probably expects int[5] instead of int[], couldn't convert and 
reported wrong error message.
Mar 08 2014
parent "bearophile" <bearophileHUGS lycos.com> writes:
Kagamin:

 It probably expects int[5] instead of int[], couldn't convert 
 and reported wrong error message.
OK, I will report the diagnostic bug. But do you also see space for a (distinct) ER? Bye, bearophile
Mar 08 2014