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

--- Comment #2 from Eyal <e...@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.

--

Reply via email to