digitalmars.D.bugs - Invariant/initialization bug?
- David Medlock (22/22) Feb 18 2005 Consider the following code:
- =?ISO-8859-1?Q?Thomas_K=FChne?= (45/45) Feb 19 2005 -----BEGIN PGP SIGNED MESSAGE-----
Consider the following code: class Test { int[] array; uint count = 0; uint capacity() { return array.length; } invariant { assert( count <= capacity ); } this() {} } void main( char[][] arg ) { Test test = new Test(); } This produces a stack overflow.... If I change the 'capacity' in the invariant to array.length it does not crash. I am guessing the problem is that the invariant call capacity() also calls the invariant upon entry. Is this improper behavior re: contracts in D or simply unspecified? In DBC as I understand it, no contracts can fire while another contract is being checked. Apparently this rule is not enforced in D? -David
Feb 18 2005
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 David Medlock wrote: | Consider the following code: | | class Test | { | int[] array; | uint count = 0; | | uint capacity() { return array.length; } | | invariant { assert( count <= capacity ); } | | this() {} | } | | void main( char[][] arg ) | { | Test test = new Test(); | } | | This produces a stack overflow.... | | If I change the 'capacity' in the invariant to array.length it does | not crash. | | I am guessing the problem is that the invariant call capacity() also | calls the invariant upon entry. | | Is this improper behavior re: contracts in D or simply unspecified? http://digitalmars.com/d/class.html#invariants | In DBC as I understand it, no contracts can fire while another contract | is being checked. Apparently this rule is not enforced in D? Known compiler bug: http://dstress.kuehne.cn/nocompile/invariant_17.d Thomas -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (MingW32) iD8DBQFCFx2/3w+/yD4P9tIRAjh+AJ9IT9IW3VKUq2lUA/K3VWMW5qniKwCggxih eiPO1945ylXL5DYLV4FuzuU= =tnie -----END PGP SIGNATURE-----
Feb 19 2005