From b1da36ecde4fecfaf25fd0ab8a39032ebcf60cae Mon Sep 17 00:00:00 2001 From: Jakub Doka Date: Fri, 25 Oct 2024 15:45:00 +0200 Subject: [PATCH] fixing upcasting signed to unsigned --- lang/README.md | 5 +++++ lang/src/lib.rs | 1 + lang/src/son.rs | 1 + lang/tests/son_tests_signed_to_unsigned_upcast.txt | 0 4 files changed, 7 insertions(+) create mode 100644 lang/tests/son_tests_signed_to_unsigned_upcast.txt diff --git a/lang/README.md b/lang/README.md index af33de8..038f065 100644 --- a/lang/README.md +++ b/lang/README.md @@ -842,6 +842,11 @@ integer_range := fn(min: uint, max: uint): uint { } ``` +#### signed_to_unsigned_upcast +```hb +main := fn(): uint return @as(i32, 1) +``` + #### writing_into_string ```hb outl := fn(): void { diff --git a/lang/src/lib.rs b/lang/src/lib.rs index a1b344c..e0dc1d1 100644 --- a/lang/src/lib.rs +++ b/lang/src/lib.rs @@ -434,6 +434,7 @@ mod ty { _ if oa.is_pointer() && ob.is_pointer() => return None, _ if a.is_signed() && b.is_signed() || a.is_unsigned() && b.is_unsigned() => ob, _ if a.is_unsigned() && b.is_signed() && a.repr() - U8 < b.repr() - I8 => ob, + _ if a.is_unsigned() && b.is_signed() && a.repr() - U8 > b.repr() - I8 => oa, _ if oa.is_integer() && ob.is_pointer() && kind == TyCheck::BinOp => ob, _ => return None, }) diff --git a/lang/src/son.rs b/lang/src/son.rs index 46fb4e1..31bb182 100644 --- a/lang/src/son.rs +++ b/lang/src/son.rs @@ -4435,6 +4435,7 @@ mod tests { small_struct_assignment; intcast_store; string_flip; + signed_to_unsigned_upcast; wide_ret; comptime_min_reg_leak; different_types; diff --git a/lang/tests/son_tests_signed_to_unsigned_upcast.txt b/lang/tests/son_tests_signed_to_unsigned_upcast.txt new file mode 100644 index 0000000..e69de29