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

Fields of type type are apparently actually &const type #958

Closed
Hejsil opened this issue Apr 26, 2018 · 2 comments
Closed

Fields of type type are apparently actually &const type #958

Hejsil opened this issue Apr 26, 2018 · 2 comments

Comments

@Hejsil
Copy link
Sponsor Contributor

Hejsil commented Apr 26, 2018

const S = struct {
    T: type
};

// error: expected type 'type', found '&const type'
//                         V
fn takeS(comptime s: S, a: &s.T) void { }

test "" {
    var a : u8 = 0;
    const s = S { .T = u8 };
    takeS(s, &a);
}

Deref the &const type, and we get this error:

const S = struct {
    T: type
};

fn takeS(comptime s: S, a: &*s.T) void { }

test "" {
    var a : u8 = 0;
    const s = S { .T = u8 };
    takeS(s, &a); // error: expected type 'u8', found '&u8'
}
@Hejsil
Copy link
Sponsor Contributor Author

Hejsil commented Apr 26, 2018

Ooh wait. This is not a bug, but a thing solved my #770

@Hejsil
Copy link
Sponsor Contributor Author

Hejsil commented Apr 26, 2018

Workaround:

const S = struct {
    T: type
};

fn takePtr(comptime T: type) type { return &T; }

fn takeS(comptime s: S, a: takePtr(s.T)) void { }

test "" {
    var a : u8 = 0;
    const s = S { .T = u8 };
    takeS(s, &a);
}

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

1 participant