Skip to content

Type coercion doesn't work inside a tuple when catching an error. #11552

Closed
@IntegratedQuantum

Description

@IntegratedQuantum

Zig Version

0.10.0-dev.1958+d5fcb5098

Steps to Reproduce

Here is the minimal reproducible example:

const err = error {SomeError};

fn testFunction() err![]const u8 {
   return err.SomeError;
}

pub fn main() void {
    var result = testFunction() catch "replacement"; // ← type coercion works in a normal variable
   var tuple = .{testFunction() catch "replacement"}; // ← but doesn't work for a tuple.
     _ = tuple;
    _ = result;
}

Expected Behavior

The string literal after the catch should coerce to the returning type of the function: []const u8.

Actual Behavior

Type coercion works fine for the normal variable, but with the tuple there is a compiler error:

./mre.zig:9:33: error: expected type '*const [11:0]u8', found '[]const u8'
   var tuple = .{testFunction() catch "replacement"}; // ← but doesn't work for a tuple.
                                ^

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorstage1The process of building from source via WebAssembly and the C backend.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions