Skip to content

@Type builtin not picking up sentinel value from @typeInfo #3828

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
marler8997 opened this issue Dec 2, 2019 · 2 comments · Fixed by #3865 or sthagen/ziglang-zig#29
Closed

@Type builtin not picking up sentinel value from @typeInfo #3828

marler8997 opened this issue Dec 2, 2019 · 2 comments · Fixed by #3865 or sthagen/ziglang-zig#29

Comments

@marler8997
Copy link
Contributor

The following program shows that @Type does not maintain the sentinel value from typeinfo:

const std = @import("std");

fn testTypes(comptime types: []const type) void {
    var errorCount : usize = 0;
    inline for (types) |Expected| {
        const Actual = @Type(@typeInfo(Expected));
        if (Expected != Actual) {
            std.debug.warn("expected '{}'\n", @typeName(Expected));
            std.debug.warn("actual   '{}'\n", @typeName(Actual));
            errorCount += 1;
        }
    }
    if (errorCount > 0) {
        std.debug.warn("{}/{} test cases failed\n", errorCount, types.len);
    }
}

pub fn main() void {
    testTypes(&[_]type {
        [11:0]u8, [4:10]u8,
        [*:0]u8,                             [*:0]const u8,
        [*:0]volatile u8,                    [*:0]const volatile u8,
        [*:0]align(4) u8,                    [*:0]align(4) const u8,
        [*:0]align(4) volatile u8,           [*:0]align(4) const volatile u8,
        [*:0]align(8) u8,                    [*:0]align(8) const u8,
        [*:0]align(8) volatile u8,           [*:0]align(8) const volatile u8,
        [*:0]allowzero u8,                   [*:0]allowzero const u8,
        [*:0]allowzero volatile u8,          [*:0]allowzero const volatile u8,
        [*:0]allowzero align(4) u8,          [*:0]allowzero align(4) const u8,
        [*:0]allowzero align(4) volatile u8, [*:0]allowzero align(4) const volatile u8,
        [*:5]allowzero align(4) volatile u8, [*:5]allowzero align(4) const volatile u8,
        [:0]u8,                              [:0]const u8,
        [:0]volatile u8,                     [:0]const volatile u8,
        [:0]align(4) u8,                     [:0]align(4) const u8,
        [:0]align(4) volatile u8,            [:0]align(4) const volatile u8,
        [:0]align(8) u8,                     [:0]align(8) const u8,
        [:0]align(8) volatile u8,            [:0]align(8) const volatile u8,
        [:0]allowzero u8,                    [:0]allowzero const u8,
        [:0]allowzero volatile u8,           [:0]allowzero const volatile u8,
        [:0]allowzero align(4) u8,           [:0]allowzero align(4) const u8,
        [:0]allowzero align(4) volatile u8,  [:0]allowzero align(4) const volatile u8,
        [:4]allowzero align(4) volatile u8,  [:4]allowzero align(4) const volatile u8,
    });
}
@andrewrk
Copy link
Member

andrewrk commented Dec 6, 2019

Fixed by #3855.

@andrewrk andrewrk closed this as completed Dec 6, 2019
@marler8997
Copy link
Contributor Author

marler8997 commented Dec 7, 2019

@andrewrk I just built master and ran this test and it still fails 46 out of 46 cases. Can you please reopen (I can't reopen for some reason)? Here is the output of the given test program with latest zig compiler (05fc4d3)

expected '[11:0]u8'
actual   '[11]u8'
expected '[4:10]u8'
actual   '[4]u8'
expected '[*:0]u8'
actual   '[*]u8'
expected '[*:0]const u8'
actual   '[*]const u8'
expected '[*:0]volatile u8'
actual   '[*]volatile u8'
expected '[*:0]const volatile u8'
actual   '[*]const volatile u8'
expected '[*:0]align(4) u8'
actual   '[*]align(4) u8'
expected '[*:0]align(4) const u8'
actual   '[*]align(4) const u8'
expected '[*:0]align(4) volatile u8'
actual   '[*]align(4) volatile u8'
expected '[*:0]align(4) const volatile u8'
actual   '[*]align(4) const volatile u8'
expected '[*:0]align(8) u8'
actual   '[*]align(8) u8'
expected '[*:0]align(8) const u8'
actual   '[*]align(8) const u8'
expected '[*:0]align(8) volatile u8'
actual   '[*]align(8) volatile u8'
expected '[*:0]align(8) const volatile u8'
actual   '[*]align(8) const volatile u8'
expected '[*:0]allowzero u8'
actual   '[*]allowzero u8'
expected '[*:0]const allowzero u8'
actual   '[*]const allowzero u8'
expected '[*:0]volatile allowzero u8'
actual   '[*]volatile allowzero u8'
expected '[*:0]const volatile allowzero u8'
actual   '[*]const volatile allowzero u8'
expected '[*:0]align(4) allowzero u8'
actual   '[*]align(4) allowzero u8'
expected '[*:0]align(4) const allowzero u8'
actual   '[*]align(4) const allowzero u8'
expected '[*:0]align(4) volatile allowzero u8'
actual   '[*]align(4) volatile allowzero u8'
expected '[*:0]align(4) const volatile allowzero u8'
actual   '[*]align(4) const volatile allowzero u8'
expected '[*:5]align(4) volatile allowzero u8'
actual   '[*]align(4) volatile allowzero u8'
expected '[*:5]align(4) const volatile allowzero u8'
actual   '[*]align(4) const volatile allowzero u8'
expected '[:0]u8'
actual   '[]u8'
expected '[:0]const u8'
actual   '[]const u8'
expected '[:0]volatile u8'
actual   '[]volatile u8'
expected '[:0]const volatile u8'
actual   '[]const volatile u8'
expected '[:0]align(4) u8'
actual   '[]align(4) u8'
expected '[:0]align(4) const u8'
actual   '[]align(4) const u8'
expected '[:0]align(4) volatile u8'
actual   '[]align(4) volatile u8'
expected '[:0]align(4) const volatile u8'
actual   '[]align(4) const volatile u8'
expected '[:0]align(8) u8'
actual   '[]align(8) u8'
expected '[:0]align(8) const u8'
actual   '[]align(8) const u8'
expected '[:0]align(8) volatile u8'
actual   '[]align(8) volatile u8'
expected '[:0]align(8) const volatile u8'
actual   '[]align(8) const volatile u8'
expected '[:0]allowzero u8'
actual   '[]allowzero u8'
expected '[:0]const allowzero u8'
actual   '[]const allowzero u8'
expected '[:0]volatile allowzero u8'
actual   '[]volatile allowzero u8'
expected '[:0]const volatile allowzero u8'
actual   '[]const volatile allowzero u8'
expected '[:0]align(4) allowzero u8'
actual   '[]align(4) allowzero u8'
expected '[:0]align(4) const allowzero u8'
actual   '[]align(4) const allowzero u8'
expected '[:0]align(4) volatile allowzero u8'
actual   '[]align(4) volatile allowzero u8'
expected '[:0]align(4) const volatile allowzero u8'
actual   '[]align(4) const volatile allowzero u8'
expected '[:4]align(4) volatile allowzero u8'
actual   '[]align(4) volatile allowzero u8'
expected '[:4]align(4) const volatile allowzero u8'
actual   '[]align(4) const volatile allowzero u8'
46/46 test cases failed

@andrewrk andrewrk reopened this Dec 7, 2019
LemonBoy added a commit to LemonBoy/zig that referenced this issue Dec 8, 2019
The code converted the whole TypeInfo payload into an optional type
instead of using the "sentinel" field value.

Fixes ziglang#3828
andrewrk pushed a commit that referenced this issue Dec 8, 2019
The code converted the whole TypeInfo payload into an optional type
instead of using the "sentinel" field value.

Fixes #3828
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants