Merge pull request #5351 from ethereum/functionTypeConversion

Relax type equality requirement of function types during conversion in code generation.
This commit is contained in:
chriseth 2018-11-08 11:29:55 +01:00 committed by GitHub
commit 84e8a782d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 144 additions and 2 deletions

View File

@ -1016,8 +1016,22 @@ void CompilerUtils::convertType(
}
else
{
// All other types should not be convertible to non-equal types.
solAssert(_typeOnStack == _targetType, "Invalid type conversion requested.");
if (stackTypeCategory == Type::Category::Function && targetTypeCategory == Type::Category::Function)
{
FunctionType const& typeOnStack = dynamic_cast<FunctionType const&>(_typeOnStack);
FunctionType const& targetType = dynamic_cast<FunctionType const&>(_targetType);
solAssert(
typeOnStack.isImplicitlyConvertibleTo(targetType) &&
typeOnStack.sizeOnStack() == targetType.sizeOnStack() &&
(typeOnStack.kind() == FunctionType::Kind::Internal || typeOnStack.kind() == FunctionType::Kind::External) &&
typeOnStack.kind() == targetType.kind(),
"Invalid function type conversion requested."
);
}
else
// All other types should not be convertible to non-equal types.
solAssert(_typeOnStack == _targetType, "Invalid type conversion requested.");
if (_cleanupNeeded && _targetType.canBeStored() && _targetType.storageBytes() < 32)
m_context
<< ((u256(1) << (8 * _targetType.storageBytes())) - 1)

View File

@ -0,0 +1,10 @@
contract C {
function h() external {
}
function f() view external returns (bytes4) {
function () payable external g = this.h;
return g.selector;
}
}
// ----
// TypeError: (105-144): Type function () external is not implicitly convertible to expected type function () payable external.

View File

@ -0,0 +1,10 @@
contract C {
function h() external {
}
function f() view external returns (bytes4) {
function () pure external g = this.h;
return g.selector;
}
}
// ----
// TypeError: (105-141): Type function () external is not implicitly convertible to expected type function () pure external.

View File

@ -0,0 +1,10 @@
contract C {
function h() external {
}
function f() view external returns (bytes4) {
function () view external g = this.h;
return g.selector;
}
}
// ----
// TypeError: (105-141): Type function () external is not implicitly convertible to expected type function () view external.

View File

@ -0,0 +1,8 @@
contract C {
function h() payable external {
}
function f() view external returns (bytes4) {
function () external g = this.h;
return g.selector;
}
}

View File

@ -0,0 +1,10 @@
contract C {
function h() payable external {
}
function f() view external returns (bytes4) {
function () pure external g = this.h;
return g.selector;
}
}
// ----
// TypeError: (113-149): Type function () payable external is not implicitly convertible to expected type function () pure external.

View File

@ -0,0 +1,10 @@
contract C {
function h() payable external {
}
function f() view external returns (bytes4) {
function () view external g = this.h;
return g.selector;
}
}
// ----
// TypeError: (113-149): Type function () payable external is not implicitly convertible to expected type function () view external.

View File

@ -0,0 +1,8 @@
contract C {
function h() pure external {
}
function f() view external returns (bytes4) {
function () external g = this.h;
return g.selector;
}
}

View File

@ -0,0 +1,10 @@
contract C {
function h() pure external {
}
function f() view external returns (bytes4) {
function () payable external g = this.h;
return g.selector;
}
}
// ----
// TypeError: (110-149): Type function () pure external is not implicitly convertible to expected type function () payable external.

View File

@ -0,0 +1,8 @@
contract C {
function h() pure external {
}
function f() view external returns (bytes4) {
function () view external g = this.h;
return g.selector;
}
}

View File

@ -0,0 +1,14 @@
contract C {
int dummy;
function h_nonpayable() external { dummy = 1; }
function h_payable() payable external {}
function h_view() view external { dummy; }
function h_pure() pure external {}
function f() view external {
function () external g_nonpayable = this.h_nonpayable; g_nonpayable;
function () payable external g_payable = this.h_payable; g_payable;
function () view external g_view = this.h_view; g_view;
function () pure external g_pure = this.h_pure; g_pure;
}
}
// ----

View File

@ -0,0 +1,10 @@
contract C {
int dummy;
function h() view external {
dummy;
}
function f() view external returns (bytes4) {
function () external g = this.h;
return g.selector;
}
}

View File

@ -0,0 +1,10 @@
contract C {
function h() view external {
}
function f() view external returns (bytes4) {
function () payable external g = this.h;
return g.selector;
}
}
// ----
// TypeError: (110-149): Type function () view external is not implicitly convertible to expected type function () payable external.

View File

@ -0,0 +1,10 @@
contract C {
function h() view external {
}
function f() view external returns (bytes4) {
function () pure external g = this.h;
return g.selector;
}
}
// ----
// TypeError: (110-146): Type function () view external is not implicitly convertible to expected type function () pure external.