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

@typeName on slices segfaults #2026

hcff opened this Issue Mar 2, 2019 · 1 comment


None yet
2 participants
Copy link

hcff commented Mar 2, 2019

pub fn main() void {
    _ = @typeName([]u8);
| []u8
Segmentation fault (core dumped)

This also happen with []bool, but not with [*]u8.

From a quick look with gdb, it seems that ir_analyze_instruction_type_name calls type_bare_name to get the type name.

Buf *type_bare_name(ZigType *type_entry) {
    if (is_container(type_entry)) {
        return get_container_scope(type_entry)->bare_name;
    } else if (type_entry->id == ZigTypeIdOpaque) {
        return type_entry->data.opaque.bare_name;
    } else {
        return &type_entry->name;

Slices have ZigTypeIdStruct as an id, so is_container(type_entry) is true, so instead of returning a perfectly valid &type_entry->name, it doesget_container_scope(type_entry)->bare_name, when type_entry->data.structure.decls_scope is null.

@andrewrk andrewrk added the bug label Mar 2, 2019

@andrewrk andrewrk added this to the 0.4.0 milestone Mar 2, 2019

@andrewrk andrewrk closed this in ea5cedc Mar 2, 2019


This comment has been minimized.

Copy link

andrewrk commented Mar 2, 2019

Thanks for the report! Fixed

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.