D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 19963 - [Regression 2.066 - 2.067.1] nested pure functions variable access
Summary: [Regression 2.066 - 2.067.1] nested pure functions variable access
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 regression
Assignee: No Owner
URL:
Keywords:
: 19964 (view as issue list)
Depends on:
Blocks:
 
Reported: 2019-06-14 10:46 UTC by Nicholas Wilson
Modified: 2024-12-13 19:03 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 Nicholas Wilson 2019-06-14 10:46:17 UTC
From the source code of DMD no less!

void f() {
  int fx;
  pure void g() {
    int gx;
    /+pure+/ void h() {
      int hx;
      /+pure+/ void i() { fx = 0; }
    }
   }
}

should give 

Error: pure nested function 'g' cannot access mutable data 'fx'
if the commented out `purees are removed it should give 

Error: pure nested function 'i' cannot access mutable data 'fx'

three times.
Comment 1 Nicholas Wilson 2019-06-14 11:28:43 UTC
*** Issue 19964 has been marked as a duplicate of this issue. ***
Comment 2 Walter Bright 2019-12-18 10:44:28 UTC
I'm not sure what the problem is?
Comment 3 RazvanN 2020-02-13 11:01:26 UTC
The problem is that function g is pure, but it contains function i that accesses the variable fx which is outside of its scope, thus violating purity. This code should issue an error, but it doesn't.
Comment 4 dlangBugzillaToGithub 2024-12-13 19:03:58 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/19584

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB