mirror of
				https://github.com/ethereum/solidity
				synced 2023-10-03 13:03:40 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			46 lines
		
	
	
		
			919 B
		
	
	
	
		
			Solidity
		
	
	
	
	
	
			
		
		
	
	
			46 lines
		
	
	
		
			919 B
		
	
	
	
		
			Solidity
		
	
	
	
	
	
contract Test {
 | 
						|
    struct S {
 | 
						|
        uint8 x;
 | 
						|
        uint16 y;
 | 
						|
        uint256 z;
 | 
						|
    }
 | 
						|
    struct X {
 | 
						|
        uint8 x;
 | 
						|
        S s;
 | 
						|
    }
 | 
						|
 | 
						|
    function test()
 | 
						|
        public
 | 
						|
        returns (uint256 a, uint256 x, uint256 y, uint256 z)
 | 
						|
    {
 | 
						|
        X memory d = combine(1, 2, 3, 4);
 | 
						|
        a = extract(d, 0);
 | 
						|
        x = extract(d, 1);
 | 
						|
        y = extract(d, 2);
 | 
						|
        z = extract(d, 3);
 | 
						|
    }
 | 
						|
 | 
						|
    function extract(X memory s, uint256 which) internal returns (uint256 x) {
 | 
						|
        if (which == 0) return s.x;
 | 
						|
        else if (which == 1) return s.s.x;
 | 
						|
        else if (which == 2) return s.s.y;
 | 
						|
        else return s.s.z;
 | 
						|
    }
 | 
						|
 | 
						|
    function combine(uint8 a, uint8 x, uint16 y, uint256 z)
 | 
						|
        internal
 | 
						|
        returns (X memory s)
 | 
						|
    {
 | 
						|
        s.x = a;
 | 
						|
        s.s.x = x;
 | 
						|
        s.s.y = y;
 | 
						|
        s.s.z = z;
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
// ====
 | 
						|
// compileViaYul: also
 | 
						|
// compileToEwasm: also
 | 
						|
// ----
 | 
						|
// test() -> 1, 2, 3, 4
 |