aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2018-05-04 12:21:28 +0800
committerchriseth <chris@ethereum.org>2018-05-04 18:47:01 +0800
commitffe7f224a6c9598284f100f842e3cfba58974d56 (patch)
tree443d70a5ad7dd48afd9d52bc3917869ed0352ed7
parent5738f93704a2d5de863d5f160adf8a27bf965361 (diff)
downloaddexon-solidity-ffe7f224a6c9598284f100f842e3cfba58974d56.tar
dexon-solidity-ffe7f224a6c9598284f100f842e3cfba58974d56.tar.gz
dexon-solidity-ffe7f224a6c9598284f100f842e3cfba58974d56.tar.bz2
dexon-solidity-ffe7f224a6c9598284f100f842e3cfba58974d56.tar.lz
dexon-solidity-ffe7f224a6c9598284f100f842e3cfba58974d56.tar.xz
dexon-solidity-ffe7f224a6c9598284f100f842e3cfba58974d56.tar.zst
dexon-solidity-ffe7f224a6c9598284f100f842e3cfba58974d56.zip
Show proper error when trying to emit a non-event
-rw-r--r--Changelog.md1
-rw-r--r--libsolidity/analysis/TypeChecker.cpp1
-rw-r--r--test/libsolidity/syntaxTests/emit_non_event.sol10
3 files changed, 12 insertions, 0 deletions
diff --git a/Changelog.md b/Changelog.md
index 817365b9..7c4ac925 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -8,6 +8,7 @@ Features:
* Type Checker: Make literals (without explicit type casting) an error for tight packing as experimental 0.5.0 feature.
Bugfixes:
+ * Type Checker: Show proper error when trying to ``emit`` a non-event.
* Type Checker: Warn about empty tuple components (this will turn into an error with version 0.5.0).
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp
index 7ea10c5b..fe907a2d 100644
--- a/libsolidity/analysis/TypeChecker.cpp
+++ b/libsolidity/analysis/TypeChecker.cpp
@@ -1067,6 +1067,7 @@ void TypeChecker::endVisit(EmitStatement const& _emit)
{
if (
_emit.eventCall().annotation().kind != FunctionCallKind::FunctionCall ||
+ type(_emit.eventCall().expression())->category() != Type::Category::Function ||
dynamic_cast<FunctionType const&>(*type(_emit.eventCall().expression())).kind() != FunctionType::Kind::Event
)
m_errorReporter.typeError(_emit.eventCall().expression().location(), "Expression has to be an event invocation.");
diff --git a/test/libsolidity/syntaxTests/emit_non_event.sol b/test/libsolidity/syntaxTests/emit_non_event.sol
new file mode 100644
index 00000000..1df6990d
--- /dev/null
+++ b/test/libsolidity/syntaxTests/emit_non_event.sol
@@ -0,0 +1,10 @@
+contract C {
+ uint256 Test;
+
+ function f() {
+ emit Test();
+ }
+}
+// ----
+// TypeError: (56-62): Type is not callable
+// TypeError: (56-60): Expression has to be an event invocation.