Skip to content

return type of a function with a comptime argument becomes var #5817

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

Closed
hiroakitakada opened this issue Jul 8, 2020 · 2 comments
Closed

Comments

@hiroakitakada
Copy link

The following code gets a compile error saying expected type 'fn(u32) u32', found 'fn(u32) var'.

fn comptime_add1(comptime x: u32) u32 {
    return x + 1;
}

fn apply(func: fn(u32) u32, x: u32) u32 {
    return func(x);
}

export var v1 = apply(comptime_add1, 1);

So, I checked the type of comptime_add1 with @compileLog(@TypeOf(comptime_add1)) and found its type is fn(u32) var. Is this a bug or an intended behavior?

@daurnimator
Copy link
Contributor

I think this is a dupe of #4984 and possibly #846?

@hiroakitakada
Copy link
Author

@daurnimator, thanks for the information.

I think #4984 is very similar, but I cannot decide they come from a same defect. I will add my code to #4984 and close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants