Bug 12402 – Improved typing for array concatenation

Status
RESOLVED
Resolution
DUPLICATE
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-03-18T05:14:14Z
Last change time
2021-04-02T00:26:16Z
Assigned to
No Owner
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2014-03-18T05:14:14Z
int[5] foo(int[2] a, int[3] b) { typeof(return) result = a ~ b; // OK return result; } int[5] bar(int[2] a, int[3] b) { return a ~ b; // Error } void main() {} DMD 2.066alpha gives: test2.d(6,12): Error: cannot implicitly convert expression (cast(int[])a ~ cast(int[])b) of type int[] to int[5] I suggest to support the code in bar() too. (A small optimization can even remove any heap allocations from the bar() function). I am not sure, but perhaps the solution is similar to a value range propagation: to propagate the statically known length of an array. (Expecially for immutable arrays, as in Issue 10594 ).
Comment #1 by pro.mathias.lang — 2021-04-02T00:26:16Z
Issue 1654 covers this in great details, so marking as duplicate. *** This issue has been marked as a duplicate of issue 1654 ***