aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeonardo Alt <leo@ethereum.org>2018-08-02 01:01:50 +0800
committerLeonardo Alt <leo@ethereum.org>2018-08-03 19:41:27 +0800
commit20c6cea7bb803a5217f6b96062c7bce150ba2b73 (patch)
tree4e1dcf9400c354b05aaffdc42daf4bfcd988c7fc
parentda6cefd475210a9bcae0aad80c03f3679ae00f56 (diff)
downloaddexon-solidity-20c6cea7bb803a5217f6b96062c7bce150ba2b73.tar.gz
dexon-solidity-20c6cea7bb803a5217f6b96062c7bce150ba2b73.tar.zst
dexon-solidity-20c6cea7bb803a5217f6b96062c7bce150ba2b73.zip
Disallow structs in events without ABIEncoderV2
-rw-r--r--Changelog.md1
-rw-r--r--libsolidity/analysis/TypeChecker.cpp10
-rw-r--r--test/libsolidity/SolidityABIJSON.cpp1
-rw-r--r--test/libsolidity/syntaxTests/emit/emit_empty.sol (renamed from test/libsolidity/syntaxTests/emit_empty.sol)0
-rw-r--r--test/libsolidity/syntaxTests/emit/emit_non_event.sol (renamed from test/libsolidity/syntaxTests/emit_non_event.sol)0
-rw-r--r--test/libsolidity/syntaxTests/events/event_nested_array.sol5
-rw-r--r--test/libsolidity/syntaxTests/events/event_nested_array_2.sol4
-rw-r--r--test/libsolidity/syntaxTests/events/event_nested_array_in_struct.sol6
-rw-r--r--test/libsolidity/syntaxTests/events/event_struct.sol6
-rw-r--r--test/libsolidity/syntaxTests/events/event_struct_indexed.sol6
10 files changed, 39 insertions, 0 deletions
diff --git a/Changelog.md b/Changelog.md
index e5306dc0..4ad65ff2 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -80,6 +80,7 @@ Bugfixes:
* References Resolver: Enforce ``storage`` as data location for mappings.
* References Resolver: Report error instead of assertion fail when FunctionType has an undeclared type as parameter.
* Type Checker: Consider fixed size arrays when checking for recursive structs.
+ * Type Checker: Report error when using structs in events without experimental ABIEncoderV2. This used to crash or log the wrong values.
* Type System: Allow arbitrary exponents for literals with a mantissa of zero.
### 0.4.24 (2018-05-16)
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp
index 8c84e4dc..d5028f3b 100644
--- a/libsolidity/analysis/TypeChecker.cpp
+++ b/libsolidity/analysis/TypeChecker.cpp
@@ -817,6 +817,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())
{
@@ -826,6 +827,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.");
diff --git a/test/libsolidity/SolidityABIJSON.cpp b/test/libsolidity/SolidityABIJSON.cpp
index f2d6d66f..0b2e23e6 100644
--- a/test/libsolidity/SolidityABIJSON.cpp
+++ b/test/libsolidity/SolidityABIJSON.cpp
@@ -980,6 +980,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; }
diff --git a/test/libsolidity/syntaxTests/emit_empty.sol b/test/libsolidity/syntaxTests/emit/emit_empty.sol
index 819d88fe..819d88fe 100644
--- a/test/libsolidity/syntaxTests/emit_empty.sol
+++ b/test/libsolidity/syntaxTests/emit/emit_empty.sol
diff --git a/test/libsolidity/syntaxTests/emit_non_event.sol b/test/libsolidity/syntaxTests/emit/emit_non_event.sol
index d5045ddf..d5045ddf 100644
--- a/test/libsolidity/syntaxTests/emit_non_event.sol
+++ b/test/libsolidity/syntaxTests/emit/emit_non_event.sol
diff --git a/test/libsolidity/syntaxTests/events/event_nested_array.sol b/test/libsolidity/syntaxTests/events/event_nested_array.sol
new file mode 100644
index 00000000..70af63b6
--- /dev/null
+++ b/test/libsolidity/syntaxTests/events/event_nested_array.sol
@@ -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.
diff --git a/test/libsolidity/syntaxTests/events/event_nested_array_2.sol b/test/libsolidity/syntaxTests/events/event_nested_array_2.sol
new file mode 100644
index 00000000..5825650e
--- /dev/null
+++ b/test/libsolidity/syntaxTests/events/event_nested_array_2.sol
@@ -0,0 +1,4 @@
+contract c {
+ event E(uint[2][]);
+}
+// ----
diff --git a/test/libsolidity/syntaxTests/events/event_nested_array_in_struct.sol b/test/libsolidity/syntaxTests/events/event_nested_array_in_struct.sol
new file mode 100644
index 00000000..fd59e962
--- /dev/null
+++ b/test/libsolidity/syntaxTests/events/event_nested_array_in_struct.sol
@@ -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.
diff --git a/test/libsolidity/syntaxTests/events/event_struct.sol b/test/libsolidity/syntaxTests/events/event_struct.sol
new file mode 100644
index 00000000..c955dc5e
--- /dev/null
+++ b/test/libsolidity/syntaxTests/events/event_struct.sol
@@ -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.
diff --git a/test/libsolidity/syntaxTests/events/event_struct_indexed.sol b/test/libsolidity/syntaxTests/events/event_struct_indexed.sol
new file mode 100644
index 00000000..69ee5017
--- /dev/null
+++ b/test/libsolidity/syntaxTests/events/event_struct_indexed.sol
@@ -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.