xls icon indicating copy to clipboard operation
xls copied to clipboard

bad type inference for range expression

Open proppy opened this issue 4 weeks ago • 1 comments

Describe the bug

It seems that range expression don't type-coerce into properly annotated typed array but instead redefine the type binding to be the max size of the range.

To Reproduce

#[test]
fn test_array2d_tiv2() {
    let data: u32[8][2] = [0..8, 8..16];
    assert_eq(u32:0 ++ u32:8, data[0][0] ++ data[1][0]);
}
0313: fn test_array2d_tiv2() {
0314: let data: u32[8][2] = [0..8, 8..16];
0315: assert_eq(u32:0 ++ u32:8, data[0][0] ++ data[1][0]);
~~~~~~~~~~~~~~~~~~~^----------------------------------------^ FailureError: The program being interpreted failed!
lhs: u64:8
rhs: u9:8
were not equal
0316: }

Expected behavior

I would expect [0..8, 8..16] to get coerced into u32[8][2].

Note that annotating the range expression will work around this issue

#[test]
fn test_array2d_tiv2() {
    let data: u32[8][2] = [u32:0..u32:8, u32:8..u32:16];
    assert_eq(u32:0 ++ u32:8, data[0][0] ++ data[1][0]);
}

proppy avatar Dec 16 '25 08:12 proppy