From 191c49ff1d0b7d9186d0df089bfebb63f9db8b16 Mon Sep 17 00:00:00 2001 From: peony Date: Sun, 3 Nov 2024 15:58:42 +0100 Subject: [PATCH] Made sure `null_check_test` reproduces exact issue. --- lang/README.md | 15 ++++++++++----- lang/tests/son_tests_inlining_loops.txt | 8 ++++++++ lang/tests/son_tests_null_check_test.txt | 6 ++++++ 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/lang/README.md b/lang/README.md index a1301fe..e853f92 100644 --- a/lang/README.md +++ b/lang/README.md @@ -1059,16 +1059,21 @@ main := fn(): uint { #### null_check_test ```hb -main := fn(): uint { - ptr := @as(?^uint, null) +get_ptr := fn(): ?^uint { value := 0 - ptr = &value + return &value +} + +main := fn(): void { + ptr := get_ptr() if ptr == null { - return 1 + return } - return *ptr + loop { + *ptr += 1 + } } ``` diff --git a/lang/tests/son_tests_inlining_loops.txt b/lang/tests/son_tests_inlining_loops.txt index e69de29..f02533a 100644 --- a/lang/tests/son_tests_inlining_loops.txt +++ b/lang/tests/son_tests_inlining_loops.txt @@ -0,0 +1,8 @@ +main: + LRA r2, r0, :x + LI64 r1, 0d + ST r1, r2, 0a, 8h + JALA r0, r31, 0a +code size: 57 +ret: 0 +status: Ok(()) diff --git a/lang/tests/son_tests_null_check_test.txt b/lang/tests/son_tests_null_check_test.txt index e69de29..c9727f8 100644 --- a/lang/tests/son_tests_null_check_test.txt +++ b/lang/tests/son_tests_null_check_test.txt @@ -0,0 +1,6 @@ +test.hb:15:4: can't prove the value is not 'null', use '@unwrap()' if you believe compiler is stupid, or explicitly check for null and handle it ('if == null { /* handle */ } else { /* use opt */ }') + *ptr += 1 + ^ +test.hb:15:4: can't prove the value is not 'null', use '@unwrap()' if you believe compiler is stupid, or explicitly check for null and handle it ('if == null { /* handle */ } else { /* use opt */ }') + *ptr += 1 + ^