View mode: basic / threaded / horizontal-split · Log in · Help
August 08, 2011
[Issue 6453] New: Allow multiple invariant per struct/class
http://d.puremagic.com/issues/show_bug.cgi?id=6453

          Summary: Allow multiple invariant per struct/class
          Product: D
          Version: D2
         Platform: Other
       OS/Version: Windows
           Status: NEW
         Severity: normal
         Priority: P2
        Component: DMD
       AssignedTo: nobody@puremagic.com
       ReportedBy: simendsjo@gmail.com


--- Comment #0 from simendsjo <simendsjo@gmail.com> 2011-08-08 03:19:03 PDT ---
I would like to use a template mixin to add some fields to a struct, but I'd
also like the template to add additional invariant checks without having to
remember to add this for all struct/classes that mixes in this code.

class C {
   int a;
}

mixin template EmbedC() {
   C _c;

   // oops.. more than one invariant
   invariant() {
       assert(_c);
   }

   void close() {
       _c = null;
   }
}

struct S {
   int i = 10;
   invariant() {
       assert(i >= 10);
   }

   mixin EmbedC!();
}

void main() {
   S s;
   s.close();
   s._c.a = 10; // access violation, but I want assertion from invariant
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 29, 2012
[Issue 6453] Allow multiple invariant per struct/class
http://d.puremagic.com/issues/show_bug.cgi?id=6453


yebblies <yebblies@gmail.com> changed:

          What    |Removed                     |Added
----------------------------------------------------------------------------
          Keywords|                            |ddoc
                CC|                            |yebblies@gmail.com
          Platform|Other                       |All
        AssignedTo|nobody@puremagic.com        |yebblies@gmail.com
        OS/Version|Windows                     |All
          Severity|normal                      |enhancement


--- Comment #1 from yebblies <yebblies@gmail.com> 2012-01-29 15:41:25 EST ---
The spec explicitly states that there can only be one invariant, so this is an
enhancement.

On the other hand, this appears to be an arbitrary restriction.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 29, 2012
[Issue 6453] Allow multiple invariant per struct/class
http://d.puremagic.com/issues/show_bug.cgi?id=6453


yebblies <yebblies@gmail.com> changed:

          What    |Removed                     |Added
----------------------------------------------------------------------------
          Keywords|                            |patch


--- Comment #2 from yebblies <yebblies@gmail.com> 2012-01-29 17:25:04 EST ---
https://github.com/D-Programming-Language/dmd/pull/653

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 23, 2012
[Issue 6453] Allow multiple invariant per struct/class
http://d.puremagic.com/issues/show_bug.cgi?id=6453


Alex Rønne Petersen <xtzgzorex@gmail.com> changed:

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


--- Comment #3 from Alex Rønne Petersen <xtzgzorex@gmail.com> 2012-02-23 12:59:01 PST ---
I completely agree with this change; I ran into this exact limitation for the
exact same scenario as well. It's rather crippling for template mixins.

While on this topic, see also bug #5038. It would be a natural extension of
this enhancement IMHO.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 16, 2013
[Issue 6453] Allow multiple invariant per struct/class
http://d.puremagic.com/issues/show_bug.cgi?id=6453


yebblies <yebblies@gmail.com> changed:

          What    |Removed                     |Added
----------------------------------------------------------------------------
                CC|                            |ah08010-d@yahoo.com


--- Comment #4 from yebblies <yebblies@gmail.com> 2013-01-17 01:28:15 EST ---
*** Issue 5038 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 13, 2013
[Issue 6453] Allow multiple invariant per struct/class
http://d.puremagic.com/issues/show_bug.cgi?id=6453



--- Comment #5 from github-bugzilla@puremagic.com 2013-05-12 19:17:40 PDT ---
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/ae70bfdeafd3a534e3f12747503bafa046be2f9d
fix Issue 6453 - Allow multiple invariant per struct/class

https://github.com/D-Programming-Language/dmd/commit/081c92a115b3006871c5a516267417e06ceacbcf
Merge pull request #1978 from 9rnsr/multi_inv

Issue 6453 - Allow multiple invariant per struct/class

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 13, 2013
[Issue 6453] Allow multiple invariant per struct/class
http://d.puremagic.com/issues/show_bug.cgi?id=6453



--- Comment #6 from github-bugzilla@puremagic.com 2013-05-12 21:34:21 PDT ---
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/ce58435fe322afd736504f804bdad6a9debb8c1d
Fix up for issue 6453 change, allow shared/synchronized invariants

But mixing non-shared/shared/synchronized is currently rejected.

https://github.com/D-Programming-Language/dmd/commit/4fbc77fa504c2d8ee4c7ef10edc70221a74742c3
Merge pull request #2028 from 9rnsr/multi_inv

Fix up for issue 6453 change, allow shared/synchronized invariants

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 13, 2013
[Issue 6453] Allow multiple invariant per struct/class
http://d.puremagic.com/issues/show_bug.cgi?id=6453


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

          What    |Removed                     |Added
----------------------------------------------------------------------------
            Status|NEW                         |RESOLVED
        Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Top | Discussion index | About this forum | D home