www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10326] New: Disallow 'invariant' for immutable, allow class/struct invariants without (), and later disallow usage of ()

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10326

           Summary: Disallow 'invariant' for immutable, allow class/struct
                    invariants without (), and later disallow usage of ()
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc



struct Foo {
    int x = 0;
    invariant() {
        assert(x != 0);
    }
    void bar() {}
}
void main() {
    Foo f;
    f.bar;
    invariant int y; // deprecation warning
}



With dmd 2.064alpha this code gives the deprecation warning:
temp.d(11): Deprecation: use of 'invariant' rather than 'immutable' is
deprecated

And then correctly asserts at run-time:
core.exception.AssertError temp(4): Assertion failure

- - - - - - - - - - - - - - - - - - -

The first step (I suggest in dmd 2.064) is to disallow 'invariant' as a
replacement for the 'immutable' turning the deprecation into an error, and at
the same time allow the definition of class/struct invariants without the ( ),
and and at the same time a give a deprecation message where a ( ) is used (the
alternative is to give just a warning, but this change has a low probability of
introducing bugs in D code, so a deprecation is enough):


struct Foo {
    int x = 0;
    invariant() { // deprecation warning here, no () needed.
        assert(x != 0);
    }
    invariant { // OK
        assert(x != 0);
    }
    void bar() {}
}
void main() {
    Foo f;
    f.bar;
    invariant int y; // error
}

- - - - - - - - - - - - - - - - - - -

In a successive compiler release the usage of ( ) at the struct/class invariant
becomes an error to tidy up the language:

struct Foo {
    int x = 0;
    invariant() { // error
        assert(x != 0);
    }
    invariant { // OK
        assert(x != 0);
    }
    void bar() {}
}
void main() {
    Foo f;
    f.bar;
    invariant int y; // error
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 10 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10326


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull



For changing current deprecation messages to errors:
https://github.com/D-Programming-Language/dmd/pull/2160

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 11 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10326




Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/5479162eed97bd7107485437f15d426658e25a76
fix Issue 10326 - Change old `invariant` usage to error

deprecation -> error

https://github.com/D-Programming-Language/dmd/commit/a9fa72432981719fa88a042d3f4649fca7ddf0fe


Issue 10326 - Change old `invariant` usage to error

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 15 2013