diff --git a/Changelog.md b/Changelog.md index f8c9b5380..6a98d1db0 100644 --- a/Changelog.md +++ b/Changelog.md @@ -19,6 +19,7 @@ Breaking Changes: * Type System: Explicit conversions between two types are disallowed if it changes more than one of sign, width or kind at the same time. * Type System: Declarations with the name ``this``, ``super`` and ``_`` are disallowed, with the exception of public functions and events. * Type System: Disallow ``type(super)``. + * Type System: Disallow ``msg.data`` in ``receive()`` function. * Command Line Interface: JSON fields `abi`, `devdoc`, `userdoc` and `storage-layout` are now sub-objects rather than strings. * Scanner: Remove support for the ``\b``, ``\f``, and ``\v`` escape sequences. diff --git a/libsolidity/analysis/StaticAnalyzer.cpp b/libsolidity/analysis/StaticAnalyzer.cpp index 7b828ebce..4931401cb 100644 --- a/libsolidity/analysis/StaticAnalyzer.cpp +++ b/libsolidity/analysis/StaticAnalyzer.cpp @@ -224,6 +224,17 @@ bool StaticAnalyzer::visit(MemberAccess const& _memberAccess) "Because of that, it might be that the deployed bytecode is different from type(...).runtimeCode." ); } + else if ( + m_currentFunction && + m_currentFunction->isReceive() && + type->kind() == MagicType::Kind::Message && + _memberAccess.memberName() == "data" + ) + m_errorReporter.typeError( + 7139_error, + _memberAccess.location(), + R"("msg.data" cannot be used inside of "receive" function.)" + ); } if (_memberAccess.memberName() == "callcode") diff --git a/test/libsolidity/syntaxTests/receiveEther/msg_data_in_receive.sol b/test/libsolidity/syntaxTests/receiveEther/msg_data_in_receive.sol new file mode 100644 index 000000000..20e0dbdf2 --- /dev/null +++ b/test/libsolidity/syntaxTests/receiveEther/msg_data_in_receive.sol @@ -0,0 +1,5 @@ +contract C { + receive() external payable { msg.data; } +} +// ---- +// TypeError 7139: (46-54): "msg.data" cannot be used inside of "receive" function.