Exemple #1
0
 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);
 }
Exemple #2
0
        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));
        }
Exemple #3
0
 public string Visit(Expr.Super expr)
 {
     throw new NotImplementedException();
 }