1
0
mirror of synced 2025-02-17 18:59:21 +01:00

patterns: Allow variables to be named the same as types

This commit is contained in:
WerWolv 2022-02-20 20:50:02 +01:00
parent 9deab9c497
commit 2e95184d30

View File

@ -11,6 +11,7 @@ namespace hex::pl {
bool Validator::validate(const std::vector<ASTNode *> &ast) {
std::unordered_set<std::string> identifiers;
std::unordered_set<std::string> types;
try {
@ -24,8 +25,8 @@ namespace hex::pl {
this->validate({ variableDeclNode->getType() });
} else if (auto typeDeclNode = dynamic_cast<ASTNodeTypeDecl *>(node); typeDeclNode != nullptr) {
if (!identifiers.insert(typeDeclNode->getName().data()).second)
throwValidatorError(hex::format("redefinition of identifier '{0}'", typeDeclNode->getName().data()), typeDeclNode->getLineNumber());
if (!types.insert(typeDeclNode->getName().data()).second)
throwValidatorError(hex::format("redefinition of type '{0}'", typeDeclNode->getName().data()), typeDeclNode->getLineNumber());
this->validate({ typeDeclNode->getType() });
} else if (auto structNode = dynamic_cast<ASTNodeStruct *>(node); structNode != nullptr) {