Thread overview
[Issue 7369] New: Inout constructor causes compiler to reject invariant
Jan 26, 2012
Stewart Gordon
Jan 28, 2012
yebblies
Jan 28, 2012
Stewart Gordon
Jan 28, 2012
yebblies
Jan 29, 2012
Walter Bright
January 26, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7369

           Summary: Inout constructor causes compiler to reject invariant
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: smjg@iname.com


--- Comment #0 from Stewart Gordon <smjg@iname.com> 2012-01-25 18:29:24 PST ---
struct TestStruct {
    invariant() {}
    this(int data) inout {}
}
----------
bad_invariant.d(2): Error: function bad_invariant.TestStruct.__invariant () is
not callable using argument types ()
----------
(DMD 2.057 Win32)

Removing the constructor removes the error.  Changing the struct to a class makes no difference.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 28, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7369


yebblies <yebblies@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yebblies@gmail.com


--- Comment #1 from yebblies <yebblies@gmail.com> 2012-01-28 15:10:45 EST ---
Well, what should happen?  You can't call a non-const invariant from a const function (or immutable or inout).  The same issue exists with shared constructors.

If anyone has a solution, we can use it to solve issue 519 as well.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 28, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7369



--- Comment #2 from Stewart Gordon <smjg@iname.com> 2012-01-28 01:08:56 PST ---
invariant() const {}
doesn't compile.  Though I've just found that
    const invariant() {}
does.

But why aren't invariants automatically const?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 28, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7369



--- Comment #3 from yebblies <yebblies@gmail.com> 2012-01-28 21:16:20 EST ---
(In reply to comment #2)
> invariant() const {}
> doesn't compile.  Though I've just found that
>     const invariant() {}
> does.
> 

That's looks like another bug.  Would you like to file it?

> But why aren't invariants automatically const?

Probably the same reason in and out contracts aren't const... but at least there's a trivial workaround.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 29, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7369



--- Comment #4 from github-bugzilla@puremagic.com 2012-01-29 14:16:12 PST ---
Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/3c138718365541cde67abbdcfc031d755c3a7969 fix Issue 7369 - Inout constructor causes compiler to reject invariant

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 29, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7369


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla@digitalmars.com
         Resolution|                            |FIXED


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