-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Stage 1 ir_analyze_container_member_access_inner panic #9142
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
Comments
I learned a bit more of the language and I think the issue is that anytype is allowed in the struct fields when it shouldn't be. Is this correct @Vexu ? |
I don't see any reason for the |
A reason for not allowing const std = @import("std");
const Dispatcher = struct {
systems: anytype,
fn doSomething(comptime this: *const @This()) void {
for (this.systems) |sys| {
}
}
};
test {
const systems1 = .{5, 6};
const dispatcher1 = Dispatcher {
.systems = systems1,
};
const systems2 = 5;
const dispatcher2 = Dispatcher {
.systems = systems2,
};
try std.testing.expect(@TypeOf(dispatcher1) != @TypeOf(dispatcher2));
} Would you expect this to fail or to succeed? I would expect this to succeed and that the types of Another example: test {
const systems1 = .{5, 6};
const dispatcher1 = Dispatcher {
.systems = systems1,
};
const systems2 = 5;
const dispatcher2 = Dispatcher {
.systems = systems2,
};
try std.testing.expect(@TypeOf(dispatcher1) != Dispatcher);
try std.testing.expect(@TypeOf(dispatcher2) != Dispatcher);
} Would you expect this to fail or to succeed? This question is a lot more though, since AlternativeI think the right way to do something like this is to use generics: fn Dispatcher(comptime T: type) type {
return struct {
systems: T,
fn doSomething(comptime this: *const @This()) void {
inline for (this.systems) |sys| {
}
}
};
}
test {
const systems = .{5, 6};
const dispatcher = Dispatcher(@TypeOf(systems)) {
.systems = systems,
};
dispatcher.doSomething();
} NOTE: I added This removes the problem of the |
I ran into this as well. In my case I had a function with an Link to the crashing case in godbolt Link with some workarounds using a function returning a type |
Zig master returns a proper error:
Closing the issue :) |
yeah |
Reproduction:
Error:
I get the same output using
zig run -O Debug src/main.zig
.Expected: Probably an error, but I'm not sure what the exact behavior should be here.
Version:
0.9.0-dev.187+bfe3558ef
The text was updated successfully, but these errors were encountered: