Пример #1
0
        public Nothing VisitReturnStmt(Stmt.Return stmt)
        {
            object value = null;

            if (stmt.Value != null)
            {
                value = Evaluate(stmt.Value);
            }

            throw new Return(value);
        }
Пример #2
0
        public Nothing VisitReturnStmt(Stmt.Return stmt)
        {
            if (currentFunction == FunctionType.None)
            {
                Lox.Error(stmt.Keyword, "Cannot return from top level code.");
            }
            if (stmt.Value != null)
            {
                if (currentFunction == FunctionType.Initializer)
                {
                    Lox.Error(stmt.Keyword, "Cannot return a value from an initializer.");
                }

                Resolve(stmt.Value);
            }
            return(Nothing.AtAll);
        }