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