D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 9807 - with statement does not work with alias this
Summary: with statement does not work with alias this
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2013-03-24 06:26 UTC by Robert Clipsham
Modified: 2015-06-09 05:15 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Robert Clipsham 2013-03-24 06:26:27 UTC
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 Andrej Mitrovic 2013-06-09 12:01:53 UTC

*** This issue has been marked as a duplicate of issue 6711 ***
Comment 2 yebblies 2013-11-22 03:32:31 UTC
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;
    }
}