class C { int[] arr; this() { // ok assert(arr.length); // Error: need 'this' to access member arr assert((arr).length); } } void main() { }
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.
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() { }
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 } ---
*** Issue 9815 has been marked as a duplicate of this issue. ***
@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
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
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