Skip to content

Commit

Permalink
Turns it into warning (error for 0.5.0) and adds Changelog entry.
Browse files Browse the repository at this point in the history
  • Loading branch information
erak committed Apr 23, 2018
1 parent f2b58de commit b2ff9bc
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,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)
Expand Down
9 changes: 8 additions & 1 deletion libsolidity/analysis/TypeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,).
Expand All @@ -1420,7 +1422,12 @@ bool TypeChecker::visit(TupleExpression const& _tuple)

if (types[i]->category() == Type::Category::Tuple)
if (dynamic_cast<TupleType const&>(*types[i]).components().empty())
m_errorReporter.fatalTypeError(components[i]->location(), "Type of tuple component cannot be null.");
{
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)
Expand Down
2 changes: 1 addition & 1 deletion test/libsolidity/syntaxTests/types/empty_tuple_event.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ contract C {
}
// ----
// Warning: (95-106): Invoking events without "emit" prefix is deprecated.
// TypeError: (95-106): Type of tuple component cannot be null.
// Warning: (95-106): Tuple component cannot be empty.
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ contract C {
}
// ----
// TypeError: (101-112): Event invocations have to be prefixed by "emit".
// TypeError: (101-112): Type of tuple component cannot be null.
// TypeError: (101-112): Tuple component cannot be empty.
7 changes: 4 additions & 3 deletions test/libsolidity/syntaxTests/types/empty_tuple_function.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
pragma solidity ^0.4.3;
contract C {
function f() {}
function a() public {
function f() private pure {}
function a() public pure {
bool x = true;
bool y = true;
(x) ? (f(), y = false) : (f(), y = false);
}
}
// ----
// TypeError: (144-147): Type of tuple component cannot be null.
// Warning: (162-165): Tuple component cannot be empty.
// Warning: (181-184): Tuple component cannot be empty.
11 changes: 11 additions & 0 deletions test/libsolidity/syntaxTests/types/empty_tuple_function_050.sol
Original file line number Diff line number Diff line change
@@ -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.

This file was deleted.

6 changes: 4 additions & 2 deletions test/libsolidity/syntaxTests/types/empty_tuple_lvalue.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
pragma solidity ^0.4.3;
contract C {
function f() public pure {}
function f() private pure {}
function a() public {
uint x;
uint y;
(x, y) = (f(), f());
}
}
// ----
// TypeError: (145-148): Type of tuple component cannot be null.
// 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).
11 changes: 11 additions & 0 deletions test/libsolidity/syntaxTests/types/empty_tuple_lvalue_050.sol
Original file line number Diff line number Diff line change
@@ -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.
13 changes: 13 additions & 0 deletions test/libsolidity/syntaxTests/types/empty_tuple_lvalue_array.sol
Original file line number Diff line number Diff line change
@@ -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()[2] memory is not implicitly convertible to expected type tuple(uint256,uint256).

0 comments on commit b2ff9bc

Please sign in to comment.