Disallow conversions from literals to payable address

To get a payable address, one has to go through address. For example, `payable(address(0))`.
This commit is contained in:
hrkrshnn 2020-12-03 22:36:56 +01:00
parent 9bd778d728
commit e1a95cfd42

View File

@ -1768,7 +1768,10 @@ TypePointer TypeChecker::typeCheckTypeConversionAndRetrieveReturnType(
if (addressType->stateMutability() != StateMutability::Payable)
{
bool payable = false;
if (argType->category() != Type::Category::Address)
if (
argType->category() != Type::Category::Address &&
argType->category() != Type::Category::RationalNumber
)
payable = argType->isExplicitlyConvertibleTo(*TypeProvider::payableAddress());
resultType = payable ? TypeProvider::payableAddress() : TypeProvider::address();
}
@ -3314,7 +3317,7 @@ void TypeChecker::endVisit(Literal const& _literal)
if (_literal.looksLikeAddress())
{
// Assign type here if it even looks like an address. This prevents double errors for invalid addresses
_literal.annotation().type = TypeProvider::payableAddress();
_literal.annotation().type = TypeProvider::address();
string msg;
if (_literal.valueWithoutUnderscores().length() != 42) // "0x" + 40 hex digits