public Void Visit_ReturnStmt(ReturnStmt stmt) { Object value = null; if (stmt.value != null) { value = Evaluate(stmt.value); } throw new Return(value); }
public Void Visit_ReturnStmt(ReturnStmt stmt) { if (_currentFunctionType == FunctionType.None) { _errors.Add(new Error(stmt.keyword, ErrorType.InvalidReturnUsage, "Cannot return from top-level code.")); } if (stmt.value != null) { if (_currentFunctionType == FunctionType.Initializer) { _errors.Add(new Error(stmt.keyword, ErrorType.InvalidReturnUsage, "Can't use 'return' inside a constructor")); } Resolve(stmt.value); } return(null); }
public object VisitReturnStmt(ReturnStmt stmt) { if (_currentFuncType == FunctionType.NONE) { Lox.Error(stmt.Keyword, "Cannot return from top-level code."); } if (stmt.Value != null) { if (_currentFuncType == FunctionType.INITIALIZER) { Lox.Error(stmt.Keyword, "Cannot return a value from an initializer."); } Resolve(stmt.Value); } return(null); }
public object VisitReturnStmt(ReturnStmt stmt) { throw new Return(stmt.Value != null ? Evaluate(stmt.Value) : null); }
public string Visit_ReturnStmt(ReturnStmt stmt) { return(Parenthesize("Return", stmt.value)); }