[Issue 3856] const arguments/instance attributes in conditions/invariants

2022-12-17 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=3856

Iain Buclaw  changed:

   What|Removed |Added

   Priority|P2  |P3

--


[Issue 3856] const arguments/instance attributes in conditions/invariants

2010-10-02 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=3856



--- Comment #3 from bearophile_h...@eml.cc 2010-10-02 04:30:04 PDT ---
See also bug 4974

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


[Issue 3856] const arguments/instance attributes in conditions/invariants

2010-08-30 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=3856


Andrej Mitrovic  changed:

   What|Removed |Added

 CC||andrej.mitrov...@gmail.com


--- Comment #2 from Andrej Mitrovic  2010-08-30 
06:10:35 PDT ---
(In reply to comment #0)
> Currently preconditions and postconditions (D contract based programming) can
> modify input arguments, this prints [0, 2]:
> 
> import std.stdio: writeln;
> 
> void foo(int[] arr)
> out { arr[0] = 0; }
> body {}
> 
> void main() {
> auto a = [1, 2];
> foo(a);
> writeln(a);
> }
> 
> But I think it's better if arguments are seen as const inside preconditions 
> and
> postconditions. Because modifying them alters too much the program behaviour
> between release and not release builds.
> 

Yes. As stated in TDPL, changing the state of the application inside an in/out
contract is *illegal*. An application must run with the same behavior and
results whether or not it executes it's contracts (debug vs release mode).

I'm not sure about invariants. Although it would be best if they didn't modify
the state of 'this', they are still allowed to call private methods and in turn
those methods might change the state of the application.

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


[Issue 3856] const arguments/instance attributes in conditions/invariants

2010-03-01 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=3856



--- Comment #1 from bearophile_h...@eml.cc 2010-03-01 09:09:00 PST ---
In practice pre/post conditions and invariants can even become pure. This
limits some of their usages (logging, printing), but not much.

Generally reading and modifying a global variable inside a condition/invariant
doesn't look like tidy code.

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