Skip to content

peer type resolution for slice and single-pointer-to-array #4766

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
andrewrk opened this issue Mar 19, 2020 · 0 comments
Closed

peer type resolution for slice and single-pointer-to-array #4766

andrewrk opened this issue Mar 19, 2020 · 0 comments
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. stage1 The process of building from source via WebAssembly and the C backend.
Milestone

Comments

@andrewrk
Copy link
Member

Extracted from #4752.

Test case:

const std = @import("std");

fn foo(c: u8, char_buf: *[4]u8) []const u8 {
    return switch (c) {
        '\"' => "\\\"",
        '\'' => "\\'",
        '\\' => "\\\\",
        '\n' => "\\n",
        '\r' => "\\r",
        '\t' => "\\t",
        else => {
            if (c == 10) {
                return bar(char_buf);
            } else {
                return bar(char_buf);
            }
        },
    };
}

fn bar(buf: []u8) []u8 {
    buf[0..4].* = "abcd".*;
    return buf;
}

test "peer type resolution for slice and single-pointer-to-array" {
    var buf: [4]u8 = undefined;
    std.testing.expect(std.mem.eql(u8, foo('\\', &buf), "\\"));
    std.testing.expect(std.mem.eql(u8, foo(10, &buf), "abcd"));
}

Expected to pass. Instead:

./test2.zig:3:33: error: incompatible types: '[]u8' and '*const [2:0]u8'
fn foo(c: u8, char_buf: *[4]u8) []const u8 {
                                ^
./test2.zig:13:27: note: type '[]u8' here
                return bar(char_buf);
                          ^
./test2.zig:5:17: note: type '*const [2:0]u8' here
        '\"' => "\\\"",
                ^
@andrewrk andrewrk added enhancement Solving this issue will likely involve adding new logic or components to the codebase. stage1 The process of building from source via WebAssembly and the C backend. labels Mar 19, 2020
@andrewrk andrewrk added this to the 0.7.0 milestone Mar 19, 2020
@andrewrk andrewrk modified the milestones: 0.7.0, 0.6.0 Mar 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. stage1 The process of building from source via WebAssembly and the C backend.
Projects
None yet
Development

No branches or pull requests

1 participant