aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYoichi Hirai <i@yoichihirai.com>2017-03-02 23:27:39 +0800
committerGitHub <noreply@github.com>2017-03-02 23:27:39 +0800
commit11195360f6742ae49eba513917af8b0b0cd60d09 (patch)
treeca1bf895276995e8abb7bccb86b6d09b8e6d4486
parent5c411b472b5830efa798309e1e7ed728acafdfa3 (diff)
parent6a9df162fd30237e9313a28599d4b0f26f2ea4f2 (diff)
downloaddexon-solidity-11195360f6742ae49eba513917af8b0b0cd60d09.tar
dexon-solidity-11195360f6742ae49eba513917af8b0b0cd60d09.tar.gz
dexon-solidity-11195360f6742ae49eba513917af8b0b0cd60d09.tar.bz2
dexon-solidity-11195360f6742ae49eba513917af8b0b0cd60d09.tar.lz
dexon-solidity-11195360f6742ae49eba513917af8b0b0cd60d09.tar.xz
dexon-solidity-11195360f6742ae49eba513917af8b0b0cd60d09.tar.zst
dexon-solidity-11195360f6742ae49eba513917af8b0b0cd60d09.zip
Merge pull request #1727 from ethereum/fixtuples
Do now allow declaring variables with inferred empty tuple type.
-rw-r--r--Changelog.md1
-rw-r--r--libsolidity/analysis/TypeChecker.cpp5
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp13
3 files changed, 19 insertions, 0 deletions
diff --git a/Changelog.md b/Changelog.md
index 3eaadf21..5eb1e401 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -13,6 +13,7 @@ Bugfixes:
* Type system: Fix a crash caused by continuing on fatal errors in the code.
* Type system: Disallow arrays with negative length.
* Type system: Fix a crash related to invalid binary operators.
+ * Type system: Disallow ``var`` declaration with empty tuple type.
* Type system: Correctly convert function argument types to pointers for member functions.
* Inline assembly: Charge one stack slot for non-value types during analysis.
* Assembly output: Print source location before the operation it refers to instead of after.
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp
index 4025831e..ff55ef1f 100644
--- a/libsolidity/analysis/TypeChecker.cpp
+++ b/libsolidity/analysis/TypeChecker.cpp
@@ -824,6 +824,11 @@ bool TypeChecker::visit(VariableDeclarationStatement const& _statement)
else
solAssert(false, "");
}
+ else if (*var.annotation().type == TupleType())
+ typeError(
+ var.location(),
+ "Cannot declare variable with void (empty tuple) type."
+ );
var.accept(*this);
}
else
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp
index 866bd9aa..3b137572 100644
--- a/test/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -2950,6 +2950,19 @@ BOOST_AUTO_TEST_CASE(multi_variable_declaration_wildcards_fail_6)
CHECK_ERROR(text, TypeError, "");
}
+BOOST_AUTO_TEST_CASE(tuple_assignment_from_void_function)
+{
+ char const* text = R"(
+ contract C {
+ function f() { }
+ function g() {
+ var (x,) = (f(), f());
+ }
+ }
+ )";
+ CHECK_ERROR(text, TypeError, "Cannot declare variable with void (empty tuple) type.");
+}
+
BOOST_AUTO_TEST_CASE(member_access_parser_ambiguity)
{
char const* text = R"(