Skip to content

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

@sengir

Description

@sengir

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorfrontendTokenization, parsing, AstGen, Sema, and Liveness.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions