D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 8064 - return reference semantics not obeyed on delegates?
Summary: return reference semantics not obeyed on delegates?
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
Depends on:
Blocks: 8065
  Show dependency treegraph
 
Reported: 2012-05-08 03:12 UTC by Gašper Ažman
Modified: 2012-05-10 22:39 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Gašper Ažman 2012-05-08 03:12:02 UTC
I feel this is best explained with a testcase:
This is the error DMD gives:
test.d(21): Error: arryacc(3LU) is not an lvalue
code: #####

class A {
   private size_t size = 5;
   auto newArrayAccessor(T)() {
      T[] a = new T[size];
      ref T accessor(size_t i) {
          return a[i];
      }
      return &accessor;
   }
}

void main() {
   uint[5] arry;
   ref uint acc(size_t i) {
       return arry[i];
   }
   acc(3) = 5; // works

   auto a = new A;
   auto arryacc = a.newArrayAccessor!(uint)();
   arryacc(3) = 5; // doesn't work. What gives?
}
Comment 1 Gašper Ažman 2012-05-08 03:27:13 UTC
Simplified testcase (by q66):
void main() {
   uint[5] arry;
   ref uint acc(size_t i) {
       return arry[i];
   }
   auto arryacc = &acc;
   arryacc(3) = 5; // same error
}
Comment 3 github-bugzilla 2012-05-10 20:00:23 UTC
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/5a9b927ae2501aac795c03d1cd6be79188e1e197
fix Issue 8064 - return reference semantics not obeyed on delegates?

https://github.com/D-Programming-Language/dmd/commit/813a0216b2a205fb06bd8d02d7c667317c7b5ce4
Merge pull request #933 from 9rnsr/fix8064

Issue 8064 - return reference semantics not obeyed on delegates?