Skip to content

Compiler should not permit fields with function types and struct functions to share the same name #1836

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
tgschultz opened this issue Dec 16, 2018 · 2 comments
Labels
breaking Implementing this issue could cause existing code to no longer compile or have different behavior. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone

Comments

@tgschultz
Copy link
Contributor

pub const S = struct
{
    func: fn() usize,
    
    pub fn func(self: *S) usize
    {
        return 2;
    }
};

pub fn func() usize
{
    return 1;
}

test ""
{
    var s = S{ .func = func, };
    debug.assert(s.func() == 2); //ambiguous
}
@andrewrk andrewrk added this to the 0.4.0 milestone Dec 17, 2018
@andrewrk andrewrk added the proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. label Dec 17, 2018
@andrewrk
Copy link
Member

andrewrk commented Feb 8, 2019

I think this is an important proposal, but deliberation and decision will have to wait until 0.5.0.

@andrewrk andrewrk modified the milestones: 0.4.0, 0.5.0 Feb 8, 2019
@andrewrk andrewrk modified the milestones: 0.5.0, 0.6.0 Sep 20, 2019
@andrewrk andrewrk added the breaking Implementing this issue could cause existing code to no longer compile or have different behavior. label Oct 17, 2019
@andrewrk andrewrk modified the milestones: 0.6.0, 0.7.0 Jan 3, 2020
@andrewrk andrewrk modified the milestones: 0.7.0, 0.8.0 Oct 10, 2020
@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 May 19, 2021
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 Nov 23, 2021
@andrewrk andrewrk modified the milestones: 0.10.0, 0.11.0 Apr 16, 2022
@andrewrk andrewrk modified the milestones: 0.11.0, 0.12.0 Apr 9, 2023
@andrewrk andrewrk modified the milestones: 0.13.0, 0.12.0 Jul 9, 2023
@xdBronch
Copy link
Contributor

added in #21231

b.zig:3:5: error: duplicate struct member name 'func'
    func: fn () usize,
    ^~~~
b.zig:5:12: note: duplicate name here
    pub fn func(self: *S) usize {
           ^~~~
b.zig:2:15: note: struct declared here
pub const S = struct {
              ^~~~~~

@Vexu Vexu closed this as completed Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking Implementing this issue could cause existing code to no longer compile or have different behavior. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Projects
None yet
Development

No branches or pull requests

4 participants