Bug 13016 – Weird error message when trying to construct Nullable!int from a size_t
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-07-02T05:36:00Z
Last change time
2015-04-25T22:37:39Z
Assigned to
nobody
Creator
monkeyworks12
Comments
Comment #0 by monkeyworks12 — 2014-07-02T05:36:55Z
import std.typecons: Nullable;
Nullable!int IndexOf(int[] arr, int val)
{
foreach (i, n; arr)
{
if (n == val)
{
//Error: inout method
//std.typecons.Nullable!int.Nullable.this
//is not callable using a mutable object
return Nullable!int(i);
}
}
return Nullable!int();
}
Comment #1 by bearophile_hugs — 2014-07-02T09:08:59Z
Note that array indexes are size_t, that are implicitly convertible to int only on 32 bit systems. This program compiles and works on 32 bits. And on 64 bit systems it can't work, you have to write "foreach (int i, n; arr)" or to use a cast.
Comment #2 by monkeyworks12 — 2015-04-25T22:34:53Z
Yeah, but the error message is really confusing.
Comment #3 by monkeyworks12 — 2015-04-25T22:37:39Z
*** This issue has been marked as a duplicate of issue 12322 ***