Merge pull request 'Fixes several changes in std.builtin.zig' (#150) from i149 into main

Reviewed-on: https://codeberg.org/ziglings/exercises/pulls/150
This commit is contained in:
Chris Boesch 2024-09-02 17:57:42 +00:00
commit 2e5b570aef
9 changed files with 22 additions and 21 deletions

View file

@ -89,6 +89,7 @@ that if you update one, you may need to also update the other.
### Version Changes ### Version Changes
Version-0.14.0-dev.1224 Version-0.14.0-dev.1224
* *2024-07-02* zig 0.14.0-dev.1409 - several changes in std.builtin, see [#21225](https://github.com/ziglang/zig/pull/21225)
* *2024-08-04* zig 0.14.0-dev.1224 - several changes in build system, see [#21115](https://github.com/ziglang/zig/pull/21115) * *2024-08-04* zig 0.14.0-dev.1224 - several changes in build system, see [#21115](https://github.com/ziglang/zig/pull/21115)
* *2024-08-04* zig 0.14.0-dev.839 - several changes in build system, see [#20580](https://github.com/ziglang/zig/pull/20580), [#20600](https://github.com/ziglang/zig/issues/20600) * *2024-08-04* zig 0.14.0-dev.839 - several changes in build system, see [#20580](https://github.com/ziglang/zig/pull/20580), [#20600](https://github.com/ziglang/zig/issues/20600)
* *2024-06-17* zig 0.14.0-dev.42 - changes in `std.mem.split and tokenize` - see [#15579](https://github.com/ziglang/zig/pull/15579) * *2024-06-17* zig 0.14.0-dev.42 - changes in `std.mem.split and tokenize` - see [#15579](https://github.com/ziglang/zig/pull/15579)

View file

@ -15,7 +15,7 @@ const print = std.debug.print;
// 1) Getting Started // 1) Getting Started
// 2) Version Changes // 2) Version Changes
comptime { comptime {
const required_zig = "0.14.0-dev.1224"; const required_zig = "0.14.0-dev.1409";
const current_zig = builtin.zig_version; const current_zig = builtin.zig_version;
const min_zig = std.SemanticVersion.parse(required_zig) catch unreachable; const min_zig = std.SemanticVersion.parse(required_zig) catch unreachable;
if (current_zig.order(min_zig) == .lt) { if (current_zig.order(min_zig) == .lt) {

View file

@ -94,7 +94,7 @@ pub fn main() void {
print("He has room in his heart for:", .{}); print("He has room in his heart for:", .{});
// A StructFields array // A StructFields array
const fields = @typeInfo(Narcissus).Struct.fields; const fields = @typeInfo(Narcissus).@"struct".fields;
// 'fields' is a slice of StructFields. Here's the declaration: // 'fields' is a slice of StructFields. Here's the declaration:
// //
@ -110,15 +110,15 @@ pub fn main() void {
// name will not be printed if the field is of type 'void' // name will not be printed if the field is of type 'void'
// (which is a zero-bit type that takes up no space at all!): // (which is a zero-bit type that takes up no space at all!):
if (fields[0].??? != void) { if (fields[0].??? != void) {
print(" {s}", .{@typeInfo(Narcissus).Struct.fields[0].name}); print(" {s}", .{@typeInfo(Narcissus).@"struct".fields[0].name});
} }
if (fields[1].??? != void) { if (fields[1].??? != void) {
print(" {s}", .{@typeInfo(Narcissus).Struct.fields[1].name}); print(" {s}", .{@typeInfo(Narcissus).@"struct".fields[1].name});
} }
if (fields[2].??? != void) { if (fields[2].??? != void) {
print(" {s}", .{@typeInfo(Narcissus).Struct.fields[2].name}); print(" {s}", .{@typeInfo(Narcissus).@"struct".fields[2].name});
} }
// Yuck, look at all that repeated code above! I don't know // Yuck, look at all that repeated code above! I don't know

View file

@ -38,7 +38,7 @@ pub fn main() void {
// Please use an 'inline for' to implement the block below // Please use an 'inline for' to implement the block below
// for each field in the slice 'fields'! // for each field in the slice 'fields'!
const fields = @typeInfo(Narcissus).Struct.fields; const fields = @typeInfo(Narcissus).@"struct".fields;
??? { ??? {
if (field.type != void) { if (field.type != void) {

View file

@ -78,7 +78,7 @@ fn printSequence(my_seq: anytype) void {
// a switch to handle printing the Array or Pointer fields, // a switch to handle printing the Array or Pointer fields,
// depending on which type of my_seq was passed in: // depending on which type of my_seq was passed in:
switch (my_typeinfo) { switch (my_typeinfo) {
.Array => { .array => {
print("Array:", .{}); print("Array:", .{});
// Loop through the items in my_seq. // Loop through the items in my_seq.
@ -86,7 +86,7 @@ fn printSequence(my_seq: anytype) void {
print("{}", .{s}); print("{}", .{s});
} }
}, },
.Pointer => { .pointer => {
// Check this out - it's pretty cool: // Check this out - it's pretty cool:
const my_sentinel = sentinel(@TypeOf(my_seq)); const my_sentinel = sentinel(@TypeOf(my_seq));
print("Many-item pointer:", .{}); print("Many-item pointer:", .{});

View file

@ -1,5 +1,5 @@
--- exercises/065_builtins2.zig 2023-10-03 22:15:22.125574535 +0200 --- exercises/065_builtins2.zig 2024-09-02 19:15:56.569952315 +0200
+++ answers/065_builtins2.zig 2023-10-05 20:04:07.136101712 +0200 +++ answers/065_builtins2.zig 2024-09-02 19:13:44.280600350 +0200
@@ -58,7 +58,7 @@ @@ -58,7 +58,7 @@
// Oops! We cannot leave the 'me' and 'myself' fields // Oops! We cannot leave the 'me' and 'myself' fields
// undefined. Please set them here: // undefined. Please set them here:
@ -24,16 +24,16 @@
// (which is a zero-bit type that takes up no space at all!): // (which is a zero-bit type that takes up no space at all!):
- if (fields[0].??? != void) { - if (fields[0].??? != void) {
+ if (fields[0].type != void) { + if (fields[0].type != void) {
print(" {s}", .{@typeInfo(Narcissus).Struct.fields[0].name}); print(" {s}", .{@typeInfo(Narcissus).@"struct".fields[0].name});
} }
- if (fields[1].??? != void) { - if (fields[1].??? != void) {
+ if (fields[1].type != void) { + if (fields[1].type != void) {
print(" {s}", .{@typeInfo(Narcissus).Struct.fields[1].name}); print(" {s}", .{@typeInfo(Narcissus).@"struct".fields[1].name});
} }
- if (fields[2].??? != void) { - if (fields[2].??? != void) {
+ if (fields[2].type != void) { + if (fields[2].type != void) {
print(" {s}", .{@typeInfo(Narcissus).Struct.fields[2].name}); print(" {s}", .{@typeInfo(Narcissus).@"struct".fields[2].name});
} }

View file

@ -1,8 +1,8 @@
--- exercises/071_comptime6.zig 2023-10-03 22:15:22.125574535 +0200 --- exercises/071_comptime6.zig 2024-09-02 19:21:50.250454978 +0200
+++ answers/071_comptime6.zig 2023-10-05 20:04:07.162768879 +0200 +++ answers/071_comptime6.zig 2024-09-02 19:21:23.553250563 +0200
@@ -40,7 +40,7 @@ @@ -40,7 +40,7 @@
const fields = @typeInfo(Narcissus).Struct.fields; const fields = @typeInfo(Narcissus).@"struct".fields;
- ??? { - ??? {
+ inline for (fields) |field| { + inline for (fields) |field| {

View file

@ -1,5 +1,5 @@
--- exercises/076_sentinels.zig 2023-10-03 22:15:22.125574535 +0200 --- exercises/076_sentinels.zig 2024-09-02 19:27:04.336781039 +0200
+++ answers/076_sentinels.zig 2023-10-05 20:04:07.186102649 +0200 +++ answers/076_sentinels.zig 2024-09-02 19:26:15.709134934 +0200
@@ -82,7 +82,7 @@ @@ -82,7 +82,7 @@
print("Array:", .{}); print("Array:", .{});

View file

@ -1,11 +1,11 @@
--- exercises/082_anonymous_structs3.zig 2023-10-03 22:15:22.125574535 +0200 --- exercises/082_anonymous_structs3.zig 2024-08-04 15:57:16.753494020 +0200
+++ answers/082_anonymous_structs3.zig 2023-10-05 20:04:07.212769813 +0200 +++ answers/082_anonymous_structs3.zig 2024-09-02 19:30:00.967005314 +0200
@@ -82,14 +82,14 @@ @@ -82,14 +82,14 @@
// @typeInfo(Circle).Struct.fields // @typeInfo(Circle).Struct.fields
// //
// This will be an array of StructFields. // This will be an array of StructFields.
- const fields = ???; - const fields = ???;
+ const fields = @typeInfo(@TypeOf(tuple)).Struct.fields; + const fields = @typeInfo(@TypeOf(tuple)).@"struct".fields;
// 2. Loop through each field. This must be done at compile // 2. Loop through each field. This must be done at compile
// time. // time.