Merge pull request #14365 from ethereum/declarationFunctionTypeConversions

Disallow conversions between declaration function types.
This commit is contained in:
Kamil Śliwak 2023-07-17 19:21:29 +02:00 committed by GitHub
commit 4c4410e0c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 0 deletions

View File

@ -29,6 +29,7 @@ Bugfixes:
* SMTChecker: Fix false negative when a verification target can be violated only by trusted external call from another public function.
* SMTChecker: Fix internal error caused by using external identifier to encode member access to functions that take an internal function as a parameter.
* Standard JSON Interface: Fix an incomplete AST being returned when analysis is interrupted by certain kinds of fatal errors.
* Type Checker: Function declaration types referring to different declarations are no longer convertible to each other.
* Yul Optimizer: Ensure that the assignment of memory slots for variables moved to memory does not depend on AST IDs that may depend on whether additional files are included during compilation.
* Yul Optimizer: Fix ``FullInliner`` step not ignoring code that is not in expression-split form.
* Yul Optimizer: Fix optimized IR being unnecessarily passed through the Yul optimizer again before bytecode generation.

View File

@ -3127,6 +3127,12 @@ BoolResult FunctionType::isImplicitlyConvertibleTo(Type const& _convertTo) const
if (convertTo.kind() != kind())
return BoolResult::err("Special functions cannot be converted to function types.");
if (
kind() == FunctionType::Kind::Declaration &&
m_declaration != convertTo.m_declaration
)
return BoolResult::err("Function declaration types referring to different functions cannot be converted to each other.");
if (!equalExcludingStateMutability(convertTo))
return false;

View File

@ -0,0 +1,11 @@
contract D {
function f() external {}
function g() external {}
}
contract C {
function f(bool c) public pure {
(c ? D.f : D.g);
}
}
// ----
// TypeError 1080: (117-130): True expression's type function D.f() does not match false expression's type function D.g().

View File

@ -0,0 +1,11 @@
contract C {
function f() internal {}
function g() internal {}
}
contract D is C {
function h(bool b) public pure {
(b ? C.f : C.g);
}
}
// ----