Skip to content

Commit

Permalink
fix(zscript): class variables not shadowing global vars properly
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilyV99 authored and connorjclark committed Mar 31, 2024
1 parent 9c5d9ae commit 8d76583
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/parser/SemanticAnalyzer.cpp
Expand Up @@ -1223,8 +1223,26 @@ void SemanticAnalyzer::caseExprIdentifier(
if(host.binding) return; //Skip if already handled
// Bind to named variable.
host.binding = lookupDatum(*scope, host, this);
if(!host.binding && parsing_user_class > puc_vars)
host.binding = lookupClassVars(*scope, host, this);
if(parsing_user_class > puc_vars)
{
bool class_bind = true;
if(host.binding)
{
for(Scope* current = &host.binding->scope; current; current = current->getParent())
{
if(current->isClass())
{
class_bind = false;
break;
}
}
}
if(class_bind)
{
if(UserClassVar* var = lookupClassVars(*scope, host, this))
host.binding = var;
}
}
if (!host.binding)
{
handleError(CompileError::VarUndeclared(&host, host.asString()));
Expand Down

0 comments on commit 8d76583

Please sign in to comment.