@@ -343,15 +343,26 @@ static void highlightOffendingType(InFlightDiagnostic &diag,
343
343
// / Emit a note on \p limitImport when it restricted the access level
344
344
// / of a type.
345
345
static void noteLimitingImport (ASTContext &ctx,
346
- const ImportAccessLevel limitImport) {
346
+ const ImportAccessLevel limitImport,
347
+ const TypeRepr *complainRepr) {
347
348
if (!limitImport.has_value ())
348
349
return ;
349
350
350
351
assert (limitImport->accessLevel != AccessLevel::Public &&
351
352
" a public import shouldn't limit the access level of a decl" );
352
- ctx.Diags .diagnose (limitImport->accessLevelLoc , diag::module_imported_here,
353
- limitImport->module .importedModule ->getName (),
354
- limitImport->accessLevel );
353
+
354
+ if (auto ITR = dyn_cast_or_null<IdentTypeRepr>(complainRepr)) {
355
+ const ValueDecl *VD = ITR->getBoundDecl ();
356
+ ctx.Diags .diagnose (limitImport->accessLevelLoc , diag::decl_import_via_here,
357
+ DescriptiveDeclKind::Type,
358
+ VD->getName (),
359
+ limitImport->accessLevel ,
360
+ limitImport->module .importedModule ->getName ());
361
+ } else {
362
+ ctx.Diags .diagnose (limitImport->accessLevelLoc , diag::module_imported_here,
363
+ limitImport->module .importedModule ->getName (),
364
+ limitImport->accessLevel );
365
+ }
355
366
}
356
367
357
368
void AccessControlCheckerBase::checkGenericParamAccess (
@@ -435,7 +446,7 @@ void AccessControlCheckerBase::checkGenericParamAccess(
435
446
Context.Diags .diagnose (ownerDecl, diagID, ownerDecl->getDescriptiveKind (),
436
447
accessControlErrorKind == ACEK::Requirement);
437
448
highlightOffendingType (diag, complainRepr);
438
- noteLimitingImport (Context, minImportLimit);
449
+ noteLimitingImport (Context, minImportLimit, complainRepr );
439
450
return ;
440
451
}
441
452
@@ -450,7 +461,7 @@ void AccessControlCheckerBase::checkGenericParamAccess(
450
461
contextAccess, minDiagAccessLevel, isa<FileUnit>(DC),
451
462
accessControlErrorKind == ACEK::Requirement);
452
463
highlightOffendingType (diag, complainRepr);
453
- noteLimitingImport (Context, minImportLimit);
464
+ noteLimitingImport (Context, minImportLimit, complainRepr );
454
465
}
455
466
456
467
void AccessControlCheckerBase::checkGenericParamAccess (
@@ -483,7 +494,7 @@ void AccessControlCheckerBase::checkGlobalActorAccess(const Decl *D) {
483
494
auto diag = D->diagnose (diag::global_actor_not_usable_from_inline,
484
495
D->getDescriptiveKind (), VD->getName ());
485
496
highlightOffendingType (diag, complainRepr);
486
- noteLimitingImport (D->getASTContext (), importLimit);
497
+ noteLimitingImport (D->getASTContext (), importLimit, complainRepr );
487
498
return ;
488
499
}
489
500
@@ -495,7 +506,7 @@ void AccessControlCheckerBase::checkGlobalActorAccess(const Decl *D) {
495
506
D->getDescriptiveKind (), VD->getName (),
496
507
diagAccessLevel, globalActorDecl->getName ());
497
508
highlightOffendingType (diag, complainRepr);
498
- noteLimitingImport (D->getASTContext (), importLimit);
509
+ noteLimitingImport (D->getASTContext (), importLimit, complainRepr );
499
510
});
500
511
}
501
512
@@ -576,12 +587,11 @@ class AccessControlChecker : public AccessControlCheckerBase,
576
587
if (downgradeToWarning == DowngradeToWarning::Yes)
577
588
diagID = diag::pattern_type_access_inferred_warn;
578
589
auto &DE = theVar->getASTContext ().Diags ;
579
- auto diag = DE.diagnose (NP->getLoc (), diagID, theVar->isLet (),
580
- isTypeContext, isExplicit, theVarAccess,
581
- isa<FileUnit>(theVar->getDeclContext ()),
582
- diagAccessLevel, theVar->getInterfaceType ());
583
- diag.flush ();
584
- noteLimitingImport (theVar->getASTContext (), importLimit);
590
+ DE.diagnose (NP->getLoc (), diagID, theVar->isLet (),
591
+ isTypeContext, isExplicit, theVarAccess,
592
+ isa<FileUnit>(theVar->getDeclContext ()),
593
+ diagAccessLevel, theVar->getInterfaceType ());
594
+ noteLimitingImport (theVar->getASTContext (), importLimit, complainRepr);
585
595
});
586
596
}
587
597
@@ -616,7 +626,7 @@ class AccessControlChecker : public AccessControlCheckerBase,
616
626
anyVarAccess, isa<FileUnit>(anyVar->getDeclContext ()),
617
627
diagAccessLevel);
618
628
highlightOffendingType (diag, complainRepr);
619
- noteLimitingImport (anyVar->getASTContext (), importLimit);
629
+ noteLimitingImport (anyVar->getASTContext (), importLimit, complainRepr );
620
630
});
621
631
622
632
// Check the property wrapper types.
@@ -642,7 +652,7 @@ class AccessControlChecker : public AccessControlCheckerBase,
642
652
isa<FileUnit>(anyVar->getDeclContext ()),
643
653
diagAccessLevel);
644
654
highlightOffendingType (diag, complainRepr);
645
- noteLimitingImport (anyVar->getASTContext (), importLimit);
655
+ noteLimitingImport (anyVar->getASTContext (), importLimit, complainRepr );
646
656
});
647
657
}
648
658
}
@@ -692,7 +702,7 @@ class AccessControlChecker : public AccessControlCheckerBase,
692
702
diagAccessLevel,
693
703
isa<FileUnit>(TAD->getDeclContext ()));
694
704
highlightOffendingType (diag, complainRepr);
695
- noteLimitingImport (TAD->getASTContext (), importLimit);
705
+ noteLimitingImport (TAD->getASTContext (), importLimit, complainRepr );
696
706
});
697
707
}
698
708
@@ -787,7 +797,8 @@ class AccessControlChecker : public AccessControlCheckerBase,
787
797
minDiagAccessLevel,
788
798
accessControlErrorKind);
789
799
highlightOffendingType (diag, complainRepr);
790
- noteLimitingImport (assocType->getASTContext (), minImportLimit);
800
+ noteLimitingImport (assocType->getASTContext (), minImportLimit,
801
+ complainRepr);
791
802
}
792
803
}
793
804
@@ -823,7 +834,7 @@ class AccessControlChecker : public AccessControlCheckerBase,
823
834
diagAccessLevel,
824
835
isa<FileUnit>(ED->getDeclContext ()));
825
836
highlightOffendingType (diag, complainRepr);
826
- noteLimitingImport (ED->getASTContext (), importLimit);
837
+ noteLimitingImport (ED->getASTContext (), importLimit, complainRepr );
827
838
});
828
839
}
829
840
}
@@ -885,7 +896,7 @@ class AccessControlChecker : public AccessControlCheckerBase,
885
896
isa<FileUnit>(CD->getDeclContext ()),
886
897
superclassLocIter->getTypeRepr () != complainRepr);
887
898
highlightOffendingType (diag, complainRepr);
888
- noteLimitingImport (CD->getASTContext (), importLimit);
899
+ noteLimitingImport (CD->getASTContext (), importLimit, complainRepr );
889
900
});
890
901
}
891
902
}
@@ -988,7 +999,7 @@ class AccessControlChecker : public AccessControlCheckerBase,
988
999
protocolControlErrorKind, minDiagAccessLevel,
989
1000
isa<FileUnit>(proto->getDeclContext ()), declKind);
990
1001
highlightOffendingType (diag, complainRepr);
991
- noteLimitingImport (proto->getASTContext (), minImportLimit);
1002
+ noteLimitingImport (proto->getASTContext (), minImportLimit, complainRepr );
992
1003
}
993
1004
}
994
1005
@@ -1052,7 +1063,7 @@ class AccessControlChecker : public AccessControlCheckerBase,
1052
1063
auto diag = SD->diagnose (diagID, isExplicit, subscriptDeclAccess,
1053
1064
minDiagAccessLevel, problemIsElement);
1054
1065
highlightOffendingType (diag, complainRepr);
1055
- noteLimitingImport (SD->getASTContext (), minImportLimit);
1066
+ noteLimitingImport (SD->getASTContext (), minImportLimit, complainRepr );
1056
1067
}
1057
1068
}
1058
1069
@@ -1159,7 +1170,7 @@ class AccessControlChecker : public AccessControlCheckerBase,
1159
1170
functionKind, problemIsResult,
1160
1171
hasInaccessibleParameterWrapper);
1161
1172
highlightOffendingType (diag, complainRepr);
1162
- noteLimitingImport (fn->getASTContext (), minImportLimit);
1173
+ noteLimitingImport (fn->getASTContext (), minImportLimit, complainRepr );
1163
1174
}
1164
1175
}
1165
1176
@@ -1178,7 +1189,8 @@ class AccessControlChecker : public AccessControlCheckerBase,
1178
1189
auto diag =
1179
1190
EED->diagnose (diagID, EED->getFormalAccess (), diagAccessLevel);
1180
1191
highlightOffendingType (diag, complainRepr);
1181
- noteLimitingImport (EED->getASTContext (), importLimit);
1192
+ noteLimitingImport (EED->getASTContext (), importLimit,
1193
+ complainRepr);
1182
1194
});
1183
1195
}
1184
1196
}
@@ -1244,7 +1256,7 @@ class AccessControlChecker : public AccessControlCheckerBase,
1244
1256
auto diag = MD->diagnose (diagID, isExplicit, macroDeclAccess,
1245
1257
minDiagAccessLevel, problemIsResult);
1246
1258
highlightOffendingType (diag, complainRepr);
1247
- noteLimitingImport (MD->getASTContext (), minImportLimit);
1259
+ noteLimitingImport (MD->getASTContext (), minImportLimit, complainRepr );
1248
1260
}
1249
1261
}
1250
1262
};
@@ -1353,7 +1365,8 @@ class UsableFromInlineChecker : public AccessControlCheckerBase,
1353
1365
}
1354
1366
Ctx.Diags .diagnose (NP->getLoc (), diagID, theVar->isLet (),
1355
1367
isTypeContext, theVar->getInterfaceType ());
1356
- noteLimitingImport (theVar->getASTContext (), importLimit);
1368
+ noteLimitingImport (theVar->getASTContext (), importLimit,
1369
+ complainRepr);
1357
1370
});
1358
1371
}
1359
1372
@@ -1392,7 +1405,8 @@ class UsableFromInlineChecker : public AccessControlCheckerBase,
1392
1405
auto diag = Ctx.Diags .diagnose (TP->getLoc (), diagID, anyVar->isLet (),
1393
1406
isTypeContext);
1394
1407
highlightOffendingType (diag, complainRepr);
1395
- noteLimitingImport (anyVar->getASTContext (), importLimit);
1408
+ noteLimitingImport (anyVar->getASTContext (), importLimit,
1409
+ complainRepr);
1396
1410
});
1397
1411
1398
1412
for (auto attr : anyVar->getAttachedPropertyWrappers ()) {
@@ -1403,12 +1417,13 @@ class UsableFromInlineChecker : public AccessControlCheckerBase,
1403
1417
[&](AccessScope typeAccessScope,
1404
1418
const TypeRepr *complainRepr,
1405
1419
DowngradeToWarning downgradeToWarning,
1406
- ImportAccessLevel importLimit, AccessLevel diagAccessLevel) {
1420
+ ImportAccessLevel importLimit,
1421
+ AccessLevel diagAccessLevel) {
1407
1422
auto diag = anyVar->diagnose (
1408
1423
diag::property_wrapper_type_not_usable_from_inline,
1409
1424
anyVar->isLet (), isTypeContext);
1410
1425
highlightOffendingType (diag, complainRepr);
1411
- noteLimitingImport (anyVar->getASTContext (), importLimit);
1426
+ noteLimitingImport (anyVar->getASTContext (), importLimit, complainRepr );
1412
1427
});
1413
1428
}
1414
1429
}
@@ -1447,7 +1462,7 @@ class UsableFromInlineChecker : public AccessControlCheckerBase,
1447
1462
diagID = diag::type_alias_underlying_type_not_usable_from_inline_warn;
1448
1463
auto diag = TAD->diagnose (diagID);
1449
1464
highlightOffendingType (diag, complainRepr);
1450
- noteLimitingImport (TAD->getASTContext (), importLimit);
1465
+ noteLimitingImport (TAD->getASTContext (), importLimit, complainRepr );
1451
1466
});
1452
1467
}
1453
1468
@@ -1471,7 +1486,8 @@ class UsableFromInlineChecker : public AccessControlCheckerBase,
1471
1486
diagID = diag::associated_type_not_usable_from_inline_warn;
1472
1487
auto diag = assocType->diagnose (diagID, ACEK_Requirement);
1473
1488
highlightOffendingType (diag, complainRepr);
1474
- noteLimitingImport (assocType->getASTContext (), importLimit);
1489
+ noteLimitingImport (assocType->getASTContext (), importLimit,
1490
+ complainRepr);
1475
1491
});
1476
1492
});
1477
1493
checkTypeAccess (assocType->getDefaultDefinitionType (),
@@ -1487,7 +1503,8 @@ class UsableFromInlineChecker : public AccessControlCheckerBase,
1487
1503
diagID = diag::associated_type_not_usable_from_inline_warn;
1488
1504
auto diag = assocType->diagnose (diagID, ACEK_DefaultDefinition);
1489
1505
highlightOffendingType (diag, complainRepr);
1490
- noteLimitingImport (assocType->getASTContext (), importLimit);
1506
+ noteLimitingImport (assocType->getASTContext (), importLimit,
1507
+ complainRepr);
1491
1508
});
1492
1509
1493
1510
if (assocType->getTrailingWhereClause ()) {
@@ -1506,7 +1523,8 @@ class UsableFromInlineChecker : public AccessControlCheckerBase,
1506
1523
diagID = diag::associated_type_not_usable_from_inline_warn;
1507
1524
auto diag = assocType->diagnose (diagID, ACEK_Requirement);
1508
1525
highlightOffendingType (diag, complainRepr);
1509
- noteLimitingImport (assocType->getASTContext (), importLimit);
1526
+ noteLimitingImport (assocType->getASTContext (), importLimit,
1527
+ complainRepr);
1510
1528
});
1511
1529
}
1512
1530
}
@@ -1537,7 +1555,7 @@ class UsableFromInlineChecker : public AccessControlCheckerBase,
1537
1555
diagID = diag::enum_raw_type_not_usable_from_inline_warn;
1538
1556
auto diag = ED->diagnose (diagID);
1539
1557
highlightOffendingType (diag, complainRepr);
1540
- noteLimitingImport (ED->getASTContext (), importLimit);
1558
+ noteLimitingImport (ED->getASTContext (), importLimit, complainRepr );
1541
1559
});
1542
1560
}
1543
1561
}
@@ -1583,7 +1601,7 @@ class UsableFromInlineChecker : public AccessControlCheckerBase,
1583
1601
auto diag = CD->diagnose (diagID, superclassLocIter->getTypeRepr () !=
1584
1602
complainRepr);
1585
1603
highlightOffendingType (diag, complainRepr);
1586
- noteLimitingImport (CD->getASTContext (), importLimit);
1604
+ noteLimitingImport (CD->getASTContext (), importLimit, complainRepr );
1587
1605
});
1588
1606
}
1589
1607
}
@@ -1609,7 +1627,7 @@ class UsableFromInlineChecker : public AccessControlCheckerBase,
1609
1627
diagID = diag::protocol_usable_from_inline_warn;
1610
1628
auto diag = proto->diagnose (diagID, PCEK_Refine);
1611
1629
highlightOffendingType (diag, complainRepr);
1612
- noteLimitingImport (proto->getASTContext (), importLimit);
1630
+ noteLimitingImport (proto->getASTContext (), importLimit, complainRepr );
1613
1631
});
1614
1632
});
1615
1633
@@ -1629,7 +1647,7 @@ class UsableFromInlineChecker : public AccessControlCheckerBase,
1629
1647
diagID = diag::protocol_usable_from_inline_warn;
1630
1648
auto diag = proto->diagnose (diagID, PCEK_Requirement);
1631
1649
highlightOffendingType (diag, complainRepr);
1632
- noteLimitingImport (proto->getASTContext (), importLimit);
1650
+ noteLimitingImport (proto->getASTContext (), importLimit, complainRepr );
1633
1651
});
1634
1652
}
1635
1653
}
@@ -1649,7 +1667,7 @@ class UsableFromInlineChecker : public AccessControlCheckerBase,
1649
1667
diagID = diag::subscript_type_usable_from_inline_warn;
1650
1668
auto diag = SD->diagnose (diagID, /* problemIsElement=*/ false );
1651
1669
highlightOffendingType (diag, complainRepr);
1652
- noteLimitingImport (SD->getASTContext (), importLimit);
1670
+ noteLimitingImport (SD->getASTContext (), importLimit, complainRepr );
1653
1671
});
1654
1672
}
1655
1673
@@ -1665,7 +1683,7 @@ class UsableFromInlineChecker : public AccessControlCheckerBase,
1665
1683
diagID = diag::subscript_type_usable_from_inline_warn;
1666
1684
auto diag = SD->diagnose (diagID, /* problemIsElement=*/ true );
1667
1685
highlightOffendingType (diag, complainRepr);
1668
- noteLimitingImport (SD->getASTContext (), importLimit);
1686
+ noteLimitingImport (SD->getASTContext (), importLimit, complainRepr );
1669
1687
});
1670
1688
}
1671
1689
@@ -1703,7 +1721,8 @@ class UsableFromInlineChecker : public AccessControlCheckerBase,
1703
1721
/* problemIsResult=*/ false ,
1704
1722
/* inaccessibleWrapper=*/ true );
1705
1723
highlightOffendingType (diag, complainRepr);
1706
- noteLimitingImport (fn->getASTContext (), importLimit);
1724
+ noteLimitingImport (fn->getASTContext (), importLimit,
1725
+ complainRepr);
1707
1726
});
1708
1727
}
1709
1728
}
@@ -1720,7 +1739,7 @@ class UsableFromInlineChecker : public AccessControlCheckerBase,
1720
1739
/* problemIsResult=*/ false ,
1721
1740
/* inaccessibleWrapper=*/ false );
1722
1741
highlightOffendingType (diag, complainRepr);
1723
- noteLimitingImport (fn->getASTContext (), importLimit);
1742
+ noteLimitingImport (fn->getASTContext (), importLimit, complainRepr );
1724
1743
});
1725
1744
}
1726
1745
@@ -1738,7 +1757,7 @@ class UsableFromInlineChecker : public AccessControlCheckerBase,
1738
1757
/* problemIsResult=*/ true ,
1739
1758
/* inaccessibleWrapper=*/ false );
1740
1759
highlightOffendingType (diag, complainRepr);
1741
- noteLimitingImport (fn->getASTContext (), importLimit);
1760
+ noteLimitingImport (fn->getASTContext (), importLimit, complainRepr );
1742
1761
});
1743
1762
}
1744
1763
}
@@ -1762,7 +1781,8 @@ class UsableFromInlineChecker : public AccessControlCheckerBase,
1762
1781
diagID = diag::enum_case_usable_from_inline_warn;
1763
1782
auto diag = EED->diagnose (diagID);
1764
1783
highlightOffendingType (diag, complainRepr);
1765
- noteLimitingImport (EED->getASTContext (), importLimit);
1784
+ noteLimitingImport (EED->getASTContext (), importLimit,
1785
+ complainRepr);
1766
1786
});
1767
1787
}
1768
1788
}
0 commit comments