D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 9490 - 'this' is not found when expression is in parentheses
Summary: 'this' is not found when expression is in parentheses
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: pull, rejects-valid
: 9815 (view as issue list)
Depends on:
Blocks:
 
Reported: 2013-02-09 10:31 UTC by Andrej Mitrovic
Modified: 2020-07-21 09:45 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Andrej Mitrovic 2013-02-09 10:31:51 UTC
class C
{
    int[] arr;

    this()
    {
        // ok
        assert(arr.length);

        // Error: need 'this' to access member arr
        assert((arr).length);
    }
}

void main()
{
}
Comment 1 yebblies 2013-06-28 20:16:31 UTC
arr goes the IdentifierExp -> DsymbolExp -> DotVarExp path, while (arr) seems to go the TypeExp -> VarExp -> Error path.

Producing DsymbolExp when resolving TypeExp to a variable does the trick, but breaks other code.
Comment 2 basile-z 2019-04-30 07:21:02 UTC
Funnily this works:

---
class C
{
    int[] arr;

    this()
    {
        auto a = ((arr)).length;
    }
}

void main()
{
}
---

The bug is not related to arrays or ctors. Same problem if you try to access the member of a member:

class C
{
    struct Foo { int a; }
    Foo foo;

    void test()
    {
        // Error: need 'this' to access member a
        auto a =  (foo).a;
    }
}

void main()
{
}
Comment 3 basile-z 2019-07-23 01:09:40 UTC
3rd test case from 9185:

---
struct S { int i; }
struct S1 { S s; }
void f(int) { }

void main()
{
    S1 s1;
    f(s1.s.tupleof); // OK
    f((s1.s).tupleof); // Error: need 'this' to access member s
}
---
Comment 4 basile-z 2019-07-23 04:03:41 UTC
*** Issue 9815 has been marked as a duplicate of this issue. ***
Comment 5 Dlang Bot 2019-11-19 12:13:52 UTC
@StianGulpen created dlang/dmd pull request #10592 "fix issue 9490 - 'this' is not found when expression is in parentheses" fixing this issue:

- fix issue 9490 - 'this' is not found when expression is in parentheses

https://github.com/dlang/dmd/pull/10592
Comment 6 Dlang Bot 2019-11-19 13:37:48 UTC
dlang/dmd pull request #10592 "fix issue 9490 - 'this' is not found when expression is in parentheses" was merged into master:

- c5e0bdd66f9833dc85715ffb20396ada69afbf5c by Stian Gulpen:
  fix issue 9490 - 'this' is not found when expression is in parentheses

https://github.com/dlang/dmd/pull/10592
Comment 7 Dlang Bot 2020-07-21 09:45:51 UTC
dlang/dmd pull request #11439 "[dmd-cxx] fix issue 9490 - 'this' is not found when expression is in parentheses" was merged into dmd-cxx:

- 3d5716d46a30122809ae7c2b58f07f6b262afcba by Stian Gulpen:
  fix issue 9490 - 'this' is not found when expression is in parentheses

https://github.com/dlang/dmd/pull/11439