D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 12402 - Improved typing for array concatenation
Summary: Improved typing for array concatenation
Status: RESOLVED DUPLICATE of issue 1654
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-03-18 05:14 UTC by bearophile_hugs
Modified: 2021-04-02 00:26 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2014-03-18 05:14:14 UTC
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 Mathias LANG 2021-04-02 00:26:16 UTC
Issue 1654 covers this in great details, so marking as duplicate.

*** This issue has been marked as a duplicate of issue 1654 ***