public object VisitSuperExpr(Super expr) { if (currentClass == ClassType.NONE) { Program.Error(expr.Keyword, "Can't use 'super' outside of a class."); } else if (currentClass != ClassType.SUBCLASS) { Program.Error(expr.Keyword, "Can't use 'super' in a class with no superclass."); } ResolveLocal(expr, expr.Keyword); return(null); }
public object VisitSuperExpr(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(expr.Method.Lexeme); if (method == null) { throw new RuntimeError(expr.Method, "Undefined property '" + expr.Method.Lexeme + "'."); } return(method.Bind(obj)); }
public string VisitSuperExpr(Super expr) { return("super"); }