www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 14721] New: Contracts should not be able to modify function

https://issues.dlang.org/show_bug.cgi?id=14721

          Issue ID: 14721
           Summary: Contracts should not be able to modify function
                    arguments
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: accepts-invalid
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: verylonglogin.reg gmail.com

This code compiles but shouldn't:
---
void f(int[] arr)
in { arr[0] = 5; } // compiles, should be an error
body { }

class C
{
    int i;

    void f()
    in { i = 5; } // compiles, should be an error
    body { }
}
---

Notes:
`invariant` doesn't allow modification of class fields as `this` is `const` and
function result passed to `out` contract is `const` too. For `in`/`out`
contracts only direct assignment to parameter is rejected (Issue 9413 & Issue
9414).

--
Jun 23 2015