Skip to content

stage2: Sema cannot distinguish vectors from arrays in expressions #11251

New issue

Have a question about this project? No Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “No Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? No Sign in to your account

Closed
Tracked by #89
sengir opened this issue Mar 21, 2022 · 1 comment · Fixed by #11749
Closed
Tracked by #89

stage2: Sema cannot distinguish vectors from arrays in expressions #11251

sengir opened this issue Mar 21, 2022 · 1 comment · Fixed by #11749
Labels
bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Milestone

Comments

@sengir
Copy link
Contributor

sengir commented Mar 21, 2022

Zig Version

0.10.0-dev.1463+5d943f621

Steps to Reproduce

An explicitly typed array initializer within an expression:

_ = -@Vector(4, i32){ 1, 2, 3, 4 };

Note that this still occurs with aliased types:

const i32x4 = std.meta.Vector(4, i32);
_ = i32x4{ 1, 2, 3, 4 } + i32x4{ 1, 2, 3, 4 };

Expected Behavior

Sema to receive type information to identify this array_init as a vector_type so the negation operator can be performed (as arrays cannot be negated, but vectors can).

Actual Behavior

Sema receives an array_init ZIR instruction pointing to each member of the initializer, but the instruction does not point to the explicitly provided vector_type, making Sema unable to determine if this list is allowed to negated. Instead, Sema will always infer that array_init returns an array, which cannot be negated.

The current workaround is to move these initializers into intermediate variables to force them to get coerced into vectors before being used.

@sengir sengir added the bug Observed behavior contradicts documented or intended behavior label Mar 21, 2022
@Vexu Vexu added the frontend Tokenization, parsing, AstGen, Sema, and Liveness. label Mar 21, 2022
@Vexu Vexu added this to the 0.10.0 milestone Mar 21, 2022
@topolarity
Copy link
Contributor

Note to future implementer: I believe #11182 is related - tuples run into the same problem

No Sign up for free to join this conversation on GitHub. Already have an account? No Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants