[Issue 5558] New: opIn_r not detected as method for 'in' in pointed struct
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Feb 10 09:50:11 PST 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5558
Summary: opIn_r not detected as method for 'in' in pointed
struct
Product: D
Version: D2
Platform: x86
OS/Version: Linux
Status: NEW
Severity: normal
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: denis.spir at gmail.com
--- Comment #0 from Denis Derman <denis.spir at gmail.com> 2011-02-10 09:47:43 PST ---
In a struct, opIn_r is not detected by the compiler as beeing the method
implementing the operator 'in'. Example:
struct S {
int i;
void show() { writeln(i); }
const bool opEquals (ref const(S) s) {
writeln("==");
return (i == s.i);
}
bool opIn_r (int j) { return (i==j); }
}
unittest {
S* sp = &(S(1));
writeln(sp.i);
sp.show();
S s2 = S(1);
writeln(sp == s2);
writeln(1 in s2);
// error:
writeln(1 in sp);
}
==>
Error: rvalue of in expression must be an associative array, not S*
This concerns opIn_r on pointed struct only; the other struct members of the
structn and the not-pointed one are only here to contrast:
* Data members, regular methods and even "language methods" like opEquals are
correctly taken into account on a struct, even via implicite deref.
* opIn_r is correctly detected as implementing 'in' on a non-pointed or
explicitely dereferenced struct.
Thus, the code works fine if one comments out the very last line.
Waiting for a fix, the error message should be corrected to eg:
Error: right operand of 'in' operation must be an associative array
or implement the operator 'in' via method opIn_r
Denis
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list