[Issue 14721] New: Contracts should not be able to modify function arguments

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Tue Jun 23 01:46:04 PDT 2015


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 at puremagic.com
          Reporter: verylonglogin.reg at 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).

--


More information about the Digitalmars-d-bugs mailing list