Skip to content

expected type 'fn() type', found 'fn() var' - only one is generic #4984

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
markfirmware opened this issue Apr 9, 2020 · 1 comment
Closed
Labels
bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend.
Milestone

Comments

@markfirmware
Copy link
Contributor

markfirmware commented Apr 9, 2020

I can't figure out what is wrong here. a() should return the function b() which itself returns a type (here an empty struct.)

./aaa.zig:10:7: error: expected type 'fn() type', found 'fn() var'
    }).b;
      ^
./aaa.zig:10:7: note: only one of the functions is generic
    }).b;
      ^


pub fn main() void {
    _ = a();
}

fn a() fn () type {
    return (struct {
        pub fn b() type {
            return struct {};
        }
    }).b;
@Vexu Vexu added bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend. labels Apr 9, 2020
@Vexu Vexu added this to the 0.7.0 milestone Apr 9, 2020
@hiroakitakada
Copy link

A similar error occurs with the following code (comes from #5817).

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);

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

@andrewrk andrewrk modified the milestones: 0.7.0, 0.8.0 Aug 13, 2020
@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 Nov 6, 2020
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 May 19, 2021
Vexu added a commit to Vexu/zig that referenced this issue Dec 31, 2022
Vexu added a commit to Vexu/zig that referenced this issue Dec 31, 2022
@andrewrk andrewrk modified the milestones: 0.12.0, 0.11.0 Jan 1, 2023
TUSF pushed a commit to TUSF/zig that referenced this issue May 9, 2024
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 stage1 The process of building from source via WebAssembly and the C backend.
Projects
None yet
Development

No branches or pull requests

4 participants