about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlexey Yerin <yyp@disroot.org>2025-08-02 13:24:49 +0300
committerAlexey Yerin <yyp@disroot.org>2025-08-02 13:24:49 +0300
commit8e8a4a50227ba3e7bda74ada326fec686f15da86 (patch)
tree704c4800a8e0c5f8b2b5ae1b6cf67492939aae1e
parent677d08ddeff8bde164fd01f7a6d19ec4bb42adcf (diff)
Print an error if there are unresolved types
-rw-r--r--cmd/hare-gi/context.ha1
-rw-r--r--cmd/hare-gi/emit.ha5
-rw-r--r--cmd/hare-gi/main.ha13
3 files changed, 19 insertions, 0 deletions
diff --git a/cmd/hare-gi/context.ha b/cmd/hare-gi/context.ha
index 672129f..606eb80 100644
--- a/cmd/hare-gi/context.ha
+++ b/cmd/hare-gi/context.ha
@@ -28,6 +28,7 @@ type namespace = struct {
 	module: ident,
 	output_file: io::file,
 	output: io::handle,
+	unresolved_types: size,
 };
 fn namespace_finish(ns: *namespace) void = {
 	gir::namespace_finish(ns);
diff --git a/cmd/hare-gi/emit.ha b/cmd/hare-gi/emit.ha
index 4a9307e..1ab3d0a 100644
--- a/cmd/hare-gi/emit.ha
+++ b/cmd/hare-gi/emit.ha
@@ -119,10 +119,12 @@ fn emit_class(ctx: *context, class: *gir::class) (void | io::error) = {
 					fmt::fprintf(ctx.current.output,
 						"#unresolved type {}#",
 						class.parent)?;
+					ctx.current.unresolved_types += 1;
 				};
 			case null =>
 				fmt::fprintf(ctx.current.output,
 					"#unresolved type {}#", class.parent)?;
+				ctx.current.unresolved_types += 1;
 			};
 			fmt::fprintln(ctx.current.output, " };")?;
 		} else {
@@ -656,6 +658,7 @@ fn emit_type(ctx: *context, t: (gir::any_type | gir::callback), flags: ctype_fla
 				case null =>
 					fmt::fprintf(ctx.current.output,
 						"#unresolved type {}#", t.name)?;
+					ctx.current.unresolved_types += 1;
 					return;
 				};
 				match (lookup_type_in_namespace(ns, second)) {
@@ -664,6 +667,7 @@ fn emit_type(ctx: *context, t: (gir::any_type | gir::callback), flags: ctype_fla
 				case =>
 					fmt::fprintf(ctx.current.output,
 						"#unresolved type {}#", t.name)?;
+					ctx.current.unresolved_types += 1;
 				};
 			};
 		};
@@ -720,6 +724,7 @@ fn emit_c_type(ctx: *context, type_: ctype, flags: ctype_flag...) (void | io::er
 		case =>
 			fmt::fprintf(ctx.current.output, "#unresolved type {}#",
 				id)?;
+			ctx.current.unresolved_types += 1;
 		};
 	case let b: cbuiltin =>
 		if (cbuiltin_needs_import(b)) {
diff --git a/cmd/hare-gi/main.ha b/cmd/hare-gi/main.ha
index a02d5b0..0ea23f8 100644
--- a/cmd/hare-gi/main.ha
+++ b/cmd/hare-gi/main.ha
@@ -142,4 +142,17 @@ export fn main() void = {
 	case let err: io::error =>
 		fmt::fatal("Error:", io::strerror(err));
 	};
+
+	let errors = 0z;
+	for (let ns &.. ctx.namespaces) {
+		if (ns.unresolved_types != 0) {
+			fmt::errorfln(
+				`{}: {} unresolved types (see "#unresolved type" in generated file)`,
+				ns.name, ns.unresolved_types)!;
+			errors += 1;
+		};
+	};
+	if (errors > 0) {
+		os::exit(1);
+	};
 };