Skip to content

bad type inference for range expression #3564

@proppy

Description

@proppy

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]);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working or is incorrectdslx:TIv2Bugs related to Type Inference v2

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions