From 4a19c7e495b2dd000457de616fb7cb1b03843d92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Wed, 2 Jun 2021 21:38:57 +0200 Subject: [PATCH] Treat invalid external function type as a fatal error to prevent the type from being used - `returnParameterTypesWithoutDynamicTypes()` assumes it won't encounter such types. --- Changelog.md | 1 + libsolidity/analysis/TypeChecker.cpp | 2 +- ...nal_function_via_local_variable_with_invalid_type.sol | 8 ++++++++ ...external_function_via_parameter_with_invalid_type.sol | 9 +++++++++ 4 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 test/libsolidity/syntaxTests/iceRegressionTests/calling_external_function_via_local_variable_with_invalid_type.sol create mode 100644 test/libsolidity/syntaxTests/iceRegressionTests/calling_external_function_via_parameter_with_invalid_type.sol diff --git a/Changelog.md b/Changelog.md index d7c3eec00..61c51b4ed 100644 --- a/Changelog.md +++ b/Changelog.md @@ -23,6 +23,7 @@ Bugfixes: * Source Locations: Properly set source location of scoped blocks. * Standard JSON: Properly allow the ``inliner`` setting under ``settings.optimizer.details``. * Type Checker: Fix internal compiler error related to having mapping types in constructor parameter for abstract contracts. + * Type Checker: Fix internal compiler error when attempting to use an invalid external function type on pre-byzantium EVMs. AST Changes: diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 22aff45d8..113755650 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -721,7 +721,7 @@ void TypeChecker::endVisit(FunctionTypeName const& _funType) { solAssert(t->annotation().type, "Type not set for parameter."); if (!t->annotation().type->interfaceType(false).get()) - m_errorReporter.typeError(2582_error, t->location(), "Internal type cannot be used for external function type."); + m_errorReporter.fatalTypeError(2582_error, t->location(), "Internal type cannot be used for external function type."); } solAssert(fun.interfaceType(false), "External function type uses internal types."); } diff --git a/test/libsolidity/syntaxTests/iceRegressionTests/calling_external_function_via_local_variable_with_invalid_type.sol b/test/libsolidity/syntaxTests/iceRegressionTests/calling_external_function_via_local_variable_with_invalid_type.sol new file mode 100644 index 000000000..7257ef0f7 --- /dev/null +++ b/test/libsolidity/syntaxTests/iceRegressionTests/calling_external_function_via_local_variable_with_invalid_type.sol @@ -0,0 +1,8 @@ +contract C { + function f() public { + function() external returns (function() internal) getCallback; + getCallback(); + } +} +// ---- +// TypeError 2582: (76-96): Internal type cannot be used for external function type. diff --git a/test/libsolidity/syntaxTests/iceRegressionTests/calling_external_function_via_parameter_with_invalid_type.sol b/test/libsolidity/syntaxTests/iceRegressionTests/calling_external_function_via_parameter_with_invalid_type.sol new file mode 100644 index 000000000..9bb40242e --- /dev/null +++ b/test/libsolidity/syntaxTests/iceRegressionTests/calling_external_function_via_parameter_with_invalid_type.sol @@ -0,0 +1,9 @@ +contract C { + function f( + function() external returns (function() internal) getCallback + ) public { + getCallback(); + } +} +// ---- +// TypeError 2582: (66-86): Internal type cannot be used for external function type.