Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIx return variables shadowing compact AST #1912

Merged
merged 1 commit into from
May 15, 2023

Conversation

smonicas
Copy link
Contributor

Fix #1867 for compact AST.
When applying the same fix to the legacy AST case strange things start happening and i'm not sure it's worth to try to fix it since it's discontinued.

contract T {
 function a() public {
    if (2>1){
       (uint aa, uint bb) = b();
       uint tot = aa+bb;
    }
    if (2<1){
     (uint aa, uint bb) = b();
     uint tot2 = aa+bb;
    }
  }
  function b() internal returns(uint,uint) {return(2,3); }
}

Before

...
		Expression: 2 < 1
		IRs:
			TMP_2(bool) = 2 < 1
			CONDITION TMP_2
		Expression: (aa,bb) = b()
		IRs:
			TUPLE_1(uint256,uint256) = INTERNAL_CALL, T.b()()
			aa(uint256)= UNPACK TUPLE_1 index: 0 
			bb(uint256)= UNPACK TUPLE_1 index: 1 
		Expression: tot2 = aa_scope_0 + bb_scope_1
		IRs:
			TMP_3(uint256) = aa_scope_0 + bb_scope_1
			tot2(uint256) := TMP_3(uint256)

After

...
		Expression: 2 < 1
		IRs:
			TMP_2(bool) = 2 < 1
			CONDITION TMP_2
		Expression: (aa_scope_0,bb_scope_1) = b()
		IRs:
			TUPLE_1(uint256,uint256) = INTERNAL_CALL, T.b()()
			aa_scope_0(uint256)= UNPACK TUPLE_1 index: 0 
			bb_scope_1(uint256)= UNPACK TUPLE_1 index: 1 
		Expression: tot2 = aa_scope_0 + bb_scope_1
		IRs:
			TMP_3(uint256) = aa_scope_0 + bb_scope_1
			tot2(uint256) := TMP_3(uint256)

Slithir for the example in the referenced issue

INFO:Printers:Contract Foo
	Function Foo.foo4(uint256) (*)
Contract T
	Function T.a(Foo) (*)
		Expression: (bb_scope_0) = bb.foo4(342)
		IRs:
			TUPLE_0(uint256,uint256,uint256,uint256) = HIGH_LEVEL_CALL, dest:bb(Foo), function:foo4, arguments:['342']  
			bb_scope_0(uint256)= UNPACK TUPLE_0 index: 1 
	Function T.b(Foo) (*)
		Expression: (bb_scope_0,cc) = bb.foo4(342)
		IRs:
			TUPLE_1(uint256,uint256,uint256,uint256) = HIGH_LEVEL_CALL, dest:bb(Foo), function:foo4, arguments:['342']  
			bb_scope_0(uint256)= UNPACK TUPLE_1 index: 1 
			cc(uint256)= UNPACK TUPLE_1 index: 2 

@0xalpharush
Copy link
Contributor

related #1533

@montyly
Copy link
Member

montyly commented May 15, 2023

I agree, we can discard the fix for the legacy AST

@montyly montyly merged commit 671dd29 into dev May 15, 2023
@montyly montyly deleted the fix-return-variables-shadowing branch May 15, 2023 12:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants