Issue 23985 - [dip1000] return scope fails to infer after assignment
Summary: [dip1000] return scope fails to infer after assignment
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-06-10 17:11 UTC by Dennis
Modified: 2023-06-11 20:28 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 Dennis 2023-06-10 17:11:22 UTC
From the newsgroup: https://forum.dlang.org/post/ooxbnqweqyohygrvspga@forum.dlang.org

```D
// REQUIRED_ARGS: -preview=dip1000
@safe:

struct B()
{
    int* a;
    C!() c;
}

class C()
{
    C!() foo(int* a)
    {
        return foo2(a);
    }

    C!() foo2(int* a)
    {
        auto b = B!()(a);
     	return b.c;
    }
}

void main()
{
    scope int* a;
    C!() c;
    // Error: scope variable `a` assigned to non-scope parameter `a` calling `foo`
    c.foo(a);
}
a);
}
```
Comment 1 timon.gehr 2023-06-11 18:28:35 UTC
Do we really want `scope` inference on virtual methods? The code type checks without deprecation if you mark both methods as `final`.
Comment 2 timon.gehr 2023-06-11 18:45:41 UTC
If inferring `return scope` on `a` was not the intention, can you maybe clarify how a fix for this issue would work?
Comment 3 Dennis 2023-06-11 20:28:14 UTC
(In reply to timon.gehr from comment #1)
> Do we really want `scope` inference on virtual methods?

Good point, I missed that the method is virtual. I think this would be invalid then. (Though of course the enhancement for separate lifetimes for separate aggregate fields still stands)