Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Open ended array slices are running into a type inference issue #1430

Closed
bettinaheim opened this issue May 5, 2022 · 4 comments · Fixed by #1477
Closed

Open ended array slices are running into a type inference issue #1430

bettinaheim opened this issue May 5, 2022 · 4 comments · Fixed by #1477
Assignees
Labels
area: type system Q# type system and type inference bug Something isn't working

Comments

@bettinaheim
Copy link
Contributor

bettinaheim commented May 5, 2022

The following code results in a compiler exception from this location.

        let arr1 = [1,2,3];
        let arr2 = [6, size = 3];

        let concatenated = arr1 + arr2;
        let slice = concatenated[arr1[0]..arr1[1]...];

A similar issue may exist for other open ended ranges (as part of slicing or as part of copy-and-update).

Edit: Capturing another case that seems to silently fail here since it is also an issue with open ended ranges; this may or may not be the same/a similar issue. This is the case that throws during building the compilation:

    operation LengthCaching (vals : Int[]) : Int[] {
        return vals[...vals[0]...];
    }
@bettinaheim bettinaheim added bug Something isn't working needs triage An initial review by a maintainer is needed area: type system Q# type system and type inference and removed needs triage An initial review by a maintainer is needed labels May 5, 2022
@ScottCarda-MS
Copy link
Contributor

When the Expression Verification determines the type of array item expressions, it seems it always assigns a type parameter as the type. I suppose this might be done because the type of the array items expressions need to be determined later on through context. This type is eventually resolved by using a InferenceContextModule.Resolver under BuildUserDefinedImplementation.

The root of the issue is that this ultimate resolution for the type of array items expressions comes too late if an array item expression is used as a component of a slicing range expression. A slicing range expression is resolved here.

@ScottCarda-MS
Copy link
Contributor

Note that the issue is specific to the step of the slicing range being derived from an array item expression, and only when one or both of the start and end components are missing.

@bamarsha
Copy link
Contributor

I think the open range expansion is purely syntactic, so I'd recommend removing any checks it does on the types of the expressions.

@ScottCarda-MS
Copy link
Contributor

@samarsha, do you know where would be a good place to add some test cases to cover this issue?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: type system Q# type system and type inference bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants