You are right, I was misled by this:
for (const TileLayer *comparedTileLayer : listYes) {
if (!comparedTileLayer->contains(x, y))
return false;
My bad, I thought contains would fail if the layer contained a zero tile at (x,y), but it only checks map bounds.