@@ -463,6 +463,16 @@ bool NoEscapeFuncToTypeConversionFailure::diagnoseParameterUse() const {
463
463
auto *locator = getLocator ();
464
464
auto diagnostic = diag::general_noescape_to_escaping;
465
465
466
+ auto getGenericParamType =
467
+ [](TypeVariableType *typeVar) -> GenericTypeParamType * {
468
+ auto *locator = typeVar->getImpl ().getLocator ();
469
+ if (locator->isForGenericParameter ()) {
470
+ const auto &GP = locator->getPath ().back ();
471
+ return GP.getGenericParameter ();
472
+ }
473
+ return nullptr ;
474
+ };
475
+
466
476
ParamDecl *PD = nullptr ;
467
477
if (auto *DRE = dyn_cast<DeclRefExpr>(anchor)) {
468
478
PD = dyn_cast<ParamDecl>(DRE->getDecl ());
@@ -480,17 +490,32 @@ bool NoEscapeFuncToTypeConversionFailure::diagnoseParameterUse() const {
480
490
(path.back ().getKind () == ConstraintLocator::ApplyArgToParam)) {
481
491
if (auto paramType =
482
492
getParameterTypeFor (getRawAnchor (), path.back ().getValue2 ())) {
483
- // If this is a situation when non-escaping parameter is passed
484
- // to the argument which represents generic parameter, there is
485
- // a tailored diagnostic for that.
486
- if (auto *GP = paramType->getAs <GenericTypeParamType>()) {
487
- emitDiagnostic (anchor->getLoc (),
488
- diag::converting_noespace_param_to_generic_type,
489
- PD->getName (), GP->getName ());
490
-
491
- emitDiagnostic (GP->getDecl (),
492
- diag::generic_parameters_always_escaping);
493
- return true ;
493
+ if (paramType->isTypeVariableOrMember ()) {
494
+ auto diagnoseGenericParamFailure = [&](Type genericParam,
495
+ GenericTypeParamDecl *decl) {
496
+ emitDiagnostic (anchor->getLoc (),
497
+ diag::converting_noespace_param_to_generic_type,
498
+ PD->getName (), genericParam);
499
+
500
+ emitDiagnostic (decl, diag::generic_parameters_always_escaping);
501
+ };
502
+
503
+ // If this is a situation when non-escaping parameter is passed
504
+ // to the argument which represents generic parameter, there is
505
+ // a tailored diagnostic for that.
506
+
507
+ if (auto *DMT = paramType->getAs <DependentMemberType>()) {
508
+ auto baseTy = DMT->getBase ()->castTo <TypeVariableType>();
509
+ diagnoseGenericParamFailure (resolveType (DMT),
510
+ getGenericParamType (baseTy)->getDecl ());
511
+ return true ;
512
+ }
513
+
514
+ auto *typeVar = paramType->getAs <TypeVariableType>();
515
+ if (auto *GP = getGenericParamType (typeVar)) {
516
+ diagnoseGenericParamFailure (GP, GP->getDecl ());
517
+ return true ;
518
+ }
494
519
}
495
520
}
496
521
@@ -554,17 +579,7 @@ Type NoEscapeFuncToTypeConversionFailure::getParameterTypeFor(
554
579
555
580
if (auto *fnType = choice->openedType ->getAs <FunctionType>()) {
556
581
const auto ¶m = fnType->getParams ()[paramIdx];
557
-
558
- auto paramType = param.getPlainType ();
559
- if (auto *typeVar = paramType->getAs <TypeVariableType>()) {
560
- auto *locator = typeVar->getImpl ().getLocator ();
561
- if (locator->isForGenericParameter ()) {
562
- const auto &GP = locator->getPath ().back ();
563
- return GP.getGenericParameter ();
564
- }
565
- }
566
-
567
- return paramType;
582
+ return param.getPlainType ();
568
583
}
569
584
570
585
return Type ();
0 commit comments