Thread overview
[Issue 4325] New: invariant syntax isn't strict
Aug 30, 2010
Andrej Mitrovic
Jun 15, 2011
yebblies
Jun 15, 2011
yebblies
June 16, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4325

           Summary: invariant syntax isn't strict
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: accepts-invalid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: bearophile_hugs@eml.cc


--- Comment #0 from bearophile_hugs@eml.cc 2010-06-15 18:11:01 PDT ---
Class/struct invariants are:
http://www.digitalmars.com/d/2.0/class.html#Invariant
    invariant() BlockStatement


But dmd v2.047 compiles this with no errors:


struct Foo {
    invariant {}
}
struct Bar {
    invariant
}
class CFoo {
    invariant {}
}
class CBar {
    invariant
}
void main() {}


See also the second part of the bug 3856

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 30, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4325


Andrej Mitrovic <andrej.mitrovich@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich@gmail.com


--- Comment #1 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2010-08-29 20:01:39 PDT ---
The compiler will still print an error if you add any statements below a class invariant, e.g.:

struct Foo {
    invariant {}
}
struct Bar {
    int x = 5;
    invariant
        assert(x == 1);
}
class CFoo {
    invariant {}
}
class CBar {
    invariant
}
void main()
{
    Bar bar;
}

bug4325.d(7): Declaration expected, not 'assert'


So it might not be that bad. The same thing happens if you put "const" "pure" "immutable" without any opening braces or colons, e.g.:

struct Foo {
    pure
}
struct Bar {
    const
}
class CFoo {
    immutable
}
class CBar {
    invariant
}
void main()
{
}

Compiles fine.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 15, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=4325


yebblies <yebblies@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |yebblies@gmail.com
         Resolution|                            |INVALID


--- Comment #2 from yebblies <yebblies@gmail.com> 2011-06-15 08:30:26 PDT ---
This has nothing to do with class invariants.  This is caused by invariant currently being an alias for immutable.  Change invariant to immutable in the examples and it will make sense.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 15, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=4325



--- Comment #3 from bearophile_hugs@eml.cc 2011-06-15 09:51:04 PDT ---
(In reply to comment #2)
> This has nothing to do with class invariants.  This is caused by invariant currently being an alias for immutable.  Change invariant to immutable in the examples and it will make sense.

I see, thank you. Do you want me to open a new enhancement request where I ask for the removal of this alias, or do you prefer me to reopen and rename this bug report?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 15, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=4325



--- Comment #4 from yebblies <yebblies@gmail.com> 2011-06-15 11:36:37 PDT ---
> I see, thank you. Do you want me to open a new enhancement request where I ask for the removal of this alias, or do you prefer me to reopen and rename this bug report?

A new report.  Changing the focus of old reports makes it more difficult to process them. (for me at least)

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