@@ -560,25 +560,37 @@ static bool parameterTypesMatch(const ValueDecl *derivedDecl,
560
560
/* derivedSubs=*/ None);
561
561
562
562
for (auto i : indices (baseParams->getArray ())) {
563
- auto baseItfTy = baseParams->get (i)->getInterfaceType ();
564
- auto baseParamTy =
565
- baseDecl->getAsGenericContext ()->mapTypeIntoContext (baseItfTy);
566
- baseParamTy = baseParamTy.subst (subs);
567
- auto derivedParamTy = derivedParams->get (i)->getInterfaceType ();
563
+ auto *baseParam = baseParams->get (i);
564
+ auto *derivedParam = derivedParams->get (i);
568
565
569
- // Attempt contravariant match.
570
- if (baseParamTy->matchesParameter (derivedParamTy, matchMode))
571
- continue ;
566
+ // Make sure inout-ness and varargs match.
567
+ if (baseParam->isInOut () != derivedParam->isInOut () ||
568
+ baseParam->isVariadic () != derivedParam->isVariadic ()) {
569
+ return false ;
570
+ }
571
+
572
+ auto baseParamTy = baseParam->getInterfaceType ();
573
+ baseParamTy = baseParamTy.subst (subs);
574
+ auto derivedParamTy = derivedParam->getInterfaceType ();
572
575
573
- // Try once more for a match, using the underlying type of an
574
- // IUO if we're allowing that.
575
- if (baseParams->get (i)
576
- ->getAttrs ()
577
- .hasAttribute <ImplicitlyUnwrappedOptionalAttr>() &&
578
- matchMode.contains (TypeMatchFlags::AllowNonOptionalForIUOParam)) {
579
- baseParamTy = baseParamTy->getOptionalObjectType ();
580
- if (baseParamTy->matches (derivedParamTy, matchMode))
576
+ if (baseParam->isInOut () || baseParam->isVariadic ()) {
577
+ // Inout and vararg parameters must match exactly.
578
+ if (baseParamTy->isEqual (derivedParamTy))
581
579
continue ;
580
+ } else {
581
+ // Attempt contravariant match.
582
+ if (baseParamTy->matchesParameter (derivedParamTy, matchMode))
583
+ continue ;
584
+
585
+ // Try once more for a match, using the underlying type of an
586
+ // IUO if we're allowing that.
587
+ if (baseParam->getAttrs ()
588
+ .hasAttribute <ImplicitlyUnwrappedOptionalAttr>() &&
589
+ matchMode.contains (TypeMatchFlags::AllowNonOptionalForIUOParam)) {
590
+ baseParamTy = baseParamTy->getOptionalObjectType ();
591
+ if (baseParamTy->matches (derivedParamTy, matchMode))
592
+ continue ;
593
+ }
582
594
}
583
595
584
596
// If there is no match, then we're done.
0 commit comments