[Issue 18757] static invariant{} should either work or not be valid syntax

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Apr 16 18:32:11 UTC 2018


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

Walter Bright <bugzilla at digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla at digitalmars.com
           Hardware|x86_64                      |All
                 OS|Linux                       |All

--- Comment #7 from Walter Bright <bugzilla at digitalmars.com> ---
A `static invariant` does not have special semantics distinct from `invariant`
other than it does not have a `this` parameter. That fully explains the
observed behavior. The `static` is not ignored:

  struct S {
    int i;
    static invariant { assert (i == 3); } // Error: need this for i of type int
    void foo() {}
  }

  void main() {
    S s;
    s.foo(); // invariant does get called
  }

Whether that is desirable behavior or not is another matter entirely. Our
general practice when confronted with these sorts of issues is to make it an
error until we figure out what is the best approach, if there even is one,
rather than inventing arbitrary behavior without much of any supporting
rationale or use cases.

--


More information about the Digitalmars-d-bugs mailing list