Bug 9807 – with statement does not work with alias this

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-03-24T06:26:00Z
Last change time
2015-06-09T05:15:00Z
Keywords
rejects-valid
Assigned to
nobody
Creator
robert
See also
http://d.puremagic.com/issues/show_bug.cgi?id=9808

Comments

Comment #0 by robert — 2013-03-24T06:26:27Z
The with statement does not appear to take alias this into account: ---- void test(T)(T t) { } struct Foo { string[string] strs; alias strs this; } void main() { Foo f; test(f.keys[0]); // Fine with(f) { test(keys[0]); // Not fine } } ---- test.d(15): Error: undefined identifier keys Using dmd 2.062.
Comment #1 by andrej.mitrovich — 2013-06-09T12:01:53Z
*** This issue has been marked as a duplicate of issue 6711 ***
Comment #2 by yebblies — 2013-11-22T03:32:31Z
This was not a dupe of issue 6711, it asks for properties of built-in types to be accessible via with. eg this doesn't work void main() { int[int] aa; with(aa) { } } Making this work for AAs is questionable, as this doesn't work: void main() { struct S { int[] a; alias a this; } S x; with(x) { length; } }