Some further test fixes.

This commit is contained in:
chriseth 2015-10-13 14:31:24 +02:00
parent 13d7bc4ee8
commit 72f7792f8e
3 changed files with 37 additions and 26 deletions

View File

@ -785,29 +785,30 @@ ASTPointer<VariableDeclarationStatement> Parser::parseVariableDeclarationStateme
// Parse `var (a, b, ,, c) = ...` into a single VariableDeclarationStatement with multiple variables.
m_scanner->next();
m_scanner->next();
while (true)
{
ASTPointer<VariableDeclaration> var;
if (
m_scanner->currentToken() != Token::Comma &&
m_scanner->currentToken() != Token::RParen
)
if (m_scanner->currentToken() != Token::RParen)
while (true)
{
ASTNodeFactory varDeclNodeFactory(*this);
ASTPointer<ASTString> name = expectIdentifierToken();
var = varDeclNodeFactory.createNode<VariableDeclaration>(
ASTPointer<TypeName>(),
name,
ASTPointer<Expression>(),
VariableDeclaration::Visibility::Default
);
ASTPointer<VariableDeclaration> var;
if (
m_scanner->currentToken() != Token::Comma &&
m_scanner->currentToken() != Token::RParen
)
{
ASTNodeFactory varDeclNodeFactory(*this);
ASTPointer<ASTString> name = expectIdentifierToken();
var = varDeclNodeFactory.createNode<VariableDeclaration>(
ASTPointer<TypeName>(),
name,
ASTPointer<Expression>(),
VariableDeclaration::Visibility::Default
);
}
variables.push_back(var);
if (m_scanner->currentToken() == Token::RParen)
break;
else
expectToken(Token::Comma);
}
variables.push_back(var);
if (m_scanner->currentToken() == Token::RParen)
break;
else
expectToken(Token::Comma);
}
nodeFactory.markEndPosition();
m_scanner->next();
}

View File

@ -589,7 +589,6 @@ void TypeChecker::endVisit(Return const& _return)
bool TypeChecker::visit(VariableDeclarationStatement const& _statement)
{
solAssert(!_statement.declarations().empty(), "");
if (!_statement.initialValue())
{
// No initial value is only permitted for single variables with specified type.
@ -628,14 +627,24 @@ bool TypeChecker::visit(VariableDeclarationStatement const& _statement)
vector<VariableDeclaration const*>& assignments = _statement.annotation().assignments;
assignments.resize(valueTypes.size(), nullptr);
vector<ASTPointer<VariableDeclaration>> const& variables = _statement.declarations();
if (valueTypes.size() != variables.size() && !variables.front() && !variables.back())
if (variables.empty())
{
if (!valueTypes.empty())
fatalTypeError(
_statement,
"Too many components (" +
toString(valueTypes.size()) +
") in value for variable assignment (0) needed"
);
}
else if (valueTypes.size() != variables.size() && !variables.front() && !variables.back())
fatalTypeError(
_statement,
"Wildcard both at beginning and end of variable declaration list is only allowed "
"if the number of components is equal."
);
size_t minNumValues = variables.size();
if (!variables.back() || !variables.front())
if (!variables.empty() && (!variables.back() || !variables.front()))
--minNumValues;
if (valueTypes.size() < minNumValues)
fatalTypeError(
@ -654,7 +663,7 @@ bool TypeChecker::visit(VariableDeclarationStatement const& _statement)
toString(minNumValues) +
" needed)."
);
bool fillRight = (!variables.back() || variables.front());
bool fillRight = !variables.empty() && (!variables.back() || variables.front());
for (size_t i = 0; i < min(variables.size(), valueTypes.size()); ++i)
if (fillRight)
assignments[i] = variables[i].get();

View File

@ -2419,9 +2419,10 @@ BOOST_AUTO_TEST_CASE(multi_variable_declaration_wildcards_fine)
var (,e,g) = two();
var (,,) = three();
var () = none();
}
}
)";
BOOST_CHECK_NO_THROW(parseAndAnalyseReturnError(text));
BOOST_CHECK_NO_THROW(parseAndAnalyse(text));
}
BOOST_AUTO_TEST_CASE(multi_variable_declaration_wildcards_fail_1)