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

Closed
winksaville opened this issue Sep 20, 2018 · 1 comment
Closed

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

winksaville opened this issue Sep 20, 2018 · 1 comment
Labels
bug Observed behavior contradicts documented or intended behavior
Milestone

Comments

@winksaville
Copy link
Contributor

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 Observed behavior contradicts documented or intended behavior label Sep 20, 2018
@winksaville
Copy link
Contributor Author

The actual source is here.

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

2 participants