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((int)distance, "super"); LoxInstance @object = (LoxInstance)_environment.GetAt((int)distance - 1, "this"); LoxFunction method = superclass.FindMethod(expr.Method.Lexeme); if (method == null) { throw new RuntimeError(expr.Method, $"Undefined method '{expr.Method.Lexeme}'."); } return(method.Bind(@object)); }
public string Visit(Expr.Super expr) { throw new NotImplementedException(); }