Skip to content
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

Closed
andrewrk opened this issue Oct 21, 2017 · 3 comments
Closed

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

andrewrk opened this issue Oct 21, 2017 · 3 comments
Labels
bug Observed behavior contradicts documented or intended behavior
Milestone

Comments

@andrewrk
Copy link
Member

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 Observed behavior contradicts documented or intended behavior label Oct 21, 2017
@andrewrk andrewrk added this to the 0.2.0 milestone Oct 21, 2017
@andrewrk andrewrk modified the milestones: 0.2.0, 0.3.0 Mar 6, 2018
@andrewrk andrewrk changed the title var args can't handle void arguments var args can't handle void or number literal arguments Apr 11, 2018
@PavelVozenilek
Copy link

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
Copy link

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)));

@andrewrk andrewrk modified the milestones: 0.4.0, 0.5.0 Feb 15, 2019
@andrewrk andrewrk modified the milestones: 0.5.0, 0.6.0 Aug 21, 2019
@andrewrk
Copy link
Member Author

andrewrk commented Dec 9, 2019

Solved by removing var args from the language in a3f6a58. Tuples do not have this limitation.

@andrewrk andrewrk closed this as completed Dec 9, 2019
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
Projects
None yet
Development

No branches or pull requests

3 participants