Bug 18295 – [Scope][dip1000] `scope class` check too conservative under -dip1000
Status
RESOLVED
Resolution
WONTFIX
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-01-24T20:50:42Z
Last change time
2021-06-10T18:50:53Z
Keywords
pull, rejects-valid, safe
Assigned to
No Owner
Creator
Mike Franklin
Comments
Comment #0 by slavo5150 — 2018-01-24T20:50:42Z
In practice, the following two examples are no different:
Example 1: Compile with -dip1000
--------------------------------
scope class C { int i; } // Notice the use of `scope` here
C increment(C c) // Error: functions cannot return scope C
{
c.i++;
return c;
}
void main()
{
scope C c = new C();
c.increment();
}
Example 2: Compile with -dip1000
--------------------------------
class C { int i; } // Notice the absence of `scope` here
C increment(C c) // OK: no error
{
c.i++;
return c;
}
void main()
{
scope C c = new C();
c.increment();
}
So, I argue that with the introduction of the -dip1000 compiler switch it is no longer necessary conservatively check the function declaration for `scope class`es. Rather a `scope class` should simply require variable instantiations to be attributed with `scope`, and let -dip1000 do the rest.