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

Missing parameter name after comptime arg asserts #1209

Closed
Hejsil opened this issue Jul 7, 2018 · 4 comments
Closed

Missing parameter name after comptime arg asserts #1209

Hejsil opened this issue Jul 7, 2018 · 4 comments
Labels
bug Observed behavior contradicts documented or intended behavior
Milestone

Comments

@Hejsil
Copy link
Sponsor Contributor

Hejsil commented Jul 7, 2018

pub fn a(comptime T: type, T) void {}

test "" {
    a(u8, 2);
}
zig/src/analyze.cpp:3448: VariableTableEntry* add_variable(CodeGen*, AstNode*, Scope*, Buf*, bool, ConstExprValue*, Tld*): Assertion `name' failed.
[1]    21470 abort (core dumped)  zig test test.zig
@Hejsil
Copy link
Sponsor Contributor Author

Hejsil commented Jul 7, 2018

Related:
It seems that only generic functions have parameters available right after they have been analyzed, while normal functions do not allow this. Is this intended?

// error: use of undeclared identifier 'b'
pub fn a(b: u8, c: @typeOf(b)) void {}

test "" {
    a(2, 2);
}
// Works, even though b is not generic
pub fn a(comptime Q: type, b: u8, c: @typeOf(b)) void {}

test "" {
    a(u8, 2, 2);
}

@andrewrk andrewrk added this to the 0.3.0 milestone Jul 7, 2018
@andrewrk andrewrk added the bug Observed behavior contradicts documented or intended behavior label Jul 7, 2018
@andrewrk
Copy link
Member

andrewrk commented Jul 7, 2018

Is this intended?

Yes, that is intended. (However, the assertion is not intended, of course.)

It could be made to work. Is there some compelling reason you would want to use @typeOf instead of repeating the type?

@Hejsil
Copy link
Sponsor Contributor Author

Hejsil commented Jul 7, 2018

@andrewrk I don't really have a usecase other than consistency, but I don't think it matters to much. Was just making sure that was how it should work.

@andrewrk
Copy link
Member

fixed in fd575fe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior
Projects
None yet
Development

No branches or pull requests

2 participants