Windows DMD 2.032
Evaluating $ in a delegate literal in an array indexing or slicing
throws access violation Error.
----
void main() {
int[] a = [1];
auto x = a[{ auto n = $; return 0; }()];
// object.Error: Access Violation
auto y = a[{ auto n = $; return 0; }() .. $];
// object.Error: Access Violation
}
Comment #1 by clugdbug — 2010-07-23T00:05:49Z
This worked in 2.000 and all versions of D1, Failed with access violation in 2.012. Bumping up to regression.
Comment #2 by clugdbug — 2010-08-06T00:11:01Z
This isn't a regression, it never worked properly (on D1, it doesn't segfault, but the generated code is wrong).
It's happening because __dollar isn't a real variable in the parent scope. I think to fix this properly, either the implementation of __dollar would need to change, OR the delegate literal would need to be inlined; but this case is so obscure, it doesn't matter much.
To turn this from wrong-code into a rather obscure rejects-valid:
declaration.c, VarDeclaration::checkNestedReference(), line 1441 (D2 svn 599):
fdv->closureVars.push(this);
L2: ;
+ // __dollar creates problems because it isn't a real variable
+ if (ident == Id::dollar)
+ ::error(loc, "cannnot use $ inside a function literal (Bugzilla 3326)");