@@ -555,19 +555,8 @@ bool NoEscapeFuncToTypeConversionFailure::diagnoseParameterUse() const {
555
555
return false ;
556
556
557
557
auto *anchor = getAnchor ();
558
- auto *locator = getLocator ();
559
558
auto diagnostic = diag::general_noescape_to_escaping;
560
559
561
- auto getGenericParamType =
562
- [](TypeVariableType *typeVar) -> GenericTypeParamType * {
563
- auto *locator = typeVar->getImpl ().getLocator ();
564
- if (locator->isForGenericParameter ()) {
565
- const auto &GP = locator->getPath ().back ();
566
- return GP.getGenericParameter ();
567
- }
568
- return nullptr ;
569
- };
570
-
571
560
ParamDecl *PD = nullptr ;
572
561
if (auto *DRE = dyn_cast<DeclRefExpr>(anchor)) {
573
562
PD = dyn_cast<ParamDecl>(DRE->getDecl ());
@@ -580,37 +569,29 @@ bool NoEscapeFuncToTypeConversionFailure::diagnoseParameterUse() const {
580
569
// Let's check whether this is a function parameter passed
581
570
// as an argument to another function which accepts @escaping
582
571
// function at that position.
583
- auto path = locator->getPath ();
584
- if (!path.empty () &&
585
- (path.back ().getKind () == ConstraintLocator::ApplyArgToParam)) {
586
- if (auto paramType =
587
- getParameterTypeFor (getRawAnchor (), path.back ().getValue2 ())) {
588
- if (paramType->isTypeVariableOrMember ()) {
589
- auto diagnoseGenericParamFailure = [&](Type genericParam,
590
- GenericTypeParamDecl *decl) {
591
- emitDiagnostic (anchor->getLoc (),
592
- diag::converting_noespace_param_to_generic_type,
593
- PD->getName (), genericParam);
594
-
595
- emitDiagnostic (decl, diag::generic_parameters_always_escaping);
596
- };
597
-
598
- // If this is a situation when non-escaping parameter is passed
599
- // to the argument which represents generic parameter, there is
600
- // a tailored diagnostic for that.
601
-
602
- if (auto *DMT = paramType->getAs <DependentMemberType>()) {
603
- auto baseTy = DMT->getBase ()->castTo <TypeVariableType>();
604
- diagnoseGenericParamFailure (resolveType (DMT),
605
- getGenericParamType (baseTy)->getDecl ());
606
- return true ;
607
- }
572
+ if (auto argApplyInfo = getFunctionArgApplyInfo (getLocator ())) {
573
+ auto paramInterfaceTy = argApplyInfo->getParamInterfaceType ();
574
+ if (paramInterfaceTy->isTypeParameter ()) {
575
+ auto diagnoseGenericParamFailure = [&](GenericTypeParamDecl *decl) {
576
+ emitDiagnostic (anchor->getLoc (),
577
+ diag::converting_noespace_param_to_generic_type,
578
+ PD->getName (), paramInterfaceTy);
579
+
580
+ emitDiagnostic (decl, diag::generic_parameters_always_escaping);
581
+ };
582
+
583
+ // If this is a situation when non-escaping parameter is passed
584
+ // to the argument which represents generic parameter, there is
585
+ // a tailored diagnostic for that.
586
+
587
+ if (auto *DMT = paramInterfaceTy->getAs <DependentMemberType>()) {
588
+ diagnoseGenericParamFailure (DMT->getRootGenericParam ()->getDecl ());
589
+ return true ;
590
+ }
608
591
609
- auto *typeVar = paramType->getAs <TypeVariableType>();
610
- if (auto *GP = getGenericParamType (typeVar)) {
611
- diagnoseGenericParamFailure (GP, GP->getDecl ());
612
- return true ;
613
- }
592
+ if (auto *GP = paramInterfaceTy->getAs <GenericTypeParamType>()) {
593
+ diagnoseGenericParamFailure (GP->getDecl ());
594
+ return true ;
614
595
}
615
596
}
616
597
@@ -641,20 +622,6 @@ bool NoEscapeFuncToTypeConversionFailure::diagnoseParameterUse() const {
641
622
return true ;
642
623
}
643
624
644
- Type NoEscapeFuncToTypeConversionFailure::getParameterTypeFor (
645
- Expr *expr, unsigned paramIdx) const {
646
- auto choice = getChoiceFor (expr);
647
- if (!choice)
648
- return Type ();
649
-
650
- if (auto *fnType = choice->openedType ->getAs <FunctionType>()) {
651
- const auto ¶m = fnType->getParams ()[paramIdx];
652
- return param.getPlainType ();
653
- }
654
-
655
- return Type ();
656
- }
657
-
658
625
bool MissingForcedDowncastFailure::diagnoseAsError () {
659
626
if (hasComplexLocator ())
660
627
return false ;
0 commit comments