[Issue 15859] opApply resolution on attributes
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Sat Apr 2 00:37:57 PDT 2016
https://issues.dlang.org/show_bug.cgi?id=15859
--- Comment #1 from qs.il.paperinik at gmail.com ---
(In reply to qs.il.paperinik from comment #0)
> struct X
> {
> int opApply(int delegate(string) dg)
> {
> return dg("impure");
> }
>
> int opApply(int delegate(string) pure dg) pure
> {
> return dg("pure");
> }
> }
>
> void main()
> {
> X x;
> string result;
>
> [ ... ]
>
> /+ (1)
> foreach (string s; x)
> {
> result = s;
> }
> writeln(result); // x.opApply matches more than one declaration
> +/
> /+ (2)
> foreach (string s; x)
> {
> result = s;
> write("");
> }
> writeln(result); // x.opApply matches more than one declaration
> +/
> }
For (1) this is true to some extent. The constructed delegate is pure, but can
be matched to the non-pure version of opApply.
For (2) the compiler rejects valid because the delegate is impure and can only
match the impure opApply.
--
More information about the Digitalmars-d-bugs
mailing list