feat(resolver): add error when re-declaring a variable
This commit is contained in:
@@ -31,7 +31,10 @@ class Resolver(Expr.Visitor[None], Stmt.Visitor[None]):
|
||||
def declare(self, name: Token) -> None:
|
||||
if len(self.scopes) == 0:
|
||||
return
|
||||
self.scopes[-1][name.lexeme] = False
|
||||
scope: dict[str, bool] = self.scopes[-1]
|
||||
if name.lexeme in scope:
|
||||
Pebble.token_error(name, "A variable with this name is already declared in this scope.")
|
||||
scope[name.lexeme] = False
|
||||
|
||||
def define(self, name: Token) -> None:
|
||||
if len(self.scopes) == 0:
|
||||
|
||||
Reference in New Issue
Block a user