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

truncate to a u0 with a variable causes a compiler error #1568

winksaville opened this Issue Sep 20, 2018 · 1 comment


None yet
2 participants
Copy link

winksaville commented Sep 20, 2018

For example, this code:

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

test "truncate.u0.literal" {
    var z = @truncate(u0, 0);
    assert(z == 0);

test "truncate.u0.const" {
    const c0: usize = 0;
    var z = @truncate(u0, c0);
    assert(z == 0);

test "truncate.u0.var" {
    var d: u8 = 2;
    var z = @truncate(u0, d);
    assert(z == 0);

Causes the compiler to generate an error:

$ zig test truncate-u0.zig 
Trunc only produces integer
  trunc i8 %1 to void, !dbg !664
LLVM ERROR: Broken module found, compilation aborted!

But If I comment out test "truncate.u0.var" the first two tests for literal and const work:

$ zig test truncate-u0.zig 
Test 1/2 truncate.u0.literal...OK
Test 2/2 truncate.u0.const...OK
All tests passed.

@andrewrk andrewrk added this to the 0.4.0 milestone Sep 20, 2018

@andrewrk andrewrk added the bug label Sep 20, 2018


This comment has been minimized.

Copy link
Contributor Author

winksaville commented Sep 20, 2018

The actual source is here.

@andrewrk andrewrk closed this in caf672c Feb 10, 2019

emekoi added a commit to emekoi/zig that referenced this issue Feb 12, 2019

`@truncate`: comptime 0 when target type is 0 bits
also if the dest type is a comptime_int, then treat it
as an implicit cast.

also compile error for attempting to truncate undefined

closes ziglang#1568
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.