示例#1
0
 public Nothing 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(Nothing.AtAll);
 }
示例#2
0
        public object VisitSuperExpr(Expr.Super expr)
        {
            int      distance   = locals[expr];
            LoxClass superclass = (LoxClass)environment.GetAt(distance, "super");
            // "this" is always one level nearer than "super"'s environment.
            LoxInstance objekt = (LoxInstance)environment.GetAt(distance - 1, "this");
            LoxFunction method = superclass.FindMethod(objekt, expr.Method.Lexeme);

            if (method == null)
            {
                throw new RuntimeError(expr.Method, $"Undefined property '{expr.Method.Lexeme}'.");
            }

            return(method);
        }
示例#3
0
 public string VisitSuperExpr(Expr.Super expr)
 {
     throw new System.NotImplementedException();
 }