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

types created inside functions are named after the function #675

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

types created inside functions are named after the function #675

andrewrk opened this issue Jan 7, 2018 · 0 comments
Labels
Milestone

Comments

@andrewrk
Copy link
Member

@andrewrk 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 removed this from the 0.2.0 milestone Jan 18, 2018
@andrewrk andrewrk added this to the 0.3.0 milestone Jan 18, 2018
bnoordhuis added a commit to bnoordhuis/zig that referenced this issue Feb 22, 2018
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
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant