Bug 23314 – Language spec falsely states that struct field invariants are checked

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dlang.org
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-08-29T16:50:31Z
Last change time
2022-09-05T03:14:20Z
Keywords
pull
Assigned to
No Owner
Creator
Paul Backus

Comments

Comment #0 by snarwin+bugzilla — 2022-08-29T16:50:31Z
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
Comment #1 by dlang-bot — 2022-09-05T02:39:28Z
@pbackus created dlang/dlang.org pull request #3405 "Fix issue 23314 - Language spec falsely states that struct field inva…" fixing this issue: - Fix issue 23314 - Language spec falsely states that struct field invariants are checked This behavior has never been implemented, and users should not rely on it in their code. https://github.com/dlang/dlang.org/pull/3405
Comment #2 by dlang-bot — 2022-09-05T03:14:20Z
dlang/dlang.org pull request #3405 "Fix issue 23314 - Language spec falsely states that struct field inva…" was merged into master: - 7239b35eca2809b779a41b9d25f9bd98aa5705ba by Paul Backus: Fix issue 23314 - Language spec falsely states that struct field invariants are checked This behavior has never been implemented, and users should not rely on it in their code. https://github.com/dlang/dlang.org/pull/3405