From f2b58de92cdffe9d6e70aff2f0198277a5da335a Mon Sep 17 00:00:00 2001 From: Erik Kundt Date: Sun, 22 Apr 2018 16:54:33 +0200 Subject: Prevents null type from being used in tuple. --- libsolidity/analysis/TypeChecker.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'libsolidity') diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 66b0af58..2675b7eb 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -1418,6 +1418,10 @@ 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(*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. if (types[i]->category() == Type::Category::RationalNumber && components.size() > 1) if (!dynamic_cast(*types[i]).mobileType()) -- cgit From b2ff9bc88d50e89419317d54b00e80b4c18a92c7 Mon Sep 17 00:00:00 2001 From: Erik Kundt Date: Mon, 23 Apr 2018 16:20:37 +0200 Subject: Turns it into warning (error for 0.5.0) and adds Changelog entry. --- libsolidity/analysis/TypeChecker.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'libsolidity') diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 2675b7eb..53409e6c 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,). @@ -1420,7 +1422,12 @@ bool TypeChecker::visit(TupleExpression const& _tuple) if (types[i]->category() == Type::Category::Tuple) if (dynamic_cast(*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) -- cgit From 896018c8a33f92e9dd507b462c858dbcf13d6385 Mon Sep 17 00:00:00 2001 From: Erik Kundt Date: Mon, 23 Apr 2018 17:11:41 +0200 Subject: Treats inline array as an error. --- libsolidity/analysis/TypeChecker.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'libsolidity') diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 53409e6c..02f2f833 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -1423,6 +1423,8 @@ bool TypeChecker::visit(TupleExpression const& _tuple) if (types[i]->category() == Type::Category::Tuple) if (dynamic_cast(*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 -- cgit