authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2023-01-02 19:23:09+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2023-01-02 19:23:09+02:00
logb048fa4f1377c84327f74fd4ecd5b03141e68e36
treec677c0659c290668e49245b75cecd296a68a4b9e
parent332a43858a6ba2128d3df9e6bca45a10547ed383

Sema: prevent spurious "depends on itself" errors

Closes #14059

1 files changed, 27 insertions(+), 3 deletions(-)

src/Sema.zig+27-3
...@@ -30337,6 +30337,18 @@ fn resolveTypeFieldsStruct(...@@ -30337,6 +30337,18 @@ fn resolveTypeFieldsStruct(
30337 ty: Type,30337 ty: Type,
30338 struct_obj: *Module.Struct,30338 struct_obj: *Module.Struct,
30339) CompileError!void {30339) CompileError!void {
30340 switch (sema.mod.declPtr(struct_obj.owner_decl).analysis) {
30341 .file_failure,
30342 .dependency_failure,
30343 .sema_failure,
30344 .sema_failure_retryable,
30345 => {
30346 sema.owner_decl.analysis = .dependency_failure;
30347 sema.owner_decl.generation = sema.mod.generation;
30348 return error.AnalysisFail;
30349 },
30350 else => {},
30351 }
30340 switch (struct_obj.status) {30352 switch (struct_obj.status) {
30341 .none => {},30353 .none => {},
30342 .field_types_wip => {30354 .field_types_wip => {
...@@ -30357,10 +30369,23 @@ fn resolveTypeFieldsStruct(...@@ -30357,10 +30369,23 @@ fn resolveTypeFieldsStruct(
30357 }30369 }
3035830370
30359 struct_obj.status = .field_types_wip;30371 struct_obj.status = .field_types_wip;
30372 errdefer struct_obj.status = .none;
30360 try semaStructFields(sema.mod, struct_obj);30373 try semaStructFields(sema.mod, struct_obj);
30361}30374}
3036230375
30363fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_obj: *Module.Union) CompileError!void {30376fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_obj: *Module.Union) CompileError!void {
30377 switch (sema.mod.declPtr(union_obj.owner_decl).analysis) {
30378 .file_failure,
30379 .dependency_failure,
30380 .sema_failure,
30381 .sema_failure_retryable,
30382 => {
30383 sema.owner_decl.analysis = .dependency_failure;
30384 sema.owner_decl.generation = sema.mod.generation;
30385 return error.AnalysisFail;
30386 },
30387 else => {},
30388 }
30364 switch (union_obj.status) {30389 switch (union_obj.status) {
30365 .none => {},30390 .none => {},
30366 .field_types_wip => {30391 .field_types_wip => {
...@@ -30381,6 +30406,7 @@ fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_obj: *Module.Union) Compi...@@ -30381,6 +30406,7 @@ fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_obj: *Module.Union) Compi
30381 }30406 }
3038230407
30383 union_obj.status = .field_types_wip;30408 union_obj.status = .field_types_wip;
30409 errdefer union_obj.status = .none;
30384 try semaUnionFields(sema.mod, union_obj);30410 try semaUnionFields(sema.mod, union_obj);
30385 union_obj.status = .have_field_types;30411 union_obj.status = .have_field_types;
30386}30412}
...@@ -30445,9 +30471,7 @@ fn resolveInferredErrorSetTy(...@@ -30445,9 +30471,7 @@ fn resolveInferredErrorSetTy(
30445fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void {30471fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void {
30446 const gpa = mod.gpa;30472 const gpa = mod.gpa;
30447 const decl_index = struct_obj.owner_decl;30473 const decl_index = struct_obj.owner_decl;
30448 const file_scope = struct_obj.namespace.file_scope;30474 const zir = struct_obj.namespace.file_scope.zir;
30449 if (file_scope.status != .success_zir) return error.AnalysisFail;
30450 const zir = file_scope.zir;
30451 const extended = zir.instructions.items(.data)[struct_obj.zir_index].extended;30475 const extended = zir.instructions.items(.data)[struct_obj.zir_index].extended;
30452 assert(extended.opcode == .struct_decl);30476 assert(extended.opcode == .struct_decl);
30453 const small = @bitCast(Zir.Inst.StructDecl.Small, extended.small);30477 const small = @bitCast(Zir.Inst.StructDecl.Small, extended.small);