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

Confusing type name of struct literal is inferred when it's passed to generic function #9339

Closed
Hadron67 opened this issue Jul 9, 2021 · 0 comments · Fixed by #9363
Closed
Labels
stage1 The process of building from source via WebAssembly and the C backend.
Milestone

Comments

@Hadron67
Copy link
Contributor

Hadron67 commented Jul 9, 2021

fn Foo(comptime T: type) type {
    return struct {
        pub const Type = T;
    };
}

const Bar = Foo(struct {});

comptime {
    @compileLog(@typeName(Bar));
    @compileLog(@typeName(Bar.Type));
}

output:

| *"Foo(Bar)"
| *"Bar"

While this seems wrong, it's actually the correct behaviour according to the documentation:

If the struct is in the initialization expression of a variable, it gets named after that variable.

So I think the type name inference rule needs some tweaking. In the example above, a more reasonable output could be something like Foo(struct:xx:xx) and struct:xx:xx.

mikdusan added a commit to mikdusan/zig that referenced this issue Jul 12, 2021
- generic "struct:L:C" naming if rloc is NodeTypeStructValueField
- generic "struct:L:C" naming if rloc is NodeTypeFnCallExpr
- move some tests from test/behavior/misc to test/behavior/typename

closes ziglang#4330
closes ziglang#9339
mikdusan added a commit to mikdusan/zig that referenced this issue Jul 12, 2021
- generic "struct:L:C" naming if rloc is NodeTypeStructValueField
- generic "struct:L:C" naming if rloc is NodeTypeFnCallExpr
- move some tests from test/behavior/misc to test/behavior/typename

closes ziglang#4330
closes ziglang#9339
mikdusan added a commit to mikdusan/zig that referenced this issue Jul 19, 2021
- generic "struct:L:C" naming if rloc is NodeTypeStructValueField
- generic "struct:L:C" naming if rloc is NodeTypeFnCallExpr
- move some tests from test/behavior/misc to test/behavior/typename

closes ziglang#4330
closes ziglang#9339
andrewrk pushed a commit that referenced this issue Jul 28, 2021
- generic "struct:L:C" naming if rloc is NodeTypeStructValueField
- generic "struct:L:C" naming if rloc is NodeTypeFnCallExpr
- move some tests from test/behavior/misc to test/behavior/typename

closes #4330
closes #9339
@andrewrk andrewrk added this to the 0.9.0 milestone Jul 28, 2021
@andrewrk andrewrk added the stage1 The process of building from source via WebAssembly and the C backend. label Jul 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stage1 The process of building from source via WebAssembly and the C backend.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants