Beispiel #1
0
        public object visitReturnStmt(Stmt.Return stmt)
        {
            object value = null;

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

            throw new Return(value);
        }
Beispiel #2
0
        public object 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);
        }