From 89eccffbf6de76e3a9cce2edd28cd163a36ff633 Mon Sep 17 00:00:00 2001 From: Alexei Kotov Date: Fri, 7 Jun 2024 10:52:46 +0300 Subject: [PATCH] Complain if a function or an integer is used as a local variable name --- components/compiler/declarationparser.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/components/compiler/declarationparser.cpp b/components/compiler/declarationparser.cpp index d23e3c141a..19d2bae976 100644 --- a/components/compiler/declarationparser.cpp +++ b/components/compiler/declarationparser.cpp @@ -2,7 +2,9 @@ #include +#include "context.hpp" #include "errorhandler.hpp" +#include "extensions.hpp" #include "locals.hpp" #include "scanner.hpp" #include "skipparser.hpp" @@ -70,6 +72,15 @@ bool Compiler::DeclarationParser::parseKeyword(int keyword, const TokenLoc& loc, else if (mState == State_Name) { // allow keywords to be used as local variable names. MW script compiler, you suck! + if (const Extensions* extensions = getContext().getExtensions()) + { + std::string argumentType; + bool hasExplicit = false; + char returnType; + if (extensions->isFunction(keyword, returnType, argumentType, hasExplicit)) + getErrorHandler().warning("Local variable declaration shadows a function", loc); + } + return parseName(loc.mLiteral, loc, scanner); } else if (mState == State_End) @@ -104,6 +115,7 @@ bool Compiler::DeclarationParser::parseInt(int value, const TokenLoc& loc, Scann if (mState == State_Name) { // Allow integers to be used as variable names + getErrorHandler().warning("Integer is used as a local variable name", loc); return parseName(loc.mLiteral, loc, scanner); } return Parser::parseInt(value, loc, scanner);