aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Changelog.md2
-rw-r--r--libsolidity/analysis/TypeChecker.cpp13
-rw-r--r--libsolidity/parsing/DocStringParser.cpp2
-rw-r--r--test/libsolidity/syntaxTests/natspec/docstring_empty_description.sol (renamed from test/libsolidity/syntaxTests/docstring_empty_description.sol)0
-rw-r--r--test/libsolidity/syntaxTests/natspec/docstring_empty_tag.sol6
-rw-r--r--test/libsolidity/syntaxTests/types/empty_tuple_event.sol10
-rw-r--r--test/libsolidity/syntaxTests/types/empty_tuple_event_050.sol10
-rw-r--r--test/libsolidity/syntaxTests/types/empty_tuple_function.sol12
-rw-r--r--test/libsolidity/syntaxTests/types/empty_tuple_function_050.sol11
-rw-r--r--test/libsolidity/syntaxTests/types/empty_tuple_lvalue.sol13
-rw-r--r--test/libsolidity/syntaxTests/types/empty_tuple_lvalue_050.sol11
-rw-r--r--test/libsolidity/syntaxTests/types/empty_tuple_lvalue_array.sol11
12 files changed, 99 insertions, 2 deletions
diff --git a/Changelog.md b/Changelog.md
index 4787f1c8..1cb96833 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -7,7 +7,7 @@ Features:
* Type Checker: Make literals (without explicit type casting) an error for tight packing as experimental 0.5.0 feature.
Bugfixes:
-
+ * Type Checker: Warn about empty tuple components (this will turn into an error with version 0.5.0).
### 0.4.23 (2018-04-19)
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp
index a672cd66..7ea10c5b 100644
--- a/libsolidity/analysis/TypeChecker.cpp
+++ b/libsolidity/analysis/TypeChecker.cpp
@@ -1406,8 +1406,10 @@ bool TypeChecker::visit(TupleExpression const& _tuple)
}
else
{
+ bool const v050 = m_scope->sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::V050);
bool isPure = true;
TypePointer inlineArrayType;
+
for (size_t i = 0; i < components.size(); ++i)
{
// Outside of an lvalue-context, the only situation where a component can be empty is (x,).
@@ -1418,6 +1420,17 @@ bool TypeChecker::visit(TupleExpression const& _tuple)
components[i]->accept(*this);
types.push_back(type(*components[i]));
+ if (types[i]->category() == Type::Category::Tuple)
+ if (dynamic_cast<TupleType const&>(*types[i]).components().empty())
+ {
+ if (_tuple.isInlineArray())
+ m_errorReporter.fatalTypeError(components[i]->location(), "Array component cannot be empty.");
+ if (v050)
+ m_errorReporter.fatalTypeError(components[i]->location(), "Tuple component cannot be empty.");
+ else
+ m_errorReporter.warning(components[i]->location(), "Tuple component cannot be empty.");
+ }
+
// Note: code generation will visit each of the expression even if they are not assigned from.
if (types[i]->category() == Type::Category::RationalNumber && components.size() > 1)
if (!dynamic_cast<RationalNumberType const&>(*types[i]).mobileType())
diff --git a/libsolidity/parsing/DocStringParser.cpp b/libsolidity/parsing/DocStringParser.cpp
index d058d556..d9588e5c 100644
--- a/libsolidity/parsing/DocStringParser.cpp
+++ b/libsolidity/parsing/DocStringParser.cpp
@@ -72,7 +72,7 @@ bool DocStringParser::parse(string const& _docString, ErrorReporter& _errorRepor
auto tagNameEndPos = firstWhitespaceOrNewline(tagPos, end);
if (tagNameEndPos == end)
{
- appendError("End of tag " + string(tagPos, tagNameEndPos) + "not found");
+ appendError("End of tag " + string(tagPos, tagNameEndPos) + " not found");
break;
}
diff --git a/test/libsolidity/syntaxTests/docstring_empty_description.sol b/test/libsolidity/syntaxTests/natspec/docstring_empty_description.sol
index 0caa1b23..0caa1b23 100644
--- a/test/libsolidity/syntaxTests/docstring_empty_description.sol
+++ b/test/libsolidity/syntaxTests/natspec/docstring_empty_description.sol
diff --git a/test/libsolidity/syntaxTests/natspec/docstring_empty_tag.sol b/test/libsolidity/syntaxTests/natspec/docstring_empty_tag.sol
new file mode 100644
index 00000000..9a28143a
--- /dev/null
+++ b/test/libsolidity/syntaxTests/natspec/docstring_empty_tag.sol
@@ -0,0 +1,6 @@
+contract C {
+ /// @param
+ function vote(uint id) public;
+}
+// ----
+// DocstringParsingError: End of tag @param not found
diff --git a/test/libsolidity/syntaxTests/types/empty_tuple_event.sol b/test/libsolidity/syntaxTests/types/empty_tuple_event.sol
new file mode 100644
index 00000000..3e40b155
--- /dev/null
+++ b/test/libsolidity/syntaxTests/types/empty_tuple_event.sol
@@ -0,0 +1,10 @@
+pragma solidity ^0.4.3;
+contract C {
+ event SomeEvent();
+ function a() public {
+ (SomeEvent(), 7);
+ }
+}
+// ----
+// Warning: (95-106): Invoking events without "emit" prefix is deprecated.
+// Warning: (95-106): Tuple component cannot be empty.
diff --git a/test/libsolidity/syntaxTests/types/empty_tuple_event_050.sol b/test/libsolidity/syntaxTests/types/empty_tuple_event_050.sol
new file mode 100644
index 00000000..aec5ff2a
--- /dev/null
+++ b/test/libsolidity/syntaxTests/types/empty_tuple_event_050.sol
@@ -0,0 +1,10 @@
+pragma experimental "v0.5.0";
+contract C {
+ event SomeEvent();
+ function a() public {
+ (SomeEvent(), 7);
+ }
+}
+// ----
+// TypeError: (101-112): Event invocations have to be prefixed by "emit".
+// TypeError: (101-112): Tuple component cannot be empty.
diff --git a/test/libsolidity/syntaxTests/types/empty_tuple_function.sol b/test/libsolidity/syntaxTests/types/empty_tuple_function.sol
new file mode 100644
index 00000000..05b54442
--- /dev/null
+++ b/test/libsolidity/syntaxTests/types/empty_tuple_function.sol
@@ -0,0 +1,12 @@
+pragma solidity ^0.4.3;
+contract C {
+ function f() private pure {}
+ function a() public pure {
+ bool x = true;
+ bool y = true;
+ (x) ? (f(), y = false) : (f(), y = false);
+ }
+}
+// ----
+// Warning: (162-165): Tuple component cannot be empty.
+// Warning: (181-184): Tuple component cannot be empty.
diff --git a/test/libsolidity/syntaxTests/types/empty_tuple_function_050.sol b/test/libsolidity/syntaxTests/types/empty_tuple_function_050.sol
new file mode 100644
index 00000000..c4b9e03f
--- /dev/null
+++ b/test/libsolidity/syntaxTests/types/empty_tuple_function_050.sol
@@ -0,0 +1,11 @@
+pragma experimental "v0.5.0";
+contract C {
+ function f() private pure {}
+ function a() public pure {
+ bool x = true;
+ bool y = true;
+ (x) ? (f(), y = false) : (f(), y = false);
+ }
+}
+// ----
+// TypeError: (168-171): Tuple component cannot be empty.
diff --git a/test/libsolidity/syntaxTests/types/empty_tuple_lvalue.sol b/test/libsolidity/syntaxTests/types/empty_tuple_lvalue.sol
new file mode 100644
index 00000000..cba30c1b
--- /dev/null
+++ b/test/libsolidity/syntaxTests/types/empty_tuple_lvalue.sol
@@ -0,0 +1,13 @@
+pragma solidity ^0.4.3;
+contract C {
+ function f() private pure {}
+ function a() public {
+ uint x;
+ uint y;
+ (x, y) = (f(), f());
+ }
+}
+// ----
+// Warning: (146-149): Tuple component cannot be empty.
+// Warning: (151-154): Tuple component cannot be empty.
+// TypeError: (145-155): Type tuple(tuple(),tuple()) is not implicitly convertible to expected type tuple(uint256,uint256).
diff --git a/test/libsolidity/syntaxTests/types/empty_tuple_lvalue_050.sol b/test/libsolidity/syntaxTests/types/empty_tuple_lvalue_050.sol
new file mode 100644
index 00000000..b0691778
--- /dev/null
+++ b/test/libsolidity/syntaxTests/types/empty_tuple_lvalue_050.sol
@@ -0,0 +1,11 @@
+pragma experimental "v0.5.0";
+contract C {
+ function f() private pure {}
+ function a() public {
+ uint x;
+ uint y;
+ (x, y) = (f(), f());
+ }
+}
+// ----
+// TypeError: (152-155): Tuple component cannot be empty.
diff --git a/test/libsolidity/syntaxTests/types/empty_tuple_lvalue_array.sol b/test/libsolidity/syntaxTests/types/empty_tuple_lvalue_array.sol
new file mode 100644
index 00000000..f8b2ae7e
--- /dev/null
+++ b/test/libsolidity/syntaxTests/types/empty_tuple_lvalue_array.sol
@@ -0,0 +1,11 @@
+pragma solidity ^0.4.3;
+contract C {
+ function f() private pure {}
+ function a() public {
+ uint x;
+ uint y;
+ (x, y) = [f(), f()];
+ }
+}
+// ----
+// TypeError: (146-149): Array component cannot be empty.