Disallow empty tuple components.

This commit is contained in:
Daniel Kirchner 2018-07-10 12:37:09 +02:00
parent d9c3b10b1c
commit a6e5a51d61

View File

@ -1411,14 +1411,12 @@ bool TypeChecker::visit(TupleExpression const& _tuple)
} }
else else
{ {
bool const v050 = m_scope->sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::V050);
bool isPure = true; bool isPure = true;
TypePointer inlineArrayType; TypePointer inlineArrayType;
for (size_t i = 0; i < components.size(); ++i) 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,). if (!components[i])
if (!components[i] && !(i == 1 && components.size() == 2))
m_errorReporter.fatalTypeError(_tuple.location(), "Tuple component cannot be empty."); m_errorReporter.fatalTypeError(_tuple.location(), "Tuple component cannot be empty.");
else if (components[i]) else if (components[i])
{ {
@ -1430,10 +1428,7 @@ bool TypeChecker::visit(TupleExpression const& _tuple)
{ {
if (_tuple.isInlineArray()) if (_tuple.isInlineArray())
m_errorReporter.fatalTypeError(components[i]->location(), "Array component cannot be empty."); m_errorReporter.fatalTypeError(components[i]->location(), "Array component cannot be empty.");
if (v050) m_errorReporter.typeError(components[i]->location(), "Tuple component cannot be empty.");
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. // Note: code generation will visit each of the expression even if they are not assigned from.