Skip to content

value with comptime-only type '@TypeOf(null)' depends on runtime control flow #16770

Closed

Description

@ehaas

Zig Version

0.12.0-dev.47+0461a64a9

Steps to Reproduce and Observed Behavior

fn foo(x: bool) error{OutOfMemory}![]const u8 {
    if (x) return "" else return error.OutOfMemory;
}

test {
    var x = true;
    const val = foo(x) catch |err| switch (err) {
        error.OutOfMemory => null,
    };
    _ = val;
}
~ % zig test test.zig
test.zig:7:36: error: value with comptime-only type '@TypeOf(null)' depends on runtime control flow
    const val = foo(x) catch |err| switch (err) {
                                   ^~~~~~
test.zig:7:24: note: runtime control flow here
    const val = foo(x) catch |err| switch (err) {
                ~~~~~~~^~~~~

Giving val an explicit type of ?[]const u8 prevents the error

Expected Behavior

Test passes

Activity

  1. added
    bug
    on Aug 11, 2023
  2. mlugg commented on Aug 11, 2023

    @mlugg
    Member

    Will be solved by the implementation of #11957

  3. added
    enhancement
    frontend
    and removed
    bug
    on Aug 11, 2023
  4. added this to the 0.13.0 milestone on Aug 11, 2023
  5. andrewrk commented on Jan 9, 2024

    @andrewrk
    Member

    fixed by acca16c

  6. modified the milestones: 0.13.0, 0.12.0 on Jan 9, 2024
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

    enhancementfrontend

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions