We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
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
0.12.0-dev.2334+aef1da163
const std = @import("std"); const A = struct { value: usize = 0, pub fn foo(self: A) void { _ = self; } pub fn bar(self: *A) void { _ = self; } pub fn baz(self: *const A) void { _ = self; } }; pub fn B(comptime Child: type) type { return struct { children: Child, }; } fn createB(children: anytype) B(@TypeOf(children)) { return .{ .children = children }; } pub fn RuntimeTuple(comptime T: type) type { const info = @typeInfo(T); const len = info.Struct.fields.len; var types: [len]type = undefined; for (info.Struct.fields, &types) |field, *tp| { tp.* = field.type; } return std.meta.Tuple(&types); } fn createRuntimeB(children: anytype) B(RuntimeTuple(@TypeOf(children))) { return .{ .children = children }; } pub fn main() !void { // creates a value with type B(struct{ comptime A = .{}, comptime A = .{} }) var a = createB(.{ A{}, A{} }); // c.children[0].value = 2; fails with reasonable error message. switch (.Ptr) { .Value => a.children[0].foo(), // Works .Ptr => a.children[0].bar(), // Semantically incorrect code. Crashes the compiler .ConstPtr => a.children[0].baz(), // Could maybe work? Crashes the compiler else => unreachable, } // What I meant to do: // create a value with type B(struct{A, A}) var b = createRuntimeB(.{ A{}, A{} }); b.children[0].foo(); b.children[0].bar(); b.children[0].baz(); }
Note that the compiler is correct in rejecting the code but should do so with some kind of error message.
Compilation should fail with an error message similar to the one when you try to modify a field of a.
The text was updated successfully, but these errors were encountered:
Duplicate of #12963
Sorry, something went wrong.
No branches or pull requests
Zig Version
0.12.0-dev.2334+aef1da163
Steps to Reproduce and Observed Behavior
Note that the compiler is correct in rejecting the code but should do so with some kind of error message.
Expected Behavior
Compilation should fail with an error message similar to the one when you try to modify a field of a.
The text was updated successfully, but these errors were encountered: