diff --git a/src/array.c b/src/array.c
index 0bfc1e6ff8a24a362492b8aeeb24fa7d740b90d3..3f58f961d58bc0caea107016035313de749d546e 100644
--- a/src/array.c
+++ b/src/array.c
@@ -1068,6 +1068,8 @@ static int obj_or_func_cmp (const struct svalue *a, const struct svalue *b)
     else
       return a->u.object->prog < b->u.object->prog ? -1 : 1;
   }
+  else if (!res)
+    return a_subtype - b_subtype;
 
   return res;
 }