From 6d1454fce6488456fba244b01d0f026ece0a7372 Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 1 Dec 2020 10:34:45 +0100 Subject: [PATCH] Disallow conversion to super. --- libsolidity/analysis/TypeChecker.cpp | 9 +++++++++ .../syntaxTests/conversion/convert_to_super_empty.sol | 7 +++++++ .../syntaxTests/conversion/convert_to_super_nonempty.sol | 7 +++++++ 3 files changed, 23 insertions(+) create mode 100644 test/libsolidity/syntaxTests/conversion/convert_to_super_empty.sol create mode 100644 test/libsolidity/syntaxTests/conversion/convert_to_super_nonempty.sol diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index f0db8f323..46b0b04f2 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -2351,7 +2351,16 @@ bool TypeChecker::visit(FunctionCall const& _functionCall) funcCallAnno.kind = FunctionCallKind::StructConstructorCall; } else + { + if (auto const* contractType = dynamic_cast(actualType)) + if (contractType->isSuper()) + m_errorReporter.fatalTypeError( + 1744_error, + _functionCall.location(), + "Cannot convert to the super type." + ); funcCallAnno.kind = FunctionCallKind::TypeConversion; + } funcCallAnno.isPure = argumentsArePure; diff --git a/test/libsolidity/syntaxTests/conversion/convert_to_super_empty.sol b/test/libsolidity/syntaxTests/conversion/convert_to_super_empty.sol new file mode 100644 index 000000000..a36882c7e --- /dev/null +++ b/test/libsolidity/syntaxTests/conversion/convert_to_super_empty.sol @@ -0,0 +1,7 @@ +contract C { + function f() public pure { + super().x; + } +} +// ---- +// TypeError 1744: (52-59): Cannot convert to the super type. diff --git a/test/libsolidity/syntaxTests/conversion/convert_to_super_nonempty.sol b/test/libsolidity/syntaxTests/conversion/convert_to_super_nonempty.sol new file mode 100644 index 000000000..0cbfe6fcb --- /dev/null +++ b/test/libsolidity/syntaxTests/conversion/convert_to_super_nonempty.sol @@ -0,0 +1,7 @@ +contract C { + function f() public pure { + super(this).f(); + } +} +// ---- +// TypeError 1744: (52-63): Cannot convert to the super type.