public object visitSuperExpr(Expr.Super expr) { if (currentClass != ClassType.SUBCLASS) { Lox.ReportError(expr.keyword, "Can't use 'super' outside of a sub class."); } else { ResolveLocal(expr, expr.keyword.lexeme, AccessType.RHS); } return(null); }
public object visitSuperExpr(Expr.Super expr) { var exprLocationData = locals[expr]; LoxClass superclass = (LoxClass)environment.GetAt(exprLocationData.depth, exprLocationData.index); // We know "this" is one environment removed from "super" because of the way we set the environments up // in visitClassStmt. Hacky fix but it works. We also know its index is 0 because "this" is the only variable // in its environment. LoxInstance instance = (LoxInstance)environment.GetAt(exprLocationData.depth - 1, 0); LoxFunction method = superclass.FindMethod(expr.method.lexeme); if (method == null) { throw new RuntimeError(expr.method, "Undefined superclass property '" + expr.method.lexeme + "'."); } return(method.Bind(instance)); }
public string visitSuperExpr(Expr.Super expr) { throw new NotImplementedException(); }