mirror of
				https://github.com/ethereum/solidity
				synced 2023-10-03 13:03:40 +00:00 
			
		
		
		
	Merge pull request #5030 from ethereum/payableConversion
Make non-payable default for conversion to address.
This commit is contained in:
		
						commit
						dc9853bb6e
					
				| @ -1778,9 +1778,7 @@ bool TypeChecker::visit(FunctionCall const& _functionCall) | ||||
| 			} | ||||
| 			if (resultType->category() == Type::Category::Address) | ||||
| 			{ | ||||
| 				bool payable = true; | ||||
| 				if (auto const* contractType = dynamic_cast<ContractType const*>(argType.get())) | ||||
| 					payable = contractType->isPayable(); | ||||
| 				bool payable = argType->isExplicitlyConvertibleTo(AddressType::addressPayable()); | ||||
| 				resultType = make_shared<AddressType>(payable ? StateMutability::Payable : StateMutability::NonPayable); | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| @ -2641,8 +2641,8 @@ bool FunctionType::operator==(Type const& _other) const | ||||
| 
 | ||||
| bool FunctionType::isExplicitlyConvertibleTo(Type const& _convertTo) const | ||||
| { | ||||
| 	if (m_kind == Kind::External && _convertTo.category() == Category::Address) | ||||
| 			return true; | ||||
| 	if (m_kind == Kind::External && _convertTo == AddressType::address()) | ||||
| 		return true; | ||||
| 	return _convertTo.category() == category(); | ||||
| } | ||||
| 
 | ||||
|  | ||||
| @ -0,0 +1,7 @@ | ||||
| contract C { | ||||
|     function f() public view returns (address payable) { | ||||
|         return address(this.f); | ||||
|     } | ||||
| } | ||||
| // ---- | ||||
| // TypeError: (85-100): Return argument type address is not implicitly convertible to expected type (type of first return variable) address payable. | ||||
| @ -0,0 +1,7 @@ | ||||
| contract C { | ||||
|     function f(address a) public pure returns (address payable) { | ||||
|         return address(address(a)); | ||||
|     } | ||||
| } | ||||
| // ---- | ||||
| // TypeError: (94-113): Return argument type address is not implicitly convertible to expected type (type of first return variable) address payable. | ||||
| @ -0,0 +1,8 @@ | ||||
| contract C { | ||||
|     function f(bytes32 x) public pure returns (address payable) { | ||||
|         return address(x); | ||||
|     } | ||||
| } | ||||
| // ---- | ||||
| // TypeError: (94-104): Explicit type conversion not allowed from "bytes32" to "address". | ||||
| // TypeError: (94-104): Return argument type address is not implicitly convertible to expected type (type of first return variable) address payable. | ||||
| @ -0,0 +1,8 @@ | ||||
| contract C { | ||||
|     function f(bytes10 x) public pure returns (address payable) { | ||||
|         return address(x); | ||||
|     } | ||||
| } | ||||
| // ---- | ||||
| // TypeError: (94-104): Explicit type conversion not allowed from "bytes10" to "address". | ||||
| // TypeError: (94-104): Return argument type address is not implicitly convertible to expected type (type of first return variable) address payable. | ||||
| @ -0,0 +1,5 @@ | ||||
| contract C { | ||||
|     function f(bytes20 x) public pure returns (address payable) { | ||||
|         return address(x); | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,5 @@ | ||||
| contract C { | ||||
|     function f(uint x) public pure returns (address payable) { | ||||
|         return address(x); | ||||
|     } | ||||
| } | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user