Skip to content
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

Can't use ?*Self as a field type when it is passed to/returned from a function #6112

Closed
chadwain opened this issue Aug 21, 2020 · 1 comment

Comments

@chadwain
Copy link
Contributor

Using 0.6.0+1a4059ed8, this works:

const S = struct {
    a: ?*S,
};

pub fn main() void {
    _ = @as(S, undefined);
}

but this doesn't:

fn identity(comptime T: type) type {
    return T;
}

const S1 = struct {
    a: identity(?*S1),
};

fn addOptionalPointer(comptime T: type) type {
    return ?*T;
}

const S2 = struct {
    a: addOptionalPointer(S2),
};

const S3 = struct {
    a: @import("std").ArrayList(?*S3),
};

pub fn main() void {
    _ = @as(S1, undefined);
    _ = @as(S2, undefined);
    _ = @as(S3, undefined);
}
./main.zig:5:12: error: struct 'S1' depends on itself
const S1 = struct {
           ^
./main.zig:6:17: note: referenced here
    a: identity(?*S1),
                ^
./main.zig:6:16: note: referenced here
    a: identity(?*S1),
               ^
./main.zig:13:12: error: struct 'S2' depends on itself
const S2 = struct {
           ^
./main.zig:9:46: note: referenced here
fn addOptionalPointer(comptime T: type) type {
                                             ^
./main.zig:14:26: note: referenced here
    a: addOptionalPointer(S2),
                         ^
./main.zig:17:12: error: struct 'S3' depends on itself
const S3 = struct {
           ^
./main.zig:18:33: note: referenced here
    a: @import("std").ArrayList(?*S3),
                                ^
./main.zig:18:32: note: referenced here
    a: @import("std").ArrayList(?*S3),
                               ^

(Trying the same thing with only ordinary pointers seems to work fine.)
Related: #5414

@Vexu
Copy link
Member

Vexu commented Aug 21, 2020

Duplicate of #4562.

@Vexu Vexu closed this as completed Aug 21, 2020
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