D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 13271 - opDispatch fails without warning message if @property
Summary: opDispatch fails without warning message if @property
Status: RESOLVED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 minor
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-08-09 05:31 UTC by Vlad Levenfeld
Modified: 2014-08-09 15:23 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Vlad Levenfeld 2014-08-09 05:31:26 UTC
struct Vector (uint length, Element = double)
{
		ref @property component (string c)()
		{
			enum mat = q{xyzw};
			enum col = q{rgba};
			enum tex = q{uv};

			static if (mat.canFind (c))
				return components[mat.countUntil (c)];
			else static if (col.canFind (c))
				return components[col.countUntil (c)];
			else static if (tex.canFind (c))
				return components[tex.countUntil (c)];
			else static assert (0);
		}

		ref @property opDispatch (string c)()
		if (c.length == 1)
		{
			auto v = component!c;
			pragma(msg, typeof(v)); // this outputs the expected result
			return v; // so everything is fine, right? wrong...
		}

	Element[length] components;
}

If @property opDispatch is replaced with auto opDispatch then it works. opDispatch should either work for properties or should give a more meaningful error message than "Error: No property `x` for Vector" etc.
Comment 1 Vlad Levenfeld 2014-08-09 15:23:43 UTC
ref @property does not imply auto ref @property.

My mistake.