Fix support for StatsOr and StatsAnd.

Fixes #6062