public Void Visit(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(Void.Instance); }
object Expr.IVisitor <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 user 'super' in a class with no superclass"); } ResolveLocal(expr, expr.keyword); return(null); }
object Expr.IVisitor <object> .VisitSuperExpr(Expr.Super expr) { int distance = locals[expr]; LoxClass superclass = (LoxClass)environment.GetAt(distance, "super"); LoxInstance obj = (LoxInstance)environment.GetAt(distance - 1, "this"); LoxFunction method = superclass.FindMethod(obj, expr.method.lexeme); if (method == null) { throw new RuntimeError(expr.method, "Undefined property '" + expr.method.lexeme + "'."); } return(method); }