D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 22910 - [dip1000] return scope struct member functions allow returning `this` by ref
Summary: [dip1000] return scope struct member functions allow returning `this` by ref
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords: pull, safe
Depends on:
Blocks:
 
Reported: 2022-03-22 15:13 UTC by Dennis
Modified: 2022-03-23 12:17 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Dennis 2022-03-22 15:13:33 UTC
This should give an error since the function is `return scope`, while it should be `return ref` for returning a reference to `this`:
```
struct S
{
    int  val;
    int* ptr;

    int* retScope() return scope
    {
        return &this.val;
    }
}
```
Comment 1 Dlang Bot 2022-03-22 16:35:52 UTC
@dkorpel created dlang/dmd pull request #13860 "Fix issue 22910 - `return scope` struct member functions allow returning `this` by ref" fixing this issue:

- Fix issue 22910 - `return scope` struct member functions allow returning `this` by ref

https://github.com/dlang/dmd/pull/13860
Comment 2 Dlang Bot 2022-03-23 12:17:33 UTC
dlang/dmd pull request #13860 "Fix issue 22910 - `return scope` struct member functions allow returning `this` by ref" was merged into master:

- 31f410b04fde66afadebf6ae2da289b37ef626d7 by Dennis Korpel:
  Fix issue 22910 - `return scope` struct member functions allow returning `this` by ref

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