@@ -6188,49 +6188,60 @@ bool InaccessibleMemberFailure::diagnoseAsError() {
6188
6188
auto loc = nameLoc.isValid () ? nameLoc.getStartLoc () : ::getLoc (anchor);
6189
6189
auto accessLevel = Member->getFormalAccessScope ().accessLevelForDiagnostics ();
6190
6190
bool suppressDeclHereNote = false ;
6191
- if (accessLevel == AccessLevel::Public) {
6191
+ if (accessLevel == AccessLevel::Public &&
6192
+ !Member->findImport (getDC ())) {
6192
6193
auto definingModule = Member->getDeclContext ()->getParentModule ();
6193
6194
emitDiagnosticAt (loc, diag::candidate_from_missing_import,
6194
6195
Member->getDescriptiveKind (), Member->getName (),
6195
6196
definingModule->getName ());
6196
6197
6197
- if (auto enclosingSF = getDC ()->getParentSourceFile ()) {
6198
- SourceLoc bestLoc;
6199
- SourceManager &srcMgr = Member->getASTContext ().SourceMgr ;
6200
- for (auto item : enclosingSF->getTopLevelItems ()) {
6201
- // If we found an import declaration, we want to insert after it.
6202
- if (auto importDecl =
6203
- dyn_cast_or_null<ImportDecl>(item.dyn_cast <Decl *>())) {
6204
- SourceLoc loc = importDecl->getEndLoc ();
6205
- if (loc.isValid ()) {
6206
- bestLoc = Lexer::getLocForEndOfLine (srcMgr, loc);
6207
- }
6208
-
6209
- // Keep looking for more import declarations.
6210
- continue ;
6211
- }
6212
-
6213
- // If we got a location based on import declarations, we're done.
6214
- if (bestLoc.isValid ())
6215
- break ;
6216
-
6217
- // For any other item, we want to insert before it.
6218
- SourceLoc loc = item.getStartLoc ();
6198
+ auto enclosingSF = getDC ()->getParentSourceFile ();
6199
+ SourceLoc bestLoc;
6200
+ SourceManager &srcMgr = Member->getASTContext ().SourceMgr ;
6201
+ for (auto item : enclosingSF->getTopLevelItems ()) {
6202
+ // If we found an import declaration, we want to insert after it.
6203
+ if (auto importDecl =
6204
+ dyn_cast_or_null<ImportDecl>(item.dyn_cast <Decl *>())) {
6205
+ SourceLoc loc = importDecl->getEndLoc ();
6219
6206
if (loc.isValid ()) {
6220
- bestLoc = Lexer::getLocForStartOfLine (srcMgr, loc);
6221
- break ;
6207
+ bestLoc = Lexer::getLocForEndOfLine (srcMgr, loc);
6222
6208
}
6209
+
6210
+ // Keep looking for more import declarations.
6211
+ continue ;
6212
+ }
6213
+
6214
+ // If we got a location based on import declarations, we're done.
6215
+ if (bestLoc.isValid ())
6216
+ break ;
6217
+
6218
+ // For any other item, we want to insert before it.
6219
+ SourceLoc loc = item.getStartLoc ();
6220
+ if (loc.isValid ()) {
6221
+ bestLoc = Lexer::getLocForStartOfLine (srcMgr, loc);
6222
+ break ;
6223
6223
}
6224
+ }
6225
+
6226
+ if (bestLoc.isValid ()) {
6227
+ llvm::SmallString<64 > importText;
6224
6228
6225
- if (bestLoc. isValid ()) {
6226
- llvm::SmallString< 64 > importText;
6227
- importText += " import " ;
6228
- importText += definingModule-> getName (). str ();
6229
- importText += " \n " ;
6230
- emitDiagnosticAt (bestLoc, diag::candidate_add_import,
6231
- definingModule-> getName ())
6232
- . fixItInsert (bestLoc, importText);
6229
+ // @_spi imports.
6230
+ if (Member-> isSPI ()) {
6231
+ auto spiGroups = Member-> getSPIGroups () ;
6232
+ if (!spiGroups. empty ()) {
6233
+ importText += " @_spi( " ;
6234
+ importText += spiGroups[ 0 ]. str ();
6235
+ importText += " ) " ;
6236
+ }
6233
6237
}
6238
+
6239
+ importText += " import " ;
6240
+ importText += definingModule->getName ().str ();
6241
+ importText += " \n " ;
6242
+ emitDiagnosticAt (bestLoc, diag::candidate_add_import,
6243
+ definingModule->getName ())
6244
+ .fixItInsert (bestLoc, importText);
6234
6245
}
6235
6246
6236
6247
suppressDeclHereNote = true ;
@@ -6244,7 +6255,8 @@ bool InaccessibleMemberFailure::diagnoseAsError() {
6244
6255
.highlight (nameLoc.getSourceRange ());
6245
6256
}
6246
6257
6247
- emitDiagnosticAt (Member, diag::decl_declared_here, Member);
6258
+ if (!suppressDeclHereNote)
6259
+ emitDiagnosticAt (Member, diag::decl_declared_here, Member);
6248
6260
return true ;
6249
6261
}
6250
6262
0 commit comments