https://issues.dlang.org/show_bug.cgi?id=13228
Steven Schveighoffer <[email protected]> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |[email protected] --- Comment #3 from Steven Schveighoffer <[email protected]> --- (In reply to bearophile_hugs from comment #0) > I suggest to introduce in D a value range analysis and propagation for the > length of slices, it should allow code like (currently refused): > > > void foo(int[100]) {} > ubyte x = 100; > void main() { > const int[] a = new int[x]; > foo(a); > } > > > That currently gives: > > test.d(5,8): Error: function test.foo (int[100] _param_0) is not callable > using argument types (const(int[])) static this() { x = 99; } oops... > > > That is comparable to code like this (that is accepted by dmd 2.066beta5): > > void foo(ubyte) {} > ubyte x = 100; > void main() { > const int a = x; > foo(a); > } This is not the same, because a's value isn't known at compile time, just its range. This ER is asking for flow analysis, which I think is not on the table. Be mindful of what the compiler can know at compile time. Value range analysis for expressions dies at the end of an expression. --
