Skip to content

peer type resolution not coercing properly #12608

Description

@nektro

Zig Version

0.10.0-dev.3672+cd5a9ba1f

Steps to Reproduce

const std = @import("std");

test {
    var a: u32 = 45;
    _ = &a;
    var b: u8 = 4;
    _ = &b;

    var runtime = true;
    _ = &runtime;
    var other = false;
    _ = &other;

    const x = if (runtime) blk: {
        break :blk a;
    } else if (other) blk: {
        break :blk b;
    } else null;

    try std.testing.expectEqual(?u32, @TypeOf(x));
    // try std.testing.expect(x == 45); // see #12609
}

Expected Behavior

All 1 tests passed.

Actual Behavior

test.zig:14:15: error: expected type '?u32', found '?u8'
    const x = if (runtime) blk: {
              ^~
test.zig:14:15: note: optional type child 'u8' cannot cast into optional type child 'u32'

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    proposalThis issue suggests language modifications. If it also has the "accepted" label then it is planned.

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions