From 9ee009263b7d22222244b4c6de1e8e927ef6c76d Mon Sep 17 00:00:00 2001 From: Daniel McGregor Date: Fri, 25 Oct 2024 16:04:21 +0800 Subject: [PATCH] fix: `algopy.arc4.Address` no longer allows mutations BREAKING CHANGE: modifying an `algopy.arc4.Address` will now raise an error --- examples/sizes.txt | 4 +- src/puya/ir/builder/arc4.py | 2 + test_cases/arc4_types/address.py | 5 ++- .../out/Arc4AddressContract.approval.mir | 38 +++++++------------ .../out/Arc4AddressContract.approval.teal | 15 +------- .../out/Arc4AddressContract.clear.mir | 2 +- .../out/Arc4AddressContract.clear.teal | 2 +- .../out/Arc4AddressContract.destructured.ir | 5 +-- .../arc4_types/out/Arc4AddressContract.ssa.ir | 8 ++-- .../out/Arc4AddressContract.ssa.opt_pass_1.ir | 5 +-- .../out/Arc4AddressContract.ssa.opt_pass_2.ir | 5 +-- .../out/Arc4AddressContract.ssa.opt_pass_3.ir | 5 +-- test_cases/arc4_types/out/module.awst | 4 +- .../out_O2/Arc4AddressContract.approval.teal | 7 ---- .../Arc4AddressContract.destructured.ir | 5 +-- .../Arc4AddressContract.approval.teal | 15 +++----- .../Arc4AddressContract.clear.teal | 2 +- .../Arc4AddressContract.destructured.ir | 6 +-- test_cases/arc4_types/puya.log | 15 +++----- tests/test_expected_output/arc4.test | 12 ++++++ 20 files changed, 59 insertions(+), 103 deletions(-) diff --git a/examples/sizes.txt b/examples/sizes.txt index 2fcbd621de..ed96652bee 100644 --- a/examples/sizes.txt +++ b/examples/sizes.txt @@ -6,7 +6,7 @@ application/Reference 177 167 - | 92 83 - arc4_dynamic_arrays/DynamicArray 2695 1931 - | 1733 1138 - arc4_numeric_comparisons/UIntNOrdering 1100 908 - | 786 597 - - arc4_types/Arc4Address 85 62 - | 37 18 - + arc4_types/Arc4Address 79 18 - | 34 11 - arc4_types/Arc4Arrays 623 376 - | 368 182 - arc4_types/Arc4BoolEval 751 14 - | 167 8 - arc4_types/Arc4BoolType 381 69 - | 307 46 - @@ -130,4 +130,4 @@ unssa/UnSSA 432 368 - | 241 204 - voting/VotingRoundApp 1593 1483 - | 734 649 - with_reentrancy/WithReentrancy 255 242 - | 132 122 - - Total 69200 53576 53517 | 32843 21764 21720 \ No newline at end of file + Total 69194 53532 53473 | 32840 21757 21713 \ No newline at end of file diff --git a/src/puya/ir/builder/arc4.py b/src/puya/ir/builder/arc4.py index 500a7dbb82..da09bb858d 100644 --- a/src/puya/ir/builder/arc4.py +++ b/src/puya/ir/builder/arc4.py @@ -359,6 +359,8 @@ def handle_arc4_assign( is_mutation: bool = False, ) -> Value: result: Value + if is_mutation and target.wtype.immutable: + raise CodeError("cannot modify an immutable value", source_location) match target: case awst_nodes.IndexExpression( base=awst_nodes.Expression( diff --git a/test_cases/arc4_types/address.py b/test_cases/arc4_types/address.py index 21e7ed7f3d..5d2091b22e 100644 --- a/test_cases/arc4_types/address.py +++ b/test_cases/arc4_types/address.py @@ -16,8 +16,9 @@ def approval_program(self) -> bool: some_address = arc4.Address(SOME_ADDRESS) assert some_address == SOME_ADDRESS - some_address[0] = arc4.Byte(123) - assert some_address != SOME_ADDRESS + address_copy = some_address + + assert some_address == address_copy return True def clear_state_program(self) -> bool: diff --git a/test_cases/arc4_types/out/Arc4AddressContract.approval.mir b/test_cases/arc4_types/out/Arc4AddressContract.approval.mir index 0f3746d3b6..f933628406 100644 --- a/test_cases/arc4_types/out/Arc4AddressContract.approval.mir +++ b/test_cases/arc4_types/out/Arc4AddressContract.approval.mir @@ -1,38 +1,26 @@ -// Op Stack (out) +// Op Stack (out) // test_cases.arc4_types.address.Arc4AddressContract.approval_program() -> uint64: main_block@0: // arc4_types/address.py:8 // address = arc4.Address(Txn.sender) - txn Sender address#0 + txn Sender address#0 // arc4_types/address.py:9 // assert address == Txn.sender - txn Sender address#0,tmp%0#0 - l-load-copy address#0 1 address#0,tmp%0#0,address#0 (copy) - l-load tmp%0#0 1 address#0,address#0 (copy),tmp%0#0 - == address#0,tmp%1#0 - assert address#0 + txn Sender address#0,tmp%0#0 + l-load-copy address#0 1 address#0,tmp%0#0,address#0 (copy) + l-load tmp%0#0 1 address#0,address#0 (copy),tmp%0#0 + == address#0,tmp%1#0 + assert address#0 // arc4_types/address.py:11 // assert address.native == Txn.sender - txn Sender address#0,tmp%3#0 - l-load address#0 1 tmp%3#0,address#0 - l-load tmp%3#0 1 address#0,tmp%3#0 - == tmp%4#0 + txn Sender address#0,tmp%3#0 + l-load address#0 1 tmp%3#0,address#0 + l-load tmp%3#0 1 address#0,tmp%3#0 + == tmp%4#0 assert - // arc4_types/address.py:16 - // some_address = arc4.Address(SOME_ADDRESS) - addr "VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA" Address(VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA) - // arc4_types/address.py:19 - // some_address[0] = arc4.Byte(123) - byte 0x7b Address(VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA),0x7b - replace2 0 some_address#1 - // arc4_types/address.py:20 - // assert some_address != SOME_ADDRESS - addr "VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA" some_address#1,Address(VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA) - != tmp%10#0 - assert - // arc4_types/address.py:21 + // arc4_types/address.py:22 // return True - int 1 1 + int 1 1 return diff --git a/test_cases/arc4_types/out/Arc4AddressContract.approval.teal b/test_cases/arc4_types/out/Arc4AddressContract.approval.teal index 959e802b42..451ea1b8d4 100644 --- a/test_cases/arc4_types/out/Arc4AddressContract.approval.teal +++ b/test_cases/arc4_types/out/Arc4AddressContract.approval.teal @@ -1,7 +1,6 @@ #pragma version 10 test_cases.arc4_types.address.Arc4AddressContract.approval_program: - bytecblock base32(VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJPQ) // arc4_types/address.py:8 // address = arc4.Address(Txn.sender) txn Sender @@ -15,19 +14,7 @@ test_cases.arc4_types.address.Arc4AddressContract.approval_program: txn Sender == assert - // arc4_types/address.py:16 - // some_address = arc4.Address(SOME_ADDRESS) - bytec_0 // addr VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA - // arc4_types/address.py:19 - // some_address[0] = arc4.Byte(123) - pushbytes 0x7b - replace2 0 - // arc4_types/address.py:20 - // assert some_address != SOME_ADDRESS - bytec_0 // addr VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA - != - assert - // arc4_types/address.py:21 + // arc4_types/address.py:22 // return True pushint 1 // 1 return diff --git a/test_cases/arc4_types/out/Arc4AddressContract.clear.mir b/test_cases/arc4_types/out/Arc4AddressContract.clear.mir index a617e4767c..00b34a80c0 100644 --- a/test_cases/arc4_types/out/Arc4AddressContract.clear.mir +++ b/test_cases/arc4_types/out/Arc4AddressContract.clear.mir @@ -1,7 +1,7 @@ // Op Stack (out) // test_cases.arc4_types.address.Arc4AddressContract.clear_state_program() -> uint64: main_block@0: - // arc4_types/address.py:24 + // arc4_types/address.py:25 // return True int 1 1 return diff --git a/test_cases/arc4_types/out/Arc4AddressContract.clear.teal b/test_cases/arc4_types/out/Arc4AddressContract.clear.teal index 44682ccdec..bceb68f932 100644 --- a/test_cases/arc4_types/out/Arc4AddressContract.clear.teal +++ b/test_cases/arc4_types/out/Arc4AddressContract.clear.teal @@ -1,7 +1,7 @@ #pragma version 10 test_cases.arc4_types.address.Arc4AddressContract.clear_state_program: - // arc4_types/address.py:24 + // arc4_types/address.py:25 // return True pushint 1 // 1 return diff --git a/test_cases/arc4_types/out/Arc4AddressContract.destructured.ir b/test_cases/arc4_types/out/Arc4AddressContract.destructured.ir index 69f5037197..449a01096d 100644 --- a/test_cases/arc4_types/out/Arc4AddressContract.destructured.ir +++ b/test_cases/arc4_types/out/Arc4AddressContract.destructured.ir @@ -9,12 +9,9 @@ contract test_cases.arc4_types.address.Arc4AddressContract: let tmp%3#0: bytes = (txn Sender) let tmp%4#0: bool = (== address#0 tmp%3#0) (assert tmp%4#0) - let some_address#1: bytes = ((replace2 0) addr VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA 0x7b) - let tmp%10#0: bool = (!= some_address#1 addr VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA) - (assert tmp%10#0) return 1u program clear-state: subroutine test_cases.arc4_types.address.Arc4AddressContract.clear_state_program() -> bool: - block@0: // L23 + block@0: // L24 return 1u \ No newline at end of file diff --git a/test_cases/arc4_types/out/Arc4AddressContract.ssa.ir b/test_cases/arc4_types/out/Arc4AddressContract.ssa.ir index 6cfafe18dd..8ad95b7e51 100644 --- a/test_cases/arc4_types/out/Arc4AddressContract.ssa.ir +++ b/test_cases/arc4_types/out/Arc4AddressContract.ssa.ir @@ -22,14 +22,12 @@ contract test_cases.arc4_types.address.Arc4AddressContract: let some_address#0: bytes = addr VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA let tmp%9#0: bool = (== some_address#0 addr VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA) (assert tmp%9#0) - let assigned_value%0#0: bytes = 0x7b - let updated_target%0#0: bytes = (replace3 some_address#0 0u assigned_value%0#0) - let some_address#1: bytes = updated_target%0#0 - let tmp%10#0: bool = (!= some_address#1 addr VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA) + let address_copy#0: bytes = some_address#0 + let tmp%10#0: bool = (== some_address#0 address_copy#0) (assert tmp%10#0) return 1u program clear-state: subroutine test_cases.arc4_types.address.Arc4AddressContract.clear_state_program() -> bool: - block@0: // L23 + block@0: // L24 return 1u \ No newline at end of file diff --git a/test_cases/arc4_types/out/Arc4AddressContract.ssa.opt_pass_1.ir b/test_cases/arc4_types/out/Arc4AddressContract.ssa.opt_pass_1.ir index de8bb9806e..379a195d88 100644 --- a/test_cases/arc4_types/out/Arc4AddressContract.ssa.opt_pass_1.ir +++ b/test_cases/arc4_types/out/Arc4AddressContract.ssa.opt_pass_1.ir @@ -18,12 +18,11 @@ contract test_cases.arc4_types.address.Arc4AddressContract: (assert tmp%8#0) let tmp%9#0: bool = 1u (assert tmp%9#0) - let some_address#1: bytes = ((replace2 0) addr VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA 0x7b) - let tmp%10#0: bool = (!= some_address#1 addr VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA) + let tmp%10#0: bool = 1u (assert tmp%10#0) return 1u program clear-state: subroutine test_cases.arc4_types.address.Arc4AddressContract.clear_state_program() -> bool: - block@0: // L23 + block@0: // L24 return 1u \ No newline at end of file diff --git a/test_cases/arc4_types/out/Arc4AddressContract.ssa.opt_pass_2.ir b/test_cases/arc4_types/out/Arc4AddressContract.ssa.opt_pass_2.ir index 64b03c8f30..3ca51517de 100644 --- a/test_cases/arc4_types/out/Arc4AddressContract.ssa.opt_pass_2.ir +++ b/test_cases/arc4_types/out/Arc4AddressContract.ssa.opt_pass_2.ir @@ -11,12 +11,9 @@ contract test_cases.arc4_types.address.Arc4AddressContract: (assert tmp%4#0) let tmp%6#0: bool = 1u (assert tmp%6#0) // Address length is 32 bytes - let some_address#1: bytes = ((replace2 0) addr VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA 0x7b) - let tmp%10#0: bool = (!= some_address#1 addr VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA) - (assert tmp%10#0) return 1u program clear-state: subroutine test_cases.arc4_types.address.Arc4AddressContract.clear_state_program() -> bool: - block@0: // L23 + block@0: // L24 return 1u \ No newline at end of file diff --git a/test_cases/arc4_types/out/Arc4AddressContract.ssa.opt_pass_3.ir b/test_cases/arc4_types/out/Arc4AddressContract.ssa.opt_pass_3.ir index 69f5037197..449a01096d 100644 --- a/test_cases/arc4_types/out/Arc4AddressContract.ssa.opt_pass_3.ir +++ b/test_cases/arc4_types/out/Arc4AddressContract.ssa.opt_pass_3.ir @@ -9,12 +9,9 @@ contract test_cases.arc4_types.address.Arc4AddressContract: let tmp%3#0: bytes = (txn Sender) let tmp%4#0: bool = (== address#0 tmp%3#0) (assert tmp%4#0) - let some_address#1: bytes = ((replace2 0) addr VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA 0x7b) - let tmp%10#0: bool = (!= some_address#1 addr VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA) - (assert tmp%10#0) return 1u program clear-state: subroutine test_cases.arc4_types.address.Arc4AddressContract.clear_state_program() -> bool: - block@0: // L23 + block@0: // L24 return 1u \ No newline at end of file diff --git a/test_cases/arc4_types/out/module.awst b/test_cases/arc4_types/out/module.awst index d55add56f1..faa7de9217 100644 --- a/test_cases/arc4_types/out/module.awst +++ b/test_cases/arc4_types/out/module.awst @@ -667,8 +667,8 @@ contract Arc4AddressContract assert(reinterpret_cast(zero_address) == reinterpret_cast(global())) some_address: arc4.static_array = Address("VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA") assert(some_address == Address("VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA")) - some_address[0u]: arc4.uint8 = 123_arc4u8 - assert(some_address != Address("VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA")) + address_copy: arc4.static_array = some_address + assert(some_address == address_copy) return true } diff --git a/test_cases/arc4_types/out_O2/Arc4AddressContract.approval.teal b/test_cases/arc4_types/out_O2/Arc4AddressContract.approval.teal index e360de973d..b73ae54d6e 100644 --- a/test_cases/arc4_types/out_O2/Arc4AddressContract.approval.teal +++ b/test_cases/arc4_types/out_O2/Arc4AddressContract.approval.teal @@ -1,7 +1,6 @@ #pragma version 10 test_cases.arc4_types.address.Arc4AddressContract.approval_program: - bytecblock base32(VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJPQ) txn Sender dupn 2 == @@ -9,11 +8,5 @@ test_cases.arc4_types.address.Arc4AddressContract.approval_program: txn Sender == assert - bytec_0 // addr VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA - pushbytes 0x7b - replace2 0 - bytec_0 // addr VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA - != - assert pushint 1 // 1 return diff --git a/test_cases/arc4_types/out_O2/Arc4AddressContract.destructured.ir b/test_cases/arc4_types/out_O2/Arc4AddressContract.destructured.ir index 69f5037197..449a01096d 100644 --- a/test_cases/arc4_types/out_O2/Arc4AddressContract.destructured.ir +++ b/test_cases/arc4_types/out_O2/Arc4AddressContract.destructured.ir @@ -9,12 +9,9 @@ contract test_cases.arc4_types.address.Arc4AddressContract: let tmp%3#0: bytes = (txn Sender) let tmp%4#0: bool = (== address#0 tmp%3#0) (assert tmp%4#0) - let some_address#1: bytes = ((replace2 0) addr VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA 0x7b) - let tmp%10#0: bool = (!= some_address#1 addr VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA) - (assert tmp%10#0) return 1u program clear-state: subroutine test_cases.arc4_types.address.Arc4AddressContract.clear_state_program() -> bool: - block@0: // L23 + block@0: // L24 return 1u \ No newline at end of file diff --git a/test_cases/arc4_types/out_unoptimized/Arc4AddressContract.approval.teal b/test_cases/arc4_types/out_unoptimized/Arc4AddressContract.approval.teal index e8aa79bb57..fbfaa2cc70 100644 --- a/test_cases/arc4_types/out_unoptimized/Arc4AddressContract.approval.teal +++ b/test_cases/arc4_types/out_unoptimized/Arc4AddressContract.approval.teal @@ -46,17 +46,12 @@ test_cases.arc4_types.address.Arc4AddressContract.approval_program: // arc4_types/address.py:16 // some_address = arc4.Address(SOME_ADDRESS) bytec_0 // addr VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA - // arc4_types/address.py:19 - // some_address[0] = arc4.Byte(123) - pushint 0 // 0 - pushbytes 0x7b - replace3 - // arc4_types/address.py:20 - // assert some_address != SOME_ADDRESS - bytec_0 // addr VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA - != - assert + dup // arc4_types/address.py:21 + // assert some_address == address_copy + == + assert + // arc4_types/address.py:22 // return True pushint 1 // 1 return diff --git a/test_cases/arc4_types/out_unoptimized/Arc4AddressContract.clear.teal b/test_cases/arc4_types/out_unoptimized/Arc4AddressContract.clear.teal index 44682ccdec..bceb68f932 100644 --- a/test_cases/arc4_types/out_unoptimized/Arc4AddressContract.clear.teal +++ b/test_cases/arc4_types/out_unoptimized/Arc4AddressContract.clear.teal @@ -1,7 +1,7 @@ #pragma version 10 test_cases.arc4_types.address.Arc4AddressContract.clear_state_program: - // arc4_types/address.py:24 + // arc4_types/address.py:25 // return True pushint 1 // 1 return diff --git a/test_cases/arc4_types/out_unoptimized/Arc4AddressContract.destructured.ir b/test_cases/arc4_types/out_unoptimized/Arc4AddressContract.destructured.ir index 3cb5fe1ef4..71d579d225 100644 --- a/test_cases/arc4_types/out_unoptimized/Arc4AddressContract.destructured.ir +++ b/test_cases/arc4_types/out_unoptimized/Arc4AddressContract.destructured.ir @@ -21,13 +21,11 @@ contract test_cases.arc4_types.address.Arc4AddressContract: (assert tmp%8#0) let tmp%9#0: bool = (== addr VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA addr VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA) (assert tmp%9#0) - let updated_target%0#0: bytes = (replace3 addr VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA 0u 0x7b) - let some_address#1: bytes = updated_target%0#0 - let tmp%10#0: bool = (!= some_address#1 addr VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA) + let tmp%10#0: bool = (== addr VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA addr VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA) (assert tmp%10#0) return 1u program clear-state: subroutine test_cases.arc4_types.address.Arc4AddressContract.clear_state_program() -> bool: - block@0: // L23 + block@0: // L24 return 1u \ No newline at end of file diff --git a/test_cases/arc4_types/puya.log b/test_cases/arc4_types/puya.log index 3f8265139b..17157a5a81 100644 --- a/test_cases/arc4_types/puya.log +++ b/test_cases/arc4_types/puya.log @@ -982,8 +982,8 @@ debug: Sealing block@3: // after_if_else_L6 debug: Terminated block@3: // after_if_else_L6 debug: Sealing block@0: // L7 debug: Terminated block@0: // L7 -debug: Sealing block@0: // L23 -debug: Terminated block@0: // L23 +debug: Sealing block@0: // L24 +debug: Terminated block@0: // L24 debug: Sealing block@0: // L6 debug: Terminated block@0: // L6 debug: Sealing block@1: // abi_routing_L6 @@ -18665,19 +18665,17 @@ debug: Optimizer: Constant Replacer debug: Optimizer: Copy Propagation debug: Found equivalence set: awst_tmp%0#0, zero_address#0 debug: Replacing {awst_tmp%0#0} with zero_address#0 made 2 modifications -debug: Found equivalence set: updated_target%0#0, some_address#1 -debug: Replacing {updated_target%0#0} with some_address#1 made 1 modifications debug: Optimizer: Intrinsic Simplifier debug: Simplified (== 32u 32u) to 1u debug: Simplified (len zero_address#0) to 32u debug: Simplified (== zero_address#0 tmp%7#0) to 1u debug: Simplified (== addr VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA addr VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA) to 1u -debug: Simplified (replace3 addr VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA 0u 0x7b) to ((replace2 0) addr VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA 0x7b) +debug: Simplified (== addr VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA addr VCMJKWOY5P5P7SKMZFFOCEROPJCZOTIJMNIYNUCKH7LRO45JMJP6UYBIJA) to 1u debug: Optimizer: Remove Unused Variables debug: Removing unused variable zero_address#0 debug: Removing unused variable tmp%7#0 debug: Removing unused variable some_address#0 -debug: Removing unused variable assigned_value%0#0 +debug: Removing unused variable address_copy#0 debug: Optimizer: Inner Txn Field Replacer debug: Optimizer: Replace Compiled References debug: Optimizer: Simplify Control Ops @@ -18712,6 +18710,7 @@ debug: Removing unused variable tmp%2#0 debug: Removing unused variable tmp%5#0 debug: Removing unused variable tmp%8#0 debug: Removing unused variable tmp%9#0 +debug: Removing unused variable tmp%10#0 debug: Optimizer: Inner Txn Field Replacer debug: Optimizer: Replace Compiled References debug: Optimizer: Simplify Control Ops @@ -18805,10 +18804,6 @@ debug: Inserted main_block@0.ops[7]: 'l-store-copy tmp%1#0 0' debug: Replaced main_block@0.ops[9]: 'v-load tmp%1#0' with 'l-load tmp%1#0' debug: Inserted main_block@0.ops[16]: 'l-store-copy tmp%4#0 0' debug: Replaced main_block@0.ops[18]: 'v-load tmp%4#0' with 'l-load tmp%4#0' -debug: Inserted main_block@0.ops[23]: 'l-store-copy some_address#1 0' -debug: Replaced main_block@0.ops[25]: 'v-load some_address#1' with 'l-load some_address#1' -debug: Inserted main_block@0.ops[28]: 'l-store-copy tmp%10#0 0' -debug: Replaced main_block@0.ops[30]: 'v-load tmp%10#0' with 'l-load tmp%10#0' debug: Inserted main_block@0.ops[3]: 'l-store-copy tmp%0#0 0' debug: Replaced main_block@0.ops[6]: 'v-load tmp%0#0' with 'l-load tmp%0#0' debug: Inserted main_block@0.ops[13]: 'l-store-copy tmp%3#0 0' diff --git a/tests/test_expected_output/arc4.test b/tests/test_expected_output/arc4.test index 3ef33845b1..8bceb74b32 100644 --- a/tests/test_expected_output/arc4.test +++ b/tests/test_expected_output/arc4.test @@ -541,3 +541,15 @@ def constant_bool() -> None: assert MyStruct(x=arc4.UInt512(0)) ## E: expression is always True assert arc4.Tuple((arc4.Bool(False),)) ## E: expression is always True + +## case: test_address_immutable +from algopy import * + +class MyTest(ARC4Contract): + @arc4.abimethod + def test(self) -> None: + some_address = arc4.Address() + + this_is_ok = some_address[0] + assert this_is_ok == 0 + some_address[0] = arc4.Byte(123) ## E: cannot modify an immutable value