Bug 20546 – Сast nested array from static to dynamic.

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2020-01-30T18:49:23Z
Last change time
2020-01-30T19:34:12Z
Assigned to
No Owner
Creator
andrei007

Attachments

IDFilenameSummaryContent-TypeSize
1774errorarray.dСast nested array from static to dynamic.text/plain535

Comments

Comment #0 by andrei007 — 2020-01-30T18:49:23Z
Created attachment 1774 Сast nested array from static to dynamic. Version: v2.090.0
Comment #1 by moonlightsentinel — 2020-01-30T19:34:12Z
The cast from int[2][2] to int[][] is invalid - you cannot slice across multiple dimensions. import std.stdio; void main(string[] args) { int[2][2] e = [[1,2],[3,4]]; int[][] c = cast(int[][]) e; writeln(c.length); // 1 writeln(c[0].length); // 8589934593 int[2][] valid = e; // no cast needed writeln(valid); // [[1, 2], [3, 4]] } The length of a static array is only known at compile time while the length of a dynamic array is a runtime value. Hence c's length is set to some garbage from the stack.