| |
| Posted by Nick Treleaven in reply to matheus | PermalinkReply |
|
Nick Treleaven
Posted in reply to matheus
| On Saturday, 15 October 2022 at 10:31:16 UTC, matheus wrote:
> On Friday, 14 October 2022 at 20:19:20 UTC, Ali Çehreli wrote:
> ...
The compiler does not perform detailed analysis of all code. Since that 5 could be a runtime expression, the compiler does not check it at compile time.
...
Yes but in this case it's known during the compiling time (Literal 5), couldn't this be checked and prevented?
It would be better to error on assigning a new array expression to a static array, there's no reason to allow that. A static array can be assigned a single element arr = 0 instead. Although ideally there would be some syntactical way of making it clear when assigning a slice to a static array, perhaps requiring [] at the end unless it is already a SliceExpression or an array literal. Then the syntax would tell you if the right hand side had a compile-time known length not (and hence you can rely on a compile-time error if lengths don't match).
|