D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 13016 - Weird error message when trying to construct Nullable!int from a size_t
Summary: Weird error message when trying to construct Nullable!int from a size_t
Status: RESOLVED DUPLICATE of issue 12322
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-07-02 05:36 UTC by Meta
Modified: 2015-04-25 22:37 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Meta 2014-07-02 05:36:55 UTC
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 bearophile_hugs 2014-07-02 09:08:59 UTC
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 Meta 2015-04-25 22:34:53 UTC
Yeah, but the error message is really confusing.
Comment 3 Meta 2015-04-25 22:37:39 UTC

*** This issue has been marked as a duplicate of issue 12322 ***