Esempio n. 1
0
        public MyVoid VisitReturnStmt(Stmt.Return stmt)
        {
            object value = null;

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

            throw new Return(value);
        }
        public MyVoid 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(null);
        }