[Issue 24565] New: out contract variable is implicitly const
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri May 24 19:41:23 UTC 2024
https://issues.dlang.org/show_bug.cgi?id=24565
Issue ID: 24565
Summary: out contract variable is implicitly const
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: minor
Priority: P1
Component: dlang.org
Assignee: nobody at puremagic.com
Reporter: nick at geany.org
The spec does not mention this:
https://dlang.org/spec/function.html#postconditions
struct R
{
bool empty(); // only logically const, not D const
}
R f() // returns a mutable R
out(r; r.empty) // Error: mutable method `R.empty` is not callable using a
`const` object
{
R r; // not const
return r;
}
For the above case, an `out` contract cannot be used. Note that inserting
`assert(r.empty);` before the return statement does work.
--
More information about the Digitalmars-d-bugs
mailing list