Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
IntegratedQuantum opened this issue Apr 29, 2022 · 1 comment
Closed
Labels
bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend.
Milestone

Comments

@IntegratedQuantum
Copy link
Contributor

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.
                                ^
@IntegratedQuantum IntegratedQuantum added the bug Observed behavior contradicts documented or intended behavior label Apr 29, 2022
@Vexu Vexu added the stage1 The process of building from source via WebAssembly and the C backend. label Apr 29, 2022
@Vexu Vexu added this to the 0.12.0 milestone Apr 29, 2022
@Vexu
Copy link
Member

Vexu commented Jan 13, 2023

Duplicate of #3882

@Vexu Vexu marked this as a duplicate of #3882 Jan 13, 2023
@Vexu Vexu closed this as completed Jan 13, 2023
@andrewrk andrewrk modified the milestones: 0.12.0, 0.11.0 Jan 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend.
Projects
None yet
Development

No branches or pull requests

3 participants