mach: better compile error for missing fields in App. (#548)
Stage2 Zig ends up coercing structs without any fields into consts. The current error given is not entirely clear to the cause or how to fix the issue for users. Related to https://github.com/ziglang/zig/issues/12275
This commit is contained in:
parent
8b50f076a6
commit
7ed8829349
1 changed files with 13 additions and 0 deletions
|
|
@ -6,6 +6,19 @@ pub fn checkApplication(comptime app_pkg: type) void {
|
|||
}
|
||||
const App = app_pkg.App;
|
||||
|
||||
// If App has no fields, it gets interpretted as '*const App' when it should be '*App'
|
||||
// This gives a more useful compiler error.
|
||||
switch(@typeInfo(App)) {
|
||||
.Struct => |app| {
|
||||
if(app.fields.len == 0) {
|
||||
@compileError("App must contain fields. Example: '_unused: i32,'");
|
||||
}
|
||||
},
|
||||
else => {
|
||||
@compileError("App must be a struct type. Found:" ++ @typeName(App));
|
||||
}
|
||||
}
|
||||
|
||||
if (@hasDecl(App, "init")) {
|
||||
const InitFn = @TypeOf(@field(App, "init"));
|
||||
if (InitFn != fn (app: *App, core: *Core) @typeInfo(@typeInfo(InitFn).Fn.return_type.?).ErrorUnion.error_set!void)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue