August 29, 2022 [Issue 23314] New: Language spec falsely states that struct field invariants are checked | ||||
|---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=23314 Issue ID: 23314 Summary: Language spec falsely states that struct field invariants are checked Product: D Version: D2 Hardware: All OS: All Status: NEW Severity: normal Priority: P1 Component: dlang.org Assignee: nobody@puremagic.com Reporter: snarwin+bugzilla@gmail.com The language spec's section on struct invariants [1] states the following: > Any invariants for fields are applied before the struct invariant. However, this has apparently never been true. According to run.dlang.io, all compiler versions since DMD 2.066.1 compile the following program such that it runs to completion successfully, which is only possible if S's invariant is never checked: --- struct S { invariant { assert(0); } } struct T { S s; invariant { assert(1); } void fun() {} } void main() { T t; t.fun(); } --- Earlier versions of DMD are unable to parse the invariant contract, which suggests this behavior has never worked as described in the spec. See also issue 19537 for a similar error in the spec for class invariants. [1] https://dlang.org/spec/struct.html#Invariant -- | ||||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply