Bug 9490 – 'this' is not found when expression is in parentheses

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-02-09T10:31:51Z
Last change time
2020-07-21T09:45:51Z
Keywords
pull, rejects-valid
Assigned to
No Owner
Creator
Andrej Mitrovic

Comments

Comment #0 by andrej.mitrovich — 2013-02-09T10:31:51Z
class C { int[] arr; this() { // ok assert(arr.length); // Error: need 'this' to access member arr assert((arr).length); } } void main() { }
Comment #1 by yebblies — 2013-06-28T20:16:31Z
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 by b2.temp — 2019-04-30T07:21:02Z
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 by b2.temp — 2019-07-23T01:09:40Z
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 by b2.temp — 2019-07-23T04:03:41Z
*** Issue 9815 has been marked as a duplicate of this issue. ***
Comment #5 by dlang-bot — 2019-11-19T12:13:52Z
@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 by dlang-bot — 2019-11-19T13:37:48Z
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 by dlang-bot — 2020-07-21T09:45:51Z
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