Merge pull request 'fixed compileError printing' (#419) from i418 into main

Reviewed-on: https://codeberg.org/ziglings/exercises/pulls/419
This commit is contained in:
Chris Boesch
2026-04-30 19:53:56 +02:00
2 changed files with 9 additions and 8 deletions

View File

@@ -1,4 +1,5 @@
const print = @import("std").debug.print; const std = @import("std");
const print = std.debug.print;
// We're going to (ab)use the power of Zig to make animal hybrid creatures! // We're going to (ab)use the power of Zig to make animal hybrid creatures!
// What do you think a GatorMouse would look like? Eek. // What do you think a GatorMouse would look like? Eek.
@@ -58,7 +59,7 @@ fn makeCreature(comptime count: usize, comptime fmt: []const u8) [count]Animal {
// other animals or is this an error? // other animals or is this an error?
'g' => ???, 'g' => ???,
else => @compileError("No animal starts with '" ++ char ++ "'!"), else => @compileError(std.fmt.comptimePrint("No animal starts with '{c}'!", .{char})),
}, },
.l => switch (char) { .l => switch (char) {

View File

@@ -1,6 +1,6 @@
--- exercises/074_comptime9.zig 2026-04-11 21:35:08.132459373 -0700 --- exercises/074_comptime9.zig 2026-04-30 19:28:08.990995153 +0200
+++ answers/074_comptime9.zig 2026-04-12 07:13:37.971010827 -0700 +++ answers/074_comptime9.zig 2026-04-30 19:27:09.642728692 +0200
@@ -27,12 +27,12 @@ @@ -28,12 +28,12 @@
start, // Ready to start a new animal. start, // Ready to start a new animal.
l, // This means we've seen an "l", so if we see an "m", we know it's a Llama. l, // This means we've seen an "l", so if we see an "m", we know it's a Llama.
}; };
@@ -15,16 +15,16 @@
inline for (fmt) |char| { inline for (fmt) |char| {
@@ -56,7 +56,7 @@ @@ -57,7 +57,7 @@
// //
// What do you think happens with Gators? Do they join with // What do you think happens with Gators? Do they join with
// other animals or is this an error? // other animals or is this an error?
- 'g' => ???, - 'g' => ???,
+ 'g' => @compileError("Gators refuse to join with other animals."), + 'g' => @compileError("Gators refuse to join with other animals."),
else => @compileError("No animal starts with '" ++ char ++ "'!"), else => @compileError(std.fmt.comptimePrint("No animal starts with '{c}'!", .{char})),
}, },
@@ -68,7 +68,7 @@ @@ -69,7 +69,7 @@
next_animal += 1; next_animal += 1;
// Something is missing here. After we finish a Llama, we // Something is missing here. After we finish a Llama, we
// need to be ready to _start_ over with a new animal... // need to be ready to _start_ over with a new animal...