@@ -1506,11 +1506,12 @@ function initSearch(rawSearchIndex) {
1506
1506
for ( j = i ; j !== fl ; ++ j ) {
1507
1507
const fnType = fnTypes [ j ] ;
1508
1508
if ( unifyFunctionTypeIsMatchCandidate ( fnType , queryElem , whereClause , mgens ) ) {
1509
+ const mgensScratch = new Map ( mgens ) ;
1509
1510
const simplifiedGenerics = unifyFunctionTypeCheckBindings (
1510
1511
fnType ,
1511
1512
queryElem ,
1512
1513
whereClause ,
1513
- mgens
1514
+ mgensScratch
1514
1515
) ;
1515
1516
if ( simplifiedGenerics ) {
1516
1517
if ( ! fnTypesScratch ) {
@@ -1520,7 +1521,7 @@ function initSearch(rawSearchIndex) {
1520
1521
simplifiedGenerics ,
1521
1522
queryElem . generics ,
1522
1523
whereClause ,
1523
- mgens ,
1524
+ mgensScratch ,
1524
1525
mgensScratch => {
1525
1526
matchCandidates . push ( {
1526
1527
fnTypesScratch,
@@ -1596,7 +1597,7 @@ function initSearch(rawSearchIndex) {
1596
1597
*
1597
1598
* @param {FunctionType } fnType
1598
1599
* @param {QueryElement } queryElem
1599
- * @param {[FunctionType ] } whereClause - Trait bounds for generic items.
1600
+ * @param {[FunctionSearchType ] } whereClause - Trait bounds for generic items.
1600
1601
* @param {Map<number,number>|null } mgensIn - Map functions generics to query generics.
1601
1602
* @returns {boolean }
1602
1603
*/
@@ -1686,10 +1687,11 @@ function initSearch(rawSearchIndex) {
1686
1687
* @param {FunctionType } fnType
1687
1688
* @param {QueryElement } queryElem
1688
1689
* @param {[FunctionType] } whereClause - Trait bounds for generic items.
1689
- * @param {Map<number,number>|null } mgensIn - Map functions generics to query generics.
1690
+ * @param {Map<number,number>|null } mgensInout - Map functions generics to query generics.
1691
+ * Written on success.
1690
1692
* @returns {boolean|FunctionType[] }
1691
1693
*/
1692
- function unifyFunctionTypeCheckBindings ( fnType , queryElem , whereClause , mgensIn ) {
1694
+ function unifyFunctionTypeCheckBindings ( fnType , queryElem , whereClause , mgensInout ) {
1693
1695
// Simplify generics now
1694
1696
let simplifiedGenerics = fnType . generics ;
1695
1697
if ( ! simplifiedGenerics ) {
@@ -1699,17 +1701,24 @@ function initSearch(rawSearchIndex) {
1699
1701
return false ;
1700
1702
}
1701
1703
if ( fnType . bindings . size > 0 ) {
1704
+ const mgensResults = new Map ( mgensInout ) ;
1702
1705
for ( const [ name , constraints ] of queryElem . bindings . entries ( ) ) {
1703
1706
if ( ! fnType . bindings . has ( name ) ) {
1704
1707
return false ;
1705
1708
}
1706
1709
// Since both items must have exactly one entry per name,
1707
- // we don't need to backtrack here.
1710
+ // we don't need to backtrack here, but do need to write mgens .
1708
1711
if ( ! unifyFunctionTypes (
1709
1712
fnType . bindings . get ( name ) ,
1710
1713
constraints ,
1711
1714
whereClause ,
1712
- mgensIn
1715
+ mgensResults ,
1716
+ mgens => {
1717
+ for ( const [ fid , qid ] of mgens . entries ( ) ) {
1718
+ mgensResults . set ( fid , qid ) ;
1719
+ }
1720
+ return true ;
1721
+ }
1713
1722
) ) {
1714
1723
return false ;
1715
1724
}
@@ -1727,6 +1736,11 @@ function initSearch(rawSearchIndex) {
1727
1736
} else {
1728
1737
simplifiedGenerics = binds ;
1729
1738
}
1739
+ if ( mgensInout ) {
1740
+ for ( const [ fid , qid ] of mgensResults . entries ( ) ) {
1741
+ mgensInout . set ( fid , qid ) ;
1742
+ }
1743
+ }
1730
1744
}
1731
1745
return simplifiedGenerics ;
1732
1746
}
0 commit comments