www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22270] New: [DIP1000] class does infer scope in methods when

https://issues.dlang.org/show_bug.cgi?id=22270

          Issue ID: 22270
           Summary: [DIP1000] class does infer scope in methods when
                    assigned to a scope variable
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: jlourenco5691 gmail.com

The struct can infer scope, but the class cannot. There are ways to get around
this, but the behavior should be consistent.

---
struct Bar
{
         safe void dummy() {}
}

class Foo
{
     safe void dummy() {}
}

 safe
void main()
{
    scope bar = new Bar;
    bar.dummy; // ok

    scope foo = new Foo;
    foo.dummy(); // fails
}
---

To work around this issue, the class function must be annotated with scope, or
be a template.

--
Sep 03 2021