[jlox] Resolve superclasses
This commit is contained in:
@@ -1,10 +1,7 @@
|
||||
package xyz.ctsk.lox;
|
||||
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Stack;
|
||||
import java.util.*;
|
||||
|
||||
public class Resolver implements Expr.Visitor<Void>, Stmt.Visitor<Void> {
|
||||
private final Interpreter interpreter;
|
||||
@@ -91,6 +88,14 @@ public class Resolver implements Expr.Visitor<Void>, Stmt.Visitor<Void> {
|
||||
currentClass = ClassType.CLASS;
|
||||
declare(stmt.name());
|
||||
define(stmt.name());
|
||||
|
||||
if (stmt.superclass() != null) {
|
||||
if (stmt.name().lexeme().equals(stmt.superclass().name().lexeme())) {
|
||||
Lox.error(stmt.superclass().name(), "A class can't inherit from itself.");
|
||||
}
|
||||
resolve(stmt.superclass());
|
||||
}
|
||||
|
||||
beginScope();
|
||||
scopes.peek().put("this", true);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user