Commit 886fa455fa

Veikka Tuominen <git@vexu.eu>
2022-12-11 21:06:17
Sema: avoid analyzing functions which failed when inlining
1 parent e658885
src/Sema.zig
@@ -2257,6 +2257,9 @@ fn failWithOwnedErrorMsg(sema: *Sema, err_msg: *Module.ErrorMsg) CompileError {
         sema.owner_decl.analysis = .sema_failure;
         sema.owner_decl.generation = mod.generation;
     }
+    if (sema.func) |func| {
+        func.state = .sema_failure;
+    }
     const gop = mod.failed_decls.getOrPutAssumeCapacity(sema.owner_decl_index);
     if (gop.found_existing) {
         // If there are multiple errors for the same Decl, prefer the first one added.
@@ -6385,6 +6388,7 @@ fn analyzeCall(
             }),
             else => unreachable,
         };
+        if (!is_comptime_call and module_fn.state == .sema_failure) return error.AnalysisFail;
 
         // Analyze the ZIR. The same ZIR gets analyzed into a runtime function
         // or an inlined call depending on what union tag the `label` field is
test/cases/compile_errors/stage1/exe/missing_main_fn_in_executable.zig
@@ -1,8 +0,0 @@
-
-
-// error
-// backend=stage1
-// target=native
-// output_mode=Exe
-//
-// error: root source file has no member called 'main'
test/cases/compile_errors/stage1/exe/private_main_fn.zig
@@ -1,9 +0,0 @@
-fn main() void {}
-
-// error
-// backend=stage1
-// target=native
-// output_mode=Exe
-//
-// error: 'main' is private
-// tmp.zig:1:1: note: declared here
test/cases/compile_errors/missing_main_fn_in_executable.zig
@@ -0,0 +1,9 @@
+
+
+// error
+// backend=llvm
+// target=x86_64-linux
+// output_mode=Exe
+//
+// :?:?: error: root struct of file 'tmp' has no member named 'main'
+// :?:?: note: called from here
test/cases/compile_errors/private_main_fn.zig
@@ -0,0 +1,10 @@
+fn main() void {}
+
+// error
+// backend=llvm
+// target=x86_64-linux
+// output_mode=Exe
+//
+// :?:?: error: 'main' is not marked 'pub'
+// :1:1: note: declared here
+// :?:?: note: called from here