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

types created inside functions are named after the function #675

Closed
andrewrk opened this Issue Jan 7, 2018 · 0 comments

Comments

Projects
None yet
1 participant
@andrewrk
Member

andrewrk commented Jan 7, 2018

This is useful for e.g.

pub fn ArrayList(comptime T: type) -> type {
    return struct {
        ...
    };
}

because now the type name created by ArrayList(u8) is ArrayList(u8).

however it becomes more problematic in this case:

export fn entry() {
    const Foo = struct { x: i32 };

    @compileLog(@typeName(Foo));
}

This prints entry() as the name of the Foo type, which is incorrect.

I think inside a function, if you assign an anonymous struct to a variable, we can use the variable name as the type name.

@andrewrk andrewrk added the bug label Jan 7, 2018

@andrewrk andrewrk added this to the 0.2.0 milestone Jan 7, 2018

@andrewrk andrewrk modified the milestones: 0.2.0, 0.3.0 Jan 18, 2018

bnoordhuis added a commit to bnoordhuis/zig that referenced this issue Feb 22, 2018

name types inside functions after variable
Before this commit:

    fn f() []const u8 {
        const S = struct {};
        return @typename(S);  // "f()", unexpected.
    }

And now:

    fn f() []const u8 {
        const S = struct {};
        return @typename(S);  // "S", expected.
    }

Fixes ziglang#675.

bnoordhuis added a commit to bnoordhuis/zig that referenced this issue Feb 22, 2018

name types inside functions after variable
Before this commit:

    fn f() []const u8 {
        const S = struct {};
        return @typename(S);  // "f()", unexpected.
    }

And now:

    fn f() []const u8 {
        const S = struct {};
        return @typename(S);  // "S", expected.
    }

Fixes ziglang#675.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment