From 1f4f9b8d66554652eeed7926e6837f851a9d1a23 Mon Sep 17 00:00:00 2001 From: Hal Ali Date: Sun, 17 Nov 2024 19:46:35 -0500 Subject: [PATCH 1/4] Update 11-pointers.mdx fix typo in code snippet. Discarding the variable should be `_ = &y;` instead of `_ = y;`. replace `var x: u16 = 0;` with `var x: u16 = 5; x -= 5;`. Else the compiler complains with `error: local variable is never mutated`. The updated example also highlights that the compiler is able to detect the value of x is not 0 through a mutation --- .../version-0.13/01-language-basics/11-pointers.mdx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/website/versioned_docs/version-0.13/01-language-basics/11-pointers.mdx b/website/versioned_docs/version-0.13/01-language-basics/11-pointers.mdx index 20c75e1..f16d11b 100644 --- a/website/versioned_docs/version-0.13/01-language-basics/11-pointers.mdx +++ b/website/versioned_docs/version-0.13/01-language-basics/11-pointers.mdx @@ -16,9 +16,10 @@ Trying to set a `*T` to the value 0 is detectable illegal behaviour. ```zig test "naughty pointer" { - var x: u16 = 0; + var x: u16 = 5; + x -= 5; var y: *u8 = @ptrFromInt(x); - _ = y; + _ = &y; } ``` From 9eac5033032c11b8d676ce8015a5e36ef25b5f3f Mon Sep 17 00:00:00 2001 From: Hal Ali Date: Sun, 17 Nov 2024 19:50:45 -0500 Subject: [PATCH 2/4] Update 11-pointers.mdx apply fix to guide for version 0.14 --- .../version-0.14/01-language-basics/11-pointers.mdx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/website/versioned_docs/version-0.14/01-language-basics/11-pointers.mdx b/website/versioned_docs/version-0.14/01-language-basics/11-pointers.mdx index 20c75e1..f16d11b 100644 --- a/website/versioned_docs/version-0.14/01-language-basics/11-pointers.mdx +++ b/website/versioned_docs/version-0.14/01-language-basics/11-pointers.mdx @@ -16,9 +16,10 @@ Trying to set a `*T` to the value 0 is detectable illegal behaviour. ```zig test "naughty pointer" { - var x: u16 = 0; + var x: u16 = 5; + x -= 5; var y: *u8 = @ptrFromInt(x); - _ = y; + _ = &y; } ``` From 128e286c2f68e7cf7f005933bec14b2baa2c40c9 Mon Sep 17 00:00:00 2001 From: Hal Ali Date: Tue, 19 Nov 2024 21:53:32 -0500 Subject: [PATCH 3/4] avoid use of `_` for discard as that might change in future --- .../version-0.14/01-language-basics/11-pointers.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/versioned_docs/version-0.14/01-language-basics/11-pointers.mdx b/website/versioned_docs/version-0.14/01-language-basics/11-pointers.mdx index f16d11b..abf5776 100644 --- a/website/versioned_docs/version-0.14/01-language-basics/11-pointers.mdx +++ b/website/versioned_docs/version-0.14/01-language-basics/11-pointers.mdx @@ -19,7 +19,7 @@ test "naughty pointer" { var x: u16 = 5; x -= 5; var y: *u8 = @ptrFromInt(x); - _ = &y; + y = y; } ``` From 73130a862e8bae091fbd2594f41e23c01c4041ac Mon Sep 17 00:00:00 2001 From: Hal Ali Date: Tue, 19 Nov 2024 21:54:05 -0500 Subject: [PATCH 4/4] avoid use of `_` for discard as that might change in future --- .../version-0.13/01-language-basics/11-pointers.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/versioned_docs/version-0.13/01-language-basics/11-pointers.mdx b/website/versioned_docs/version-0.13/01-language-basics/11-pointers.mdx index f16d11b..abf5776 100644 --- a/website/versioned_docs/version-0.13/01-language-basics/11-pointers.mdx +++ b/website/versioned_docs/version-0.13/01-language-basics/11-pointers.mdx @@ -19,7 +19,7 @@ test "naughty pointer" { var x: u16 = 5; x -= 5; var y: *u8 = @ptrFromInt(x); - _ = &y; + y = y; } ```