mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Prevents null type from being used in tuple.
This commit is contained in:
parent
d674cde34c
commit
f2b58de92c
@ -1418,6 +1418,10 @@ bool TypeChecker::visit(TupleExpression const& _tuple)
|
|||||||
components[i]->accept(*this);
|
components[i]->accept(*this);
|
||||||
types.push_back(type(*components[i]));
|
types.push_back(type(*components[i]));
|
||||||
|
|
||||||
|
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.");
|
||||||
|
|
||||||
// Note: code generation will visit each of the expression even if they are not assigned from.
|
// 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 (types[i]->category() == Type::Category::RationalNumber && components.size() > 1)
|
||||||
if (!dynamic_cast<RationalNumberType const&>(*types[i]).mobileType())
|
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.
|
||||||
|
// TypeError: (95-106): Type of tuple component cannot be null.
|
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): Type of tuple component cannot be null.
|
11
test/libsolidity/syntaxTests/types/empty_tuple_function.sol
Normal file
11
test/libsolidity/syntaxTests/types/empty_tuple_function.sol
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
pragma solidity ^0.4.3;
|
||||||
|
contract C {
|
||||||
|
function f() {}
|
||||||
|
function a() public {
|
||||||
|
bool x = true;
|
||||||
|
bool y = true;
|
||||||
|
(x) ? (f(), y = false) : (f(), y = false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// TypeError: (144-147): Type of tuple component cannot be null.
|
@ -0,0 +1,8 @@
|
|||||||
|
pragma solidity ^0.4.3;
|
||||||
|
contract C {
|
||||||
|
function a() public {
|
||||||
|
(a(), 7);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// TypeError: (72-75): Type of tuple component cannot be null.
|
11
test/libsolidity/syntaxTests/types/empty_tuple_lvalue.sol
Normal file
11
test/libsolidity/syntaxTests/types/empty_tuple_lvalue.sol
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
pragma solidity ^0.4.3;
|
||||||
|
contract C {
|
||||||
|
function f() public pure {}
|
||||||
|
function a() public {
|
||||||
|
uint x;
|
||||||
|
uint y;
|
||||||
|
(x, y) = (f(), f());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// TypeError: (145-148): Type of tuple component cannot be null.
|
Loading…
Reference in New Issue
Block a user