Compile path ignored as soon as I add functions to the compiler

As soon as I add a custom function to my Volt compiler in services.php, for some reason my PHP files stop compiling to my /cache/ directory, and instead compile to the same directory as the volt files. What is the reason for this?

This is the relevant code in my services.php:

$view->registerEngines([
    '.volt' => function ($view) {
        $config = $this->getConfig();

        $volt = new VoltEngine($view, $this);

        // Adding these two lines breaks where my code compiles
        $compiler = $volt->getCompiler();
        $compiler->addFunction('get_object_vars', 'get_object_vars');

        $volt->setOptions([
            'compiledPath' => $config->application->cacheDir,
            'compiledSeparator' => '_'
        ]);

        return $volt;
    }
]);

Move

$compiler = $volt->getCompiler();
$compiler->addFunction('get_object_vars', 'get_object_vars');

after

$volt->setOptions([
  'compiledPath' => $config->application->cacheDir,
  'compiledSeparator' => '_'
]);