mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #4922 from ethereum/event_struct_error_0425
Disallow structs in events without ABIEncoderV2
This commit is contained in:
commit
ba5625063c
@ -1,5 +1,7 @@
|
||||
### 0.4.25 (unreleased)
|
||||
|
||||
Bugfixes:
|
||||
* Type Checker: Report error when using structs in events without experimental ABIEncoderV2. This used to crash or log the wrong values.
|
||||
|
||||
### 0.4.24 (2018-05-16)
|
||||
|
||||
|
@ -864,6 +864,7 @@ void TypeChecker::visitManually(
|
||||
|
||||
bool TypeChecker::visit(EventDefinition const& _eventDef)
|
||||
{
|
||||
solAssert(_eventDef.visibility() > Declaration::Visibility::Internal, "");
|
||||
unsigned numIndexed = 0;
|
||||
for (ASTPointer<VariableDeclaration> const& var: _eventDef.parameters())
|
||||
{
|
||||
@ -873,6 +874,15 @@ bool TypeChecker::visit(EventDefinition const& _eventDef)
|
||||
m_errorReporter.typeError(var->location(), "Type is required to live outside storage.");
|
||||
if (!type(*var)->interfaceType(false))
|
||||
m_errorReporter.typeError(var->location(), "Internal or recursive type is not allowed as event parameter type.");
|
||||
if (
|
||||
!_eventDef.sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::ABIEncoderV2) &&
|
||||
!typeSupportedByOldABIEncoder(*type(*var))
|
||||
)
|
||||
m_errorReporter.typeError(
|
||||
var->location(),
|
||||
"This type is only supported in the new experimental ABI encoder. "
|
||||
"Use \"pragma experimental ABIEncoderV2;\" to enable the feature."
|
||||
);
|
||||
}
|
||||
if (_eventDef.isAnonymous() && numIndexed > 4)
|
||||
m_errorReporter.typeError(_eventDef.location(), "More than 4 indexed arguments for anonymous event.");
|
||||
|
@ -1036,6 +1036,7 @@ BOOST_AUTO_TEST_CASE(return_structs_with_contracts)
|
||||
BOOST_AUTO_TEST_CASE(event_structs)
|
||||
{
|
||||
char const* text = R"(
|
||||
pragma experimental ABIEncoderV2;
|
||||
contract C {
|
||||
struct S { uint a; T[] sub; bytes b; }
|
||||
struct T { uint[2] x; }
|
||||
|
7
test/libsolidity/syntaxTests/emit/emit_empty.sol
Normal file
7
test/libsolidity/syntaxTests/emit/emit_empty.sol
Normal file
@ -0,0 +1,7 @@
|
||||
contract C {
|
||||
function f() public {
|
||||
emit;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// ParserError: (45-46): Expected event name or path.
|
@ -0,0 +1,5 @@
|
||||
contract c {
|
||||
event E(uint[][]);
|
||||
}
|
||||
// ----
|
||||
// TypeError: (25-33): This type is only supported in the new experimental ABI encoder. Use "pragma experimental ABIEncoderV2;" to enable the feature.
|
@ -0,0 +1,4 @@
|
||||
contract c {
|
||||
event E(uint[2][]);
|
||||
}
|
||||
// ----
|
@ -0,0 +1,6 @@
|
||||
contract c {
|
||||
struct S { uint x; uint[][] arr; }
|
||||
event E(S);
|
||||
}
|
||||
// ----
|
||||
// TypeError: (61-62): This type is only supported in the new experimental ABI encoder. Use "pragma experimental ABIEncoderV2;" to enable the feature.
|
6
test/libsolidity/syntaxTests/events/event_struct.sol
Normal file
6
test/libsolidity/syntaxTests/events/event_struct.sol
Normal file
@ -0,0 +1,6 @@
|
||||
contract c {
|
||||
struct S { uint a ; }
|
||||
event E(S);
|
||||
}
|
||||
// ----
|
||||
// TypeError: (51-52): This type is only supported in the new experimental ABI encoder. Use "pragma experimental ABIEncoderV2;" to enable the feature.
|
@ -0,0 +1,6 @@
|
||||
contract c {
|
||||
struct S { uint a ; }
|
||||
event E(S indexed);
|
||||
}
|
||||
// ----
|
||||
// TypeError: (51-52): This type is only supported in the new experimental ABI encoder. Use "pragma experimental ABIEncoderV2;" to enable the feature.
|
Loading…
Reference in New Issue
Block a user