ballerina-platform / ballerina-lang

The Ballerina Programming Language
https://ballerina.io/
Apache License 2.0
3.55k stars 735 forks source link

[Task]: Fix fixed length array size overflowing #42684

Closed lochana-chathura closed 1 month ago

lochana-chathura commented 1 month ago

Description

$subject. The following tests fail at the moment. It is included in the fixed-length-array-large-t.bal added by PR #42663.

public const int MAX_VALUE = 9223372036854775807;

public const int MAX_VALUE_M_1 = MAX_VALUE - 1;

// @type LargeArray < IntArray
type LargeArray int[MAX_VALUE];

// @type LargeArray <> LargeArray2
type LargeArray2 int[MAX_VALUE_M_1];
heshanpadmasiri commented 1 month ago

We already support array lengths that are constants

This is caused by an integer overflow here. But in general I think this indicate fixed length must be a long not an int to have the same behavior as nBallerina. Will send a fix

heshanpadmasiri commented 1 month ago

After an offline chat we decided not support this and instead give a proper error for such overflow. This is because our lists are internally backed by java arrays and their indices have an upper limit enforced by int not long. Note this is consistent with the existing behavior of jBallerina

lochana-chathura commented 1 month ago

Closing with #42701