@@ -1529,57 +1529,48 @@ void Type::accept(IValVisitor* visitor, void* extra)
1529
1529
1530
1530
RefPtr<Val> DeclaredSubtypeWitness::SubstituteImpl (Substitutions* subst, int * ioDiff)
1531
1531
{
1532
- DeclRef<GenericTypeParamDecl> genParamDeclRef;
1533
- if (auto subDeclRefType = this ->sub .As <DeclRefType>())
1532
+ if (auto genConstraintDecl = declRef.As <GenericTypeConstraintDecl>())
1534
1533
{
1535
- genParamDeclRef = subDeclRefType->declRef .As <GenericTypeParamDecl>();
1536
- }
1537
- if (!genParamDeclRef)
1538
- return this ;
1539
- auto genParamDecl = genParamDeclRef.getDecl ();
1540
- // search for a substitution that might apply to us
1541
- for (auto s = subst; s; s = s->outer .Ptr ())
1542
- {
1543
- if (auto genericSubst = dynamic_cast <GenericSubstitution*>(s))
1534
+ // search for a substitution that might apply to us
1535
+ for (auto s = subst; s; s = s->outer .Ptr ())
1544
1536
{
1545
- // the generic decl associated with the substitution list must be
1546
- // the generic decl that declared this parameter
1547
- auto genericDecl = genericSubst->genericDecl ;
1548
- if (genericDecl != genParamDecl->ParentDecl )
1549
- continue ;
1550
- bool found = false ;
1551
- int index = 0 ;
1552
- for (auto m : genericDecl->Members )
1537
+ if (auto genericSubst = dynamic_cast <GenericSubstitution*>(s))
1553
1538
{
1554
- if (m.Ptr () == genParamDecl)
1555
- {
1556
- // We've found it, so return the corresponding specialization argument
1557
- (*ioDiff)++;
1558
- found = true ;
1559
- break ;
1560
- }
1561
- else if (auto typeParam = m.As <GenericTypeParamDecl>())
1562
- {
1563
- index ++;
1564
- }
1565
- else if (auto valParam = m.As <GenericValueParamDecl>())
1539
+ // the generic decl associated with the substitution list must be
1540
+ // the generic decl that declared this parameter
1541
+ auto genericDecl = genericSubst->genericDecl ;
1542
+ if (genericDecl != genConstraintDecl.getDecl ()->ParentDecl )
1543
+ continue ;
1544
+ bool found = false ;
1545
+ UInt index = 0 ;
1546
+ for (auto m : genericDecl->Members )
1566
1547
{
1567
- index ++;
1548
+ if (auto constraintParam = m.As <GenericTypeConstraintDecl>())
1549
+ {
1550
+ if (constraintParam.Ptr () == declRef.getDecl ())
1551
+ {
1552
+ found = true ;
1553
+ break ;
1554
+ }
1555
+ index ++;
1556
+ }
1568
1557
}
1569
- else
1558
+ if (found)
1570
1559
{
1560
+ (*ioDiff)++;
1561
+ auto ordinaryParamCount = genericDecl->getMembersOfType <GenericTypeParamDecl>().Count () +
1562
+ genericDecl->getMembersOfType <GenericValueParamDecl>().Count ();
1563
+ SLANG_ASSERT (index + ordinaryParamCount < genericSubst->args .Count ());
1564
+ return genericSubst->args [index + ordinaryParamCount];
1571
1565
}
1572
1566
}
1573
- if (found)
1574
- {
1575
- auto ordinaryParamCount = genericDecl->getMembersOfType <GenericTypeParamDecl>().Count () +
1576
- genericDecl->getMembersOfType <GenericValueParamDecl>().Count ();
1577
- SLANG_ASSERT (ordinaryParamCount + index < genericSubst->args .Count ());
1578
- return genericSubst->args [ordinaryParamCount + index ];
1579
- }
1580
1567
}
1581
1568
}
1582
- return this ;
1569
+ RefPtr<DeclaredSubtypeWitness> rs = new DeclaredSubtypeWitness ();
1570
+ rs->sub = sub->SubstituteImpl (subst, ioDiff).As <Type>();
1571
+ rs->sup = sup->SubstituteImpl (subst, ioDiff).As <Type>();
1572
+ rs->declRef = declRef.SubstituteImpl (subst, ioDiff);
1573
+ return rs;
1583
1574
}
1584
1575
1585
1576
String DeclaredSubtypeWitness::ToString ()
0 commit comments