You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
mongodb find().sort({a:1}): a user .sort() on a call-result receiver lowers to Array.prototype.sort (comparison function TypeError) #11187
With #11157's fix and #11146 applied to origin/main93a86ff, the mongodb 7.5.0 CRUD fixture (bson 7.3.3, auto-optimize on) connects, and insertMany of 3 documents succeeds. The next call fails:
const found = await collection.find({}).sort({ a: 1 }).toArray();
TypeError: The comparison function must be either a function or undefined: #<Object>
FindCursor.prototype.sort(sort, direction) is a user method. Perry lowers .sort(<object>) on a call-result receiver to Array.prototype.sort, and that throws on the non-function argument.
A {"sort":{"sort":{"a":1}}}
B {"sort":{"sort":{"a":1}}}
Perry (93a86ff + #11157 fix + #11146, perry-dev, Linux x64, PERRY_NO_AUTO_OPTIMIZE=1):
A error The comparison function must be either a function or undefined: #<Object>
B {"sort":{"sort":{"a":1}}}
Binding the receiver to a local first (B) works. Only the chained call-result receiver (A) goes to the array path. The error text comes from the array-sort lowering in crates/perry-hir/src/lower/expr_call/{array_only_methods,local_array_methods,imported_array_methods}.rs. I have not checked which of these takes the call-result receiver.
This does not look related to the #11157 change (HIR class-declaration self-binding). I have not re-run it on a pristine main build.
Activity
changelog: #11199 Array-named methods on unproven receivers (#11187)
fix(hir): an Array-named method on an unproven receiver keeps its own…
changelog: #11199 Array-named methods on unproven receivers (#11187)