mirror of
				https://github.com/ethereum/solidity
				synced 2023-10-03 13:03:40 +00:00 
			
		
		
		
	Adding more tests for function types
This commit is contained in:
		
							parent
							
								
									e7d5a7da10
								
							
						
					
					
						commit
						a1da90d14b
					
				| @ -6,5 +6,7 @@ contract C { | ||||
|         return (false ? g : h)(2, 1); | ||||
|     } | ||||
| } | ||||
| // ==== | ||||
| // compileViaYul: also | ||||
| // ---- | ||||
| // f() -> 1 | ||||
|  | ||||
| @ -0,0 +1,10 @@ | ||||
| contract C { | ||||
|     function f() external payable returns (uint) { assert(msg.value > 0); return 1; } | ||||
|     function g() external payable returns (uint) { assert(msg.value > 0); return 2; } | ||||
| 
 | ||||
|     function h() public payable returns (uint) { | ||||
|         return [this.f, this.g][0]{value: 1}(); | ||||
|     } | ||||
| } | ||||
| // ---- | ||||
| // h(), 1 ether -> 1 | ||||
| @ -0,0 +1,9 @@ | ||||
| contract C { | ||||
|     function f() pure public { | ||||
|         function(uint a) returns (uint) x; | ||||
|         x({a:2}); | ||||
|     } | ||||
| } | ||||
| // ---- | ||||
| // Warning 6162: (61-67): Naming function type parameters is deprecated. | ||||
| // TypeError 4974: (95-103): Named argument "a" does not match function declaration. | ||||
| @ -0,0 +1,13 @@ | ||||
| library L { | ||||
|     function f(uint a) internal pure {} | ||||
|     function g(uint a) internal pure {} | ||||
| } | ||||
| contract C { | ||||
|     using L for *; | ||||
|     function f() pure public { | ||||
|         uint t = 8; | ||||
|         [t.f, t.g][0](); | ||||
|     } | ||||
| } | ||||
| // ---- | ||||
| // TypeError 9563: (186-189): Invalid mobile type. | ||||
| @ -0,0 +1,13 @@ | ||||
| library L { | ||||
|     function f(uint a) internal pure {} | ||||
| } | ||||
| contract C { | ||||
|     using L for *; | ||||
|     function f() pure public { | ||||
|         uint t; | ||||
|         function() pure x; | ||||
|         [t.f, x][0]({a: 8}); | ||||
|     } | ||||
| } | ||||
| // ---- | ||||
| // TypeError 9563: (169-172): Invalid mobile type. | ||||
| @ -0,0 +1,13 @@ | ||||
| contract D { | ||||
|     function f(uint a) external payable {} | ||||
|     function g(uint a) external {} | ||||
| } | ||||
| 
 | ||||
| contract C { | ||||
|     function f() public { | ||||
|         D d; | ||||
|         [d.f{value: 1}, d.g][0](8); | ||||
|     } | ||||
| } | ||||
| // ---- | ||||
| // TypeError 9563: (155-168): Invalid mobile type. | ||||
| @ -0,0 +1,14 @@ | ||||
| library L { | ||||
|     function f(uint a) internal pure {} | ||||
|     function g(uint a) internal pure {} | ||||
| } | ||||
| contract C { | ||||
|     using L for *; | ||||
|     function f(bool x) pure public { | ||||
|         uint t = 8; | ||||
|         (x ? t.f : t.g)(); | ||||
|     } | ||||
| } | ||||
| // ---- | ||||
| // TypeError 9717: (196-199): Invalid mobile type in true expression. | ||||
| // TypeError 3703: (202-205): Invalid mobile type in false expression. | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user