Was this supposed to be allowed?
Petar
Petar
Wed Sep 15 15:11:57 UTC 2021
On Wednesday, 15 September 2021 at 13:52:40 UTC, z wrote:
> ```D
> float[2] somevalue = somefloat3value[] + cast(Unqual!float[2])
> [somesharedfloatarray1[i],somesharedfloatarray2[ii]];
> ```
> Older LDC/DMD releases never complained but now that i upgraded
> DMD, DMD-compiled builds suffer from runtime assert error
> `core.internal.array.operations.arrayOp!(float[], float[],
> float[], "+", "=").arrayOp at
> .....\src\druntime\import\core\internal\array\operations.d(45)
> : Mismatched array lengths for vector operation `
>
> Explicitly specifying `somefloat3value[0..2]` now works, and it
> seems that this assert check is an addition to a recent DMD
> version's `druntime`, does it means that this was a recent
> change in the language+runtime or just a retroactive
> enforcement of language rules that didn't use to be enforced?
> Big thanks.
The history is roughly as follows:
* between dmd 2.065 and 2.076 (including), this used to fail at
runtime with message "Array lengths don't match for vector
operation: 2 != 3"
* dmd 2.077 included [druntime PR 1891][1] which was a ground-up
re-implementation of the way array operations are implemented and
in general a very welcome improvement. Unfortunately that PR
didn't include checks to ensure that all arrays have equal length
(or perhaps it had insufficient checks, I didn't dig into the
details).
* 2020-08-04 The issue was reported:
https://issues.dlang.org/show_bug.cgi?id=21110
* 2021-08-09 A PR that fixes the issue was merged:
https://github.com/dlang/druntime/pull/3267
* 2021-08-09 The fix was released in 2.097.2
In summary, the validation was always supposed to be there, but
between 2.077.0 and 2.097.1 it wasn't.
[1]: https://github.com/dlang/druntime/pull/1891
More information about the Digitalmars-d-learn
mailing list