mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #3976 from ethereum/emptyTupleComponent
Empty tuple components should not be possible
This commit is contained in:
commit
e685f9f59e
@ -6,7 +6,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)
|
||||
|
@ -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())
|
||||
|
10
test/libsolidity/syntaxTests/types/empty_tuple_event.sol
Normal file
10
test/libsolidity/syntaxTests/types/empty_tuple_event.sol
Normal file
@ -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.
|
10
test/libsolidity/syntaxTests/types/empty_tuple_event_050.sol
Normal file
10
test/libsolidity/syntaxTests/types/empty_tuple_event_050.sol
Normal file
@ -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.
|
12
test/libsolidity/syntaxTests/types/empty_tuple_function.sol
Normal file
12
test/libsolidity/syntaxTests/types/empty_tuple_function.sol
Normal file
@ -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.
|
@ -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.
|
13
test/libsolidity/syntaxTests/types/empty_tuple_lvalue.sol
Normal file
13
test/libsolidity/syntaxTests/types/empty_tuple_lvalue.sol
Normal file
@ -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).
|
@ -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.
|
@ -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.
|
Loading…
Reference in New Issue
Block a user