Fixed segfault occurring with accidentally unnamed variables.

This commit is contained in:
Patrick Lühne 2017-06-21 16:48:43 +02:00
parent 17985e3b5a
commit ec8007125f
Signed by: patrick
GPG Key ID: 05F3611E97A70ABF

View File

@ -21,8 +21,15 @@ void parseAndAddUntypedVariableDeclaration(Context &context, ast::VariableDeclar
auto &tokenizer = context.tokenizer;
tokenizer.expect<std::string>("?");
const auto position = tokenizer.position();
auto variableName = tokenizer.getIdentifier();
assert(variableName != "-");
if (variableName == "" || variableName == "-")
{
tokenizer.seek(position);
throw ParserException(tokenizer.location(), "could not parse variable name");
}
variableDeclarations.emplace_back(std::make_unique<ast::VariableDeclaration>(std::move(variableName)));
}