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

var args can't handle void or number literal arguments #557

Open
andrewrk opened this Issue Oct 21, 2017 · 2 comments

Comments

Projects
None yet
3 participants
@andrewrk
Member

andrewrk commented Oct 21, 2017

Issue discovered in #547

Related to #313 #279 #280

Add this test to std/fmt/index.zig:

    {
        var buf1: [32]u8 = undefined;
        const value: void = {};
        const result = bufPrint(buf1[0..], "void: {}\n", value);
        assert(mem.eql(u8, result, "void: {}\n"));
    }

@andrewrk andrewrk added the bug label Oct 21, 2017

@andrewrk andrewrk added this to the 0.2.0 milestone Oct 21, 2017

andrewrk added a commit that referenced this issue Oct 21, 2017

@andrewrk andrewrk modified the milestones: 0.2.0, 0.3.0 Mar 6, 2018

@andrewrk andrewrk changed the title from var args can't handle void arguments to var args can't handle void or number literal arguments Apr 11, 2018

@PavelVozenilek

This comment has been minimized.

PavelVozenilek commented Apr 28, 2018

When I try this in online compiler:

const std = @import("std");
const warn = std.debug.warn;

pub fn main() void {
  const o  = 1;
  warn("{}\n", o);    
}

I get this error:

/home/runner/.code.tio:6:16: error: compiler bug: integer and float literals in var args function must be casted. https://github.com/zig-lang/zig/issues/557

Something feels wrong here. When the value has explicit type it work.

@bfloch

This comment has been minimized.

bfloch commented Dec 1, 2018

Here is another one that points here:

warn("sizeOf u32 {}\n", @sizeOf(u32));

Fixed if the type is explicit:

const u32_size: usize = @sizeOf(u32);
warn("sizeOf u32 {}\n", u32_size);

Or even:

warn("sizeOf u32 {}\n", @intCast(usize, @sizeOf(u32)));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment