@@ -1615,8 +1615,8 @@ ModuleFile::resolveCrossReference(ModuleDecl *baseModule, uint32_t pathLen) {
1615
1615
pathTrace.addGenericParam (paramIndex);
1616
1616
1617
1617
ValueDecl *base = values.front ();
1618
- GenericParamList *paramList = nullptr ;
1619
1618
1619
+ GenericSignature *currentSig = nullptr ;
1620
1620
if (auto nominal = dyn_cast<NominalTypeDecl>(base)) {
1621
1621
if (genericSig) {
1622
1622
// Find an extension in the requested module that has the
@@ -1625,49 +1625,46 @@ ModuleFile::resolveCrossReference(ModuleDecl *baseModule, uint32_t pathLen) {
1625
1625
if (ext->getModuleContext () == M &&
1626
1626
ext->getGenericSignature ()->getCanonicalSignature ()
1627
1627
== genericSig) {
1628
- paramList = ext->getGenericParams ();
1628
+ currentSig = ext->getGenericSignature ();
1629
1629
break ;
1630
1630
}
1631
1631
}
1632
- assert (paramList && " Couldn't find constrained extension" );
1632
+ assert (currentSig && " Couldn't find constrained extension" );
1633
1633
} else {
1634
1634
// Simple case: use the nominal type's generic parameters.
1635
- paramList = nominal->getGenericParamsOfContext ();
1635
+ currentSig = nominal->getGenericSignature ();
1636
1636
}
1637
1637
} else if (auto alias = dyn_cast<TypeAliasDecl>(base)) {
1638
- paramList = alias->getGenericParams ();
1638
+ currentSig = alias->getGenericSignature ();
1639
1639
} else if (auto fn = dyn_cast<AbstractFunctionDecl>(base)) {
1640
- paramList = fn->getGenericParams ();
1640
+ currentSig = fn->getGenericSignature ();
1641
1641
} else if (auto subscript = dyn_cast<SubscriptDecl>(base)) {
1642
- paramList = subscript->getGenericParams ();
1642
+ currentSig = subscript->getGenericSignature ();
1643
1643
}
1644
1644
1645
- if (!paramList ) {
1645
+ if (!currentSig ) {
1646
1646
return llvm::make_error<XRefError>(
1647
1647
" cross-reference to generic param for non-generic type" ,
1648
1648
pathTrace, getXRefDeclNameForError ());
1649
1649
}
1650
1650
1651
- unsigned currentDepth = paramList-> getDepth () ;
1652
- if (currentDepth < depth ) {
1653
- return llvm::make_error<XRefError>(
1654
- " a containing type has been made non-generic " ,
1655
- pathTrace, getXRefDeclNameForError () );
1656
- }
1657
- while (currentDepth > depth) {
1658
- paramList = paramList-> getOuterParameters () ;
1659
- --currentDepth;
1651
+ bool found = false ;
1652
+ for ( auto paramTy : currentSig-> getGenericParams () ) {
1653
+ if (paramTy-> getIndex () == paramIndex &&
1654
+ paramTy-> getDepth () == depth) {
1655
+ values. clear ( );
1656
+ values. push_back (paramTy-> getDecl ());
1657
+ found = true ;
1658
+ break ;
1659
+ }
1660
1660
}
1661
1661
1662
- if (paramIndex >= paramList-> size () ) {
1662
+ if (!found ) {
1663
1663
return llvm::make_error<XRefError>(
1664
- " generic argument index out of bounds " ,
1664
+ " invalid generic argument index or depth " ,
1665
1665
pathTrace, getXRefDeclNameForError ());
1666
1666
}
1667
1667
1668
- values.clear ();
1669
- values.push_back (paramList->getParams ()[paramIndex]);
1670
- assert (values.back ());
1671
1668
break ;
1672
1669
}
1673
1670
0 commit comments