NEWTON
Asked
5 months ago
25
views
0
I have the following code:
from starkware.cairo.common.uint256 import Uint256
func main():
test()
return()
end
func test() -> (res : felt):
alloc_locals
local a : Uint256 = Uint256(low=1, high=0)
if 1 == 1:
local a : Uint256 = Uint256(low=2, high=0)
end
return (res = a)
end
But I keep getting Error: code:20:19: Reference 'a' was revoked.
return (res = a)
^
What is a good pattern for solving this issue?
ㅤ This question was originally posted on Triality
0
You can make the dynamic variable in the conditional a felt and use the following pattern:
Hopefully there will be some updates to the language in the future though, so this won't be an issue
from starkware.cairo.common.uint256 import Uint256
func main():
test()
return()
end
func test() -> (res : felt):
alloc_locals
local a
if 1 == 1:
a = 2
else:
a = 3
end
local b: Uint256 = Uint256(low=a, high=0)
return (res = a)
end
ㅤ This answer was originally posted on Triality
answered
5 months ago
Cairo error "Expected expression of type 'starkware.cairo.common.uint256.Uint256' to have an address."
Fixed Point pow operation error
How do you optimize gas in Cairo with Uint256/felt?
Cairo Error: 'range_check_ptr' cannot be used as an implicit return value. Consider using a 'with' statement.
How to import uint256 in Cairo?
How can I send a Uint256 amount of ERC20 tokens from L1 to starknet? And how should I build my payload for "sendMessageToL2" to match the Uint256 format of Cairo?
Is uint256 math operators like uint256_le safe? Why do I need to use uint256_check?
How can I verify a contract on starkscan or voyager after deploying the contract
Why am I having trouble deploying my Cairo contract?
Have there been any security issues reported on the Cairo code generated from warp so far?
Is there a javascript version of StarkEx playground?
Cairo: How can i approve erc20 and transfer in the same transaction?
Revoked References exercise from Cairo-lang
Why does Starkware pedersen Hash Function split numbers in high and low bits