Closed alaviss closed 2 years ago
The issue is that it fails with {.requiresInit.}
.
While the destructors spec allows =destroy
to be called on zero-initialized values, the requiresInit
spec forces a strict requirement on a value to be initialized at construction. By this reasoning, it means that a value is not considered valid until it has been constructed and that no hooks can be executed before that.
In Nim, "construction" is the first value to be written into the variable (of which =sink
is skipped), and the compiler already has the analysis needed for this (as required for implementation of requiresInit
). This appears to me to be a case of the analysis not accounting for this specific case (it happened before in #16607).
You are right, since compiler knows r
refer to an uninitialized O
, it should consider r[] = initO()
is for initialize it.
There is no bug here, the spec does not mention special cases for requiresInit
.
An another case of #16607
Example
Current Output
Expected Output
no output
Additional Information
nim-sys
.