public object visitSuperExpr(Expr.Super expr) { if (currentClass == ClassType.NONE) { Lox.error(expr.keyword, "Cannot use 'super' outside of a class."); } else if (currentClass != ClassType.SUBCLASS) { Lox.error(expr.keyword, "Cannot use 'super' in a class with no superclass."); } resolveLocal(expr, expr.keyword); return(null); }
public object visitSuperExpr(Expr.Super expr) { int distance = locals[expr]; LoxClass superclass = (LoxClass)environment.getAt(distance, "super"); // "this" is always one level nearer than "super"'s environment LoxInstance object_ = (LoxInstance)environment.getAt(distance - 1, "this"); LoxFunction method = superclass.findMethod(expr.method.lexeme); if (method == null) { throw new RuntimeError(expr.method, "Undefined property '" + expr.method.lexeme + "'."); } return(method.bind(object_)); }
public string visitSuperExpr(Expr.Super expr) { return(""); }