public object VisitSuperExpr(Super expr) { if (currentClass == ClassType.NONE) { CsLox.Error(expr.Keyword, "Cannot use 'super' outside of a class."); } else if (currentClass != ClassType.SUBCLASS) { CsLox.Error(expr.Keyword, "Cannot 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"); // "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 RuntimeException(expr.Method, $"Undefined property '{expr.Method.Lexeme}'."); } return(method.Bind(@object)); }
public string VisitSuperExpr(Super expr) { throw new System.NotImplementedException(); }