Skip to content

Confusing error message with colliding struct fn and struct member names #2000

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
Sahnvour opened this issue Feb 23, 2019 · 1 comment
Closed

Comments

@Sahnvour
Copy link
Contributor

I was surprised to find that this snippet

const Foo = struct {
    bar: u32,

    pub fn bar(self: *Foo) u32 {
        return self.bar;
    }
};

test "bar" {
    var b = Foo{ .bar = 0 };
    _ = b.bar();
}

gives the following error

$ zig test typeIsNotAFunction.zig
typeIsNotAFunction.zig:11:10: error: type 'u32' not a function
    _ = b.bar();
         ^

I think Zig should first warn of an identifier clash, instead of choosing the struct member, and trying to use its type (??).

@tiehuis
Copy link
Member

tiehuis commented Feb 23, 2019

Duplicate of #705.

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