Skip to content

Commit 5072472

Browse files
committed
Fix abi.encodeCall checks
1 parent 800088e commit 5072472

File tree

6 files changed

+63
-12
lines changed

6 files changed

+63
-12
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Compiler Features:
1313

1414
Bugfixes:
1515
* Commandline Interface: Disallow the following options outside of the compiler mode: ``--via-ir``,``--metadata-literal``, ``--metadata-hash``, ``--model-checker-show-unproved``, ``--model-checker-div-mod-no-slacks``, ``--model-checker-engine``, ``--model-checker-invariants``, ``--model-checker-solvers``, ``--model-checker-timeout``, ``--model-checker-contracts``, ``--model-checker-targets``.
16+
* Type Checker: Fix null dereference in `abi.encodeCall` type checking of free function.
1617

1718

1819
### 0.8.15 (2022-06-15)

libsolidity/analysis/TypeChecker.cpp

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2195,14 +2195,28 @@ void TypeChecker::typeCheckABIEncodeCallFunction(FunctionCall const& _functionCa
21952195
)
21962196
{
21972197
string msg = "Expected regular external function type, or external view on public function.";
2198-
if (externalFunctionType->kind() == FunctionType::Kind::Internal)
2199-
msg += " Provided internal function.";
2200-
else if (externalFunctionType->kind() == FunctionType::Kind::DelegateCall)
2201-
msg += " Cannot use library functions for abi.encodeCall.";
2202-
else if (externalFunctionType->kind() == FunctionType::Kind::Creation)
2203-
msg += " Provided creation function.";
2204-
else
2205-
msg += " Cannot use special function.";
2198+
2199+
switch (externalFunctionType->kind())
2200+
{
2201+
case FunctionType::Kind::Internal:
2202+
msg += " Provided internal function.";
2203+
break;
2204+
case FunctionType::Kind::DelegateCall:
2205+
msg += " Cannot use library functions for abi.encodeCall.";
2206+
break;
2207+
case FunctionType::Kind::Creation:
2208+
msg += " Provided creation function.";
2209+
break;
2210+
case FunctionType::Kind::Event:
2211+
msg += " Cannot use events for abi.encodeCall.";
2212+
break;
2213+
case FunctionType::Kind::Error:
2214+
msg += " Cannot use errors for abi.encodeCall.";
2215+
break;
2216+
default:
2217+
msg += " Cannot use special function.";
2218+
}
2219+
22062220
SecondarySourceLocation ssl{};
22072221

22082222
if (externalFunctionType->hasDeclaration())
@@ -2213,10 +2227,14 @@ void TypeChecker::typeCheckABIEncodeCallFunction(FunctionCall const& _functionCa
22132227
externalFunctionType->declaration().scope() == m_currentContract
22142228
)
22152229
msg += " Did you forget to prefix \"this.\"?";
2216-
else if (util::contains(
2217-
m_currentContract->annotation().linearizedBaseContracts,
2218-
externalFunctionType->declaration().scope()
2219-
) && externalFunctionType->declaration().scope() != m_currentContract)
2230+
else if (
2231+
m_currentContract &&
2232+
externalFunctionType->declaration().scope() != m_currentContract &&
2233+
util::contains(
2234+
m_currentContract->annotation().linearizedBaseContracts,
2235+
externalFunctionType->declaration().scope()
2236+
)
2237+
)
22202238
msg += " Functions from base contracts have to be external.";
22212239
}
22222240

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
error E(uint);
2+
3+
function f() {
4+
abi.encodeCall(E, (1));
5+
}
6+
// ----
7+
// TypeError 3509: (50-51): Expected regular external function type, or external view on public function. Cannot use errors for abi.encodeCall.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
library L {
2+
event E(uint);
3+
}
4+
5+
function f() {
6+
abi.encodeCall(L.E, (1));
7+
}
8+
// ----
9+
// TypeError 3509: (68-71): Expected regular external function type, or external view on public function. Cannot use events for abi.encodeCall.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
function g(uint) {}
2+
3+
function f() {
4+
abi.encodeCall(g, (1));
5+
}
6+
// ----
7+
// TypeError 3509: (55-56): Expected regular external function type, or external view on public function. Provided internal function.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
library L {
2+
function g() external {}
3+
}
4+
5+
function f() {
6+
abi.encodeCall(L.g, (1));
7+
}
8+
// ----
9+
// TypeError 3509: (78-81): Expected regular external function type, or external view on public function. Cannot use library functions for abi.encodeCall.

0 commit comments

Comments
 (0)