Skip to content

comptime-known undefined values can coerce to any type, even when not of type @Type(.Undefined) #13958

@mlugg

Description

@mlugg

Zig Version

0.11.0-dev.811+8ff9284c4

Steps to Reproduce and Observed Behavior

pub fn main() void {
    const x: []u8 = undefined;
    const y: f32 = x;
    _ = y;
}

The compilation completes successfully. Adding @compileLog(@TypeOf(x)) (and the same for y) shows that the types are as expected (nothing has become @Type(.Undefined)):

[mlugg@vega test]$ zig run test.zig
test.zig:3:5: error: found compile log statement
    @compileLog(@TypeOf(x));
    ^~~~~~~~~~~~~~~~~~~~~~~

Compile Log Output:
@as(type, []u8)
@as(type, f32)

Expected Behavior

The compilation should fail with this error:

test.zig:3:20: error: expected type 'f32', found '[]u8'
    const y: f32 = x;

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions