diff --git a/sway-core/src/semantic_analysis/ast_node/expression/intrinsic_function.rs b/sway-core/src/semantic_analysis/ast_node/expression/intrinsic_function.rs index cac9a64521e..fb2d698aa86 100644 --- a/sway-core/src/semantic_analysis/ast_node/expression/intrinsic_function.rs +++ b/sway-core/src/semantic_analysis/ast_node/expression/intrinsic_function.rs @@ -587,7 +587,10 @@ impl ty::TyIntrinsicFunctionKind { warnings, errors ); - let is_valid_arg_ty = matches!(arg_ty, TypeInfo::UnsignedInteger(_)); + let is_valid_arg_ty = matches!( + arg_ty, + TypeInfo::UnsignedInteger(_) | TypeInfo::RawUntypedPtr + ); if !is_valid_arg_ty { errors.push(CompileError::IntrinsicUnsupportedArgType { name: kind.to_string(), @@ -601,7 +604,13 @@ impl ty::TyIntrinsicFunctionKind { let ctx = ctx .by_ref() .with_help_text("Incorrect argument type") - .with_type_annotation(lhs.return_type); + .with_type_annotation(match arg_ty { + // Expect a u64 at the RHS if the LHS is a raw_ptr + TypeInfo::RawUntypedPtr => { + insert_type(TypeInfo::UnsignedInteger(IntegerBits::SixtyFour)) + } + _ => lhs.return_type, + }); let rhs = check!( ty::TyExpression::type_check(ctx, rhs), return err(warnings, errors), diff --git a/sway-lib-core/src/raw_ptr.sw b/sway-lib-core/src/raw_ptr.sw index 3c2d022aeb2..365677c101f 100644 --- a/sway-lib-core/src/raw_ptr.sw +++ b/sway-lib-core/src/raw_ptr.sw @@ -3,8 +3,8 @@ library raw_ptr; impl raw_ptr { /// Returns `true` if the pointer is null. pub fn is_null(self) -> bool { - let addr = asm(ptr: self) { ptr: u64 }; - __eq(addr, 0) + let null_ptr = asm() { zero: raw_ptr }; + __eq(self, null_ptr) } /// Gets the address of the pointer. @@ -14,16 +14,12 @@ impl raw_ptr { /// Calculates the offset from the pointer. pub fn add(self, count: u64) -> raw_ptr { - let addr = asm(ptr: self) { ptr: u64 }; - let addr = __add(addr, count); - asm(ptr: addr) { ptr: raw_ptr } + __add(self, count) } /// Calculates the offset from the pointer. pub fn sub(self, count: u64) -> raw_ptr { - let addr = asm(ptr: self) { ptr: u64 }; - let addr = __sub(addr, count); - asm(ptr: addr) { ptr: raw_ptr } + __sub(self, count) } /// Reads the given type of value from the address. @@ -37,7 +33,7 @@ impl raw_ptr { } } } - + /// Copies `size` bytes from `self` to `dst`. pub fn copy_to(self, dst: raw_ptr, count: u64) { asm(dst: dst, src: self, count: count) { diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_basic_storage/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_basic_storage/src/main.sw index 4cdd431d884..8c8854b20f4 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_basic_storage/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_basic_storage/src/main.sw @@ -3,7 +3,7 @@ use basic_storage_abi::{StoreU64, Quad}; use std::assert::assert; fn main() -> u64 { - let addr = abi(StoreU64, 0x5c452aa39ace5925513ac6a078eee827fc78245258c71ed9851ffe2251719b9d); + let addr = abi(StoreU64, 0x4a70196dbef39aeddf4fff88a2d9e54591d8743da0154649bd298cf86cc12c6f); let key = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff; let value = 4242;