@@ -1545,11 +1545,12 @@ function initSearch(rawSearchIndex) {
1545
1545
for ( j = i ; j !== fl ; ++ j ) {
1546
1546
const fnType = fnTypes [ j ] ;
1547
1547
if ( unifyFunctionTypeIsMatchCandidate ( fnType , queryElem , whereClause , mgens ) ) {
1548
+ const mgensScratch = new Map ( mgens ) ;
1548
1549
const simplifiedGenerics = unifyFunctionTypeCheckBindings (
1549
1550
fnType ,
1550
1551
queryElem ,
1551
1552
whereClause ,
1552
- mgens
1553
+ mgensScratch
1553
1554
) ;
1554
1555
if ( simplifiedGenerics ) {
1555
1556
if ( ! fnTypesScratch ) {
@@ -1559,7 +1560,7 @@ function initSearch(rawSearchIndex) {
1559
1560
simplifiedGenerics ,
1560
1561
queryElem . generics ,
1561
1562
whereClause ,
1562
- mgens ,
1563
+ mgensScratch ,
1563
1564
mgensScratch => {
1564
1565
matchCandidates . push ( {
1565
1566
fnTypesScratch,
@@ -1635,7 +1636,7 @@ function initSearch(rawSearchIndex) {
1635
1636
*
1636
1637
* @param {FunctionType } fnType
1637
1638
* @param {QueryElement } queryElem
1638
- * @param {[FunctionType ] } whereClause - Trait bounds for generic items.
1639
+ * @param {[FunctionSearchType ] } whereClause - Trait bounds for generic items.
1639
1640
* @param {Map<number,number>|null } mgensIn - Map functions generics to query generics.
1640
1641
* @returns {boolean }
1641
1642
*/
@@ -1725,10 +1726,11 @@ function initSearch(rawSearchIndex) {
1725
1726
* @param {FunctionType } fnType
1726
1727
* @param {QueryElement } queryElem
1727
1728
* @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.
1729
1731
* @returns {boolean|FunctionType[] }
1730
1732
*/
1731
- function unifyFunctionTypeCheckBindings ( fnType , queryElem , whereClause , mgensIn ) {
1733
+ function unifyFunctionTypeCheckBindings ( fnType , queryElem , whereClause , mgensInout ) {
1732
1734
// Simplify generics now
1733
1735
let simplifiedGenerics = fnType . generics ;
1734
1736
if ( ! simplifiedGenerics ) {
@@ -1738,17 +1740,24 @@ function initSearch(rawSearchIndex) {
1738
1740
return false ;
1739
1741
}
1740
1742
if ( fnType . bindings . size > 0 ) {
1743
+ const mgensResults = new Map ( mgensInout ) ;
1741
1744
for ( const [ name , constraints ] of queryElem . bindings . entries ( ) ) {
1742
1745
if ( ! fnType . bindings . has ( name ) ) {
1743
1746
return false ;
1744
1747
}
1745
1748
// 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 .
1747
1750
if ( ! unifyFunctionTypes (
1748
1751
fnType . bindings . get ( name ) ,
1749
1752
constraints ,
1750
1753
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
+ }
1752
1761
) ) {
1753
1762
return false ;
1754
1763
}
@@ -1766,6 +1775,11 @@ function initSearch(rawSearchIndex) {
1766
1775
} else {
1767
1776
simplifiedGenerics = binds ;
1768
1777
}
1778
+ if ( mgensInout ) {
1779
+ for ( const [ fid , qid ] of mgensResults . entries ( ) ) {
1780
+ mgensInout . set ( fid , qid ) ;
1781
+ }
1782
+ }
1769
1783
}
1770
1784
return simplifiedGenerics ;
1771
1785
}
0 commit comments