@@ -1545,11 +1545,12 @@ function initSearch(rawSearchIndex) {
15451545 for ( j = i ; j !== fl ; ++ j ) {
15461546 const fnType = fnTypes [ j ] ;
15471547 if ( unifyFunctionTypeIsMatchCandidate ( fnType , queryElem , whereClause , mgens ) ) {
1548+ const mgensScratch = new Map ( mgens ) ;
15481549 const simplifiedGenerics = unifyFunctionTypeCheckBindings (
15491550 fnType ,
15501551 queryElem ,
15511552 whereClause ,
1552- mgens
1553+ mgensScratch
15531554 ) ;
15541555 if ( simplifiedGenerics ) {
15551556 if ( ! fnTypesScratch ) {
@@ -1559,7 +1560,7 @@ function initSearch(rawSearchIndex) {
15591560 simplifiedGenerics ,
15601561 queryElem . generics ,
15611562 whereClause ,
1562- mgens ,
1563+ mgensScratch ,
15631564 mgensScratch => {
15641565 matchCandidates . push ( {
15651566 fnTypesScratch,
@@ -1635,7 +1636,7 @@ function initSearch(rawSearchIndex) {
16351636 *
16361637 * @param {FunctionType } fnType
16371638 * @param {QueryElement } queryElem
1638- * @param {[FunctionType ] } whereClause - Trait bounds for generic items.
1639+ * @param {[FunctionSearchType ] } whereClause - Trait bounds for generic items.
16391640 * @param {Map<number,number>|null } mgensIn - Map functions generics to query generics.
16401641 * @returns {boolean }
16411642 */
@@ -1725,10 +1726,11 @@ function initSearch(rawSearchIndex) {
17251726 * @param {FunctionType } fnType
17261727 * @param {QueryElement } queryElem
17271728 * @param {[FunctionType] } whereClause - Trait bounds for generic items.
1728- * @param {Map<number,number>|null } mgensIn - Map functions generics to query generics.
1729+ * @param {Map<number,number>|null } mgensInout - Map functions generics to query generics.
1730+ * Written on success.
17291731 * @returns {boolean|FunctionType[] }
17301732 */
1731- function unifyFunctionTypeCheckBindings ( fnType , queryElem , whereClause , mgensIn ) {
1733+ function unifyFunctionTypeCheckBindings ( fnType , queryElem , whereClause , mgensInout ) {
17321734 // Simplify generics now
17331735 let simplifiedGenerics = fnType . generics ;
17341736 if ( ! simplifiedGenerics ) {
@@ -1738,17 +1740,24 @@ function initSearch(rawSearchIndex) {
17381740 return false ;
17391741 }
17401742 if ( fnType . bindings . size > 0 ) {
1743+ const mgensResults = new Map ( mgensInout ) ;
17411744 for ( const [ name , constraints ] of queryElem . bindings . entries ( ) ) {
17421745 if ( ! fnType . bindings . has ( name ) ) {
17431746 return false ;
17441747 }
17451748 // Since both items must have exactly one entry per name,
1746- // we don't need to backtrack here.
1749+ // we don't need to backtrack here, but do need to write mgens .
17471750 if ( ! unifyFunctionTypes (
17481751 fnType . bindings . get ( name ) ,
17491752 constraints ,
17501753 whereClause ,
1751- mgensIn
1754+ mgensResults ,
1755+ mgens => {
1756+ for ( const [ fid , qid ] of mgens . entries ( ) ) {
1757+ mgensResults . set ( fid , qid ) ;
1758+ }
1759+ return true ;
1760+ }
17521761 ) ) {
17531762 return false ;
17541763 }
@@ -1766,6 +1775,11 @@ function initSearch(rawSearchIndex) {
17661775 } else {
17671776 simplifiedGenerics = binds ;
17681777 }
1778+ if ( mgensInout ) {
1779+ for ( const [ fid , qid ] of mgensResults . entries ( ) ) {
1780+ mgensInout . set ( fid , qid ) ;
1781+ }
1782+ }
17691783 }
17701784 return simplifiedGenerics ;
17711785 }
0 commit comments