From f34b6aa02408cbc1483ab182592a2f8d5b0a4f9a Mon Sep 17 00:00:00 2001 From: Dave Gauer Date: Sat, 19 Mar 2022 19:38:05 -0400 Subject: [PATCH] Update sentinel type for v0.10.0 Fixes .../076_sentinels.zig:95:30: error: incompatible types: 'u32' and '?*const anyopaque': while (my_seq[i] != my_sentinel) { --- README.md | 10 ++++++++-- build.zig | 2 +- exercises/076_sentinels.zig | 7 ++++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index bf47d86..2dad36c 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ Verify the installation and build number of `zig` like so: ```bash $ zig version -0.9.0-dev.2025+xxxxxxxxx +0.10.0-dev.1427+xxxxxxxxx ``` Clone this repository with Git: @@ -62,7 +62,7 @@ $ zig build The Zig language is under very active development. In order to be current, Ziglings tracks **development** builds of the Zig compiler rather than versioned **release** builds. The last stable release was `0.8.1`, but Ziglings -needs a dev build with pre-release version "0.9.0" and a build number at least +needs a dev build with pre-release version "0.10.0" and a build number at least as high as that shown in the example version check above. It is likely that you'll download a build which is _greater_ than the minimum. @@ -80,7 +80,13 @@ about input: [no tab characters or Windows CR/LF newlines are allowed](https://github.com/ziglang/zig/issues/544). ### Version Changes +.. +./patches/healed/076_sentinels.zig:95:30: error: incompatible +types: 'u32' and '?*const anyopaque' + while (my_seq[i] != my_sentinel) { + 9 +* 2022-03-19 0.10.0-dev.1427 - method for getting sentinel of type changed * 2021-12-20 0.9.0-dev.2025 - `c_void` is now `anyopaque` * 2021-06-14 0.9.0-dev.137 - std.build.Id `.Custom` is now `.custom` * 2021-04-21 0.8.0-dev.1983 - std.fmt.format() `any` format string required diff --git a/build.zig b/build.zig index bddc9c5..8471ca7 100644 --- a/build.zig +++ b/build.zig @@ -8,7 +8,7 @@ const print = std.debug.print; // When changing this version, be sure to also update README.md in two places: // 1) Getting Started // 2) Version Changes -const needed_version = std.SemanticVersion.parse("0.9.0-dev.2025") catch unreachable; +const needed_version = std.SemanticVersion.parse("0.10.0-dev.1427") catch unreachable; const Exercise = struct { /// main_file must have the format key_name.zig. diff --git a/exercises/076_sentinels.zig b/exercises/076_sentinels.zig index 5d5f70e..6f7abae 100644 --- a/exercises/076_sentinels.zig +++ b/exercises/076_sentinels.zig @@ -39,6 +39,7 @@ // data being terminated! // const print = @import("std").debug.print; +const sentinel = @import("std").meta.sentinel; pub fn main() void { // Here's a zero-terminated array of u32 values: @@ -71,12 +72,12 @@ pub fn main() void { // complete, but there are a couple missing bits. Please fix // them! fn printSequence(my_seq: anytype) void { - const my_type = @typeInfo(@TypeOf(my_seq)); + const my_typeinfo = @typeInfo(@TypeOf(my_seq)); // The TypeInfo contained in my_type is a union. We use a // switch to handle printing the Array or Pointer fields, // depending on which type of my_seq was passed in: - switch (my_type) { + switch (my_typeinfo) { .Array => { print("Array:", .{}); @@ -87,7 +88,7 @@ fn printSequence(my_seq: anytype) void { }, .Pointer => { // Check this out - it's pretty cool: - const my_sentinel = my_type.Pointer.sentinel; + const my_sentinel = sentinel(@TypeOf(my_seq)); print("Many-item pointer:", .{}); // Loop through the items in my_seq until we hit the