Merge pull request 'add hint that @field() works differently on types and values' (#367) from pebose/exercises:add-hint-to-exercise-82 into main

Reviewed-on: https://codeberg.org/ziglings/exercises/pulls/367
This commit is contained in:
Chris Boesch 2026-02-27 19:17:59 +01:00
commit 908109df2d
2 changed files with 8 additions and 4 deletions

View File

@ -118,6 +118,10 @@ fn printTuple(tuple: anytype) void {
// @field(foo, "x"); // returns the value at foo.x
//
// The first field should print as: "0"(bool):true
//
// Hint: Be careful! If your 'lhs' is a type, @field() looks
// for declarations. If it's a value, it looks for data.
//
print("\"{s}\"({any}):{any} ", .{
field.???,
field.???,

View File

@ -1,5 +1,5 @@
--- exercises/082_anonymous_structs3.zig 2025-03-14 16:41:17.892873287 +0200
+++ answers/082_anonymous_structs3.zig 2025-03-14 16:40:56.043829543 +0200
--- exercises/082_anonymous_structs3.zig 2026-02-27 13:05:46
+++ answers/082_anonymous_structs3.zig 2026-02-27 13:07:22
@@ -82,14 +82,14 @@
// @typeInfo(Circle).@"struct".fields
//
@ -17,9 +17,9 @@
// 3. Print the field's name, type, and value.
//
// Each 'field' in this loop is one of these:
@@ -119,9 +119,9 @@
@@ -123,9 +123,9 @@
// for declarations. If it's a value, it looks for data.
//
// The first field should print as: "0"(bool):true
print("\"{s}\"({any}):{any} ", .{
- field.???,
- field.???,