mirror of
				https://github.com/ethereum/solidity
				synced 2023-10-03 13:03:40 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			37 lines
		
	
	
		
			644 B
		
	
	
	
		
			Solidity
		
	
	
	
	
	
			
		
		
	
	
			37 lines
		
	
	
		
			644 B
		
	
	
	
		
			Solidity
		
	
	
	
	
	
| // This tests a swap in storage which does not work as one
 | |
| // might expect because we do not have temporary storage.
 | |
| // (x, y) = (y, x) is the same as
 | |
| // y = x;
 | |
| // x = y;
 | |
| contract c {
 | |
|     struct S {
 | |
|         uint256 a;
 | |
|         uint256 b;
 | |
|     }
 | |
|     S public x;
 | |
|     S public y;
 | |
| 
 | |
|     function set() public {
 | |
|         x.a = 1;
 | |
|         x.b = 2;
 | |
|         y.a = 3;
 | |
|         y.b = 4;
 | |
|     }
 | |
| 
 | |
|     function swap() public {
 | |
|         (x, y) = (y, x);
 | |
|     }
 | |
| }
 | |
| // ----
 | |
| // x() -> 0, 0
 | |
| // y() -> 0, 0
 | |
| // set() ->
 | |
| // gas irOptimized: 109690
 | |
| // gas legacy: 109728
 | |
| // gas legacyOptimized: 109680
 | |
| // x() -> 1, 2
 | |
| // y() -> 3, 4
 | |
| // swap() ->
 | |
| // x() -> 1, 2
 | |
| // y() -> 1, 2
 |