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

Mutating "methods" can't be called on zero sized struct. #838

Closed
Hejsil opened this Issue Mar 17, 2018 · 1 comment

Comments

Projects
None yet
3 participants
@Hejsil
Member

Hejsil commented Mar 17, 2018

const S = struct {
    fn doC(s: &const S) void {}
    fn do(s: &S) void {}
};

test "" {
    var s = S{};
    S.doC(&s); // works!
    s.doC();   // works!
    S.do(&s);  // works!
    s.do();    // error: expected type '&S', found 'S'
}

@Hejsil Hejsil added the bug label Mar 18, 2018

@Sahnvour

This comment has been minimized.

Contributor

Sahnvour commented Mar 21, 2018

The branch between empty and non empty structs happens at https://github.com/zig-lang/zig/blob/master/src/ir.cpp#L12178 where an empty struct "handle" is not considered a pointer since 7bc0145.
We end up with first_arg being S instead of &S.

At this point I'm not sure what the correct fix would be.

@andrewrk andrewrk added this to the 0.3.0 milestone Mar 21, 2018

@andrewrk andrewrk closed this in 2594132 Jun 12, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment