Bug 12323 – std.typecons.Nullable of a fixed-size array

Status
RESOLVED
Resolution
INVALID
Severity
enhancement
Priority
P4
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-03-08T14:11:36Z
Last change time
2024-12-01T16:20:22Z
Assigned to
No Owner
Creator
bearophile_hugs
Moved to GitHub: phobos#9627 →

Comments

Comment #0 by bearophile_hugs — 2014-03-08T14:11:36Z
This is an enhancement request, related to Issue 12322 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() {} 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 Is it possible to support code like in the function bar2()?
Comment #1 by nick — 2024-11-12T18:10:53Z
Still happens with dmd v2.109.0.
Comment #2 by nick — 2024-11-12T22:06:42Z
Sorry, the error messages are different now: nullableslice.d(10): Error: constructor `std.typecons.Nullable!(int[5]).Nullable.this(inout(int[5]) value) inout` is not callable using argument types `(int[])` nullableslice.d(10): cannot pass argument `array(iota(5))` of type `int[]` to parameter `inout(int[5]) value` nullableslice.d(13): Error: constructor `std.typecons.Nullable!(int[5]).Nullable.this(inout(int[5]) value) inout` is not callable using argument types `(immutable(int)[])` nullableslice.d(13): cannot pass argument `idup(array(iota(5)))` of type `immutable(int)[]` to parameter `inout(int[5]) value` That is actually correct because the type system can't know at compile-time that `array` or `idup` will each return a slice that has 5 elements.
Comment #3 by robert.schadek — 2024-12-01T16:20:22Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/9627 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB