[Issue 17138] Warn about superfluous "with" statements

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Fri May 12 08:24:58 PDT 2017


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

--- Comment #2 from Eyal <eyal at weka.io> ---
struct Object {
   auto acquired() {
     struct Acquired {
         Object obj;
         this(Object* obj) { this.obj = obj; obj.acquire(); }
         ~this() { obj.release(); }
     }
     return Acquired(&this);
   }
   ...
}

Resource someObject;
with(someObject.acquired()) { // <-- makes sense
  ..
}

Resource someObject;
with(someObject) { // Oops! Accidental senseless 'with' statement
  ..
}

The latter can be detected as senseless, since it doesn't affect the code in
any way.

If dropping the with() statement (and keeping its body instead) would result in
the exact same semantics -- warn about superfluous 'with' statement.

--


More information about the Digitalmars-d-bugs mailing list