@@ -30,8 +30,9 @@ Optional<Type> TypeChecker::checkObjCKeyPathExpr(DeclContext *dc,
30
30
if (expr->getObjCStringLiteralExpr () && !requireResultType) return None;
31
31
32
32
// ObjC #keyPath only makes sense when we have the Objective-C runtime.
33
+ auto &diags = dc->getASTContext ().Diags ;
33
34
if (!Context.LangOpts .EnableObjCInterop ) {
34
- diagnose (expr->getLoc (), diag::expr_keypath_no_objc_runtime);
35
+ diags. diagnose (expr->getLoc (), diag::expr_keypath_no_objc_runtime);
35
36
36
37
expr->setObjCStringLiteralExpr (
37
38
new (Context) StringLiteralExpr (" " , expr->getSourceRange (),
@@ -212,9 +213,9 @@ Optional<Type> TypeChecker::checkObjCKeyPathExpr(DeclContext *dc,
212
213
case KeyPathExpr::Component::Kind::OptionalChain:
213
214
case KeyPathExpr::Component::Kind::OptionalForce:
214
215
case KeyPathExpr::Component::Kind::TupleElement:
215
- diagnose (componentNameLoc,
216
- diag::expr_unsupported_objc_key_path_component,
217
- (unsigned )kind);
216
+ diags. diagnose (componentNameLoc,
217
+ diag::expr_unsupported_objc_key_path_component,
218
+ (unsigned )kind);
218
219
continue ;
219
220
case KeyPathExpr::Component::Kind::OptionalWrap:
220
221
case KeyPathExpr::Component::Kind::Property:
@@ -224,8 +225,8 @@ Optional<Type> TypeChecker::checkObjCKeyPathExpr(DeclContext *dc,
224
225
225
226
auto componentFullName = component.getUnresolvedDeclName ();
226
227
if (!componentFullName.isSimpleName ()) {
227
- diagnose (componentNameLoc,
228
- diag::expr_unsupported_objc_key_path_compound_name);
228
+ diags. diagnose (componentNameLoc,
229
+ diag::expr_unsupported_objc_key_path_compound_name);
229
230
continue ;
230
231
}
231
232
auto componentName = componentFullName.getBaseName ();
@@ -259,11 +260,11 @@ Optional<Type> TypeChecker::checkObjCKeyPathExpr(DeclContext *dc,
259
260
corrections);
260
261
261
262
if (currentType)
262
- diagnose (componentNameLoc, diag::could_not_find_type_member,
263
- currentType, componentName);
263
+ diags. diagnose (componentNameLoc, diag::could_not_find_type_member,
264
+ currentType, componentName);
264
265
else
265
- diagnose (componentNameLoc, diag::use_unresolved_identifier,
266
- componentName, false );
266
+ diags. diagnose (componentNameLoc, diag::use_unresolved_identifier,
267
+ componentName, false );
267
268
268
269
// Note all the correction candidates.
269
270
corrections.noteAllCandidates ();
@@ -300,15 +301,15 @@ Optional<Type> TypeChecker::checkObjCKeyPathExpr(DeclContext *dc,
300
301
break ;
301
302
302
303
if (lookupType)
303
- diagnose (componentNameLoc, diag::ambiguous_member_overload_set,
304
- componentName);
304
+ diags. diagnose (componentNameLoc, diag::ambiguous_member_overload_set,
305
+ componentName);
305
306
else
306
- diagnose (componentNameLoc, diag::ambiguous_decl_ref,
307
- componentName);
307
+ diags. diagnose (componentNameLoc, diag::ambiguous_decl_ref,
308
+ componentName);
308
309
309
310
for (auto result : lookup) {
310
- diagnose (result.getValueDecl (), diag::decl_declared_here,
311
- result.getValueDecl ()->getFullName ());
311
+ diags. diagnose (result.getValueDecl (), diag::decl_declared_here,
312
+ result.getValueDecl ()->getFullName ());
312
313
}
313
314
isInvalid = true ;
314
315
break ;
@@ -327,11 +328,11 @@ Optional<Type> TypeChecker::checkObjCKeyPathExpr(DeclContext *dc,
327
328
328
329
// Check that the property is @objc.
329
330
if (!var->isObjC ()) {
330
- diagnose (componentNameLoc, diag::expr_keypath_non_objc_property,
331
- componentName);
331
+ diags. diagnose (componentNameLoc, diag::expr_keypath_non_objc_property,
332
+ componentName);
332
333
if (var->getLoc ().isValid () && var->getDeclContext ()->isTypeContext ()) {
333
- diagnose (var, diag::make_decl_objc,
334
- var->getDescriptiveKind ())
334
+ diags. diagnose (var, diag::make_decl_objc,
335
+ var->getDescriptiveKind ())
335
336
.fixItInsert (var->getAttributeInsertionLoc (false ),
336
337
" @objc " );
337
338
}
@@ -341,10 +342,12 @@ Optional<Type> TypeChecker::checkObjCKeyPathExpr(DeclContext *dc,
341
342
if (attr->isSwift3Inferred () &&
342
343
Context.LangOpts .WarnSwift3ObjCInference ==
343
344
Swift3ObjCInferenceWarnings::Minimal) {
344
- diagnose (componentNameLoc, diag::expr_keypath_swift3_objc_inference,
345
- var->getFullName (),
346
- var->getDeclContext ()->getSelfNominalTypeDecl ()->getName ());
347
- diagnose (var, diag::make_decl_objc, var->getDescriptiveKind ())
345
+ auto *parent = var->getDeclContext ()->getSelfNominalTypeDecl ();
346
+ diags.diagnose (componentNameLoc,
347
+ diag::expr_keypath_swift3_objc_inference,
348
+ var->getFullName (),
349
+ parent->getName ());
350
+ diags.diagnose (var, diag::make_decl_objc, var->getDescriptiveKind ())
348
351
.fixItInsert (var->getAttributeInsertionLoc (false ),
349
352
" @objc " );
350
353
}
@@ -361,16 +364,16 @@ Optional<Type> TypeChecker::checkObjCKeyPathExpr(DeclContext *dc,
361
364
if (auto type = dyn_cast<TypeDecl>(found)) {
362
365
// We cannot refer to a type via a property.
363
366
if (isResolvingProperty ()) {
364
- diagnose (componentNameLoc, diag::expr_keypath_type_of_property,
365
- componentName, currentType);
367
+ diags. diagnose (componentNameLoc, diag::expr_keypath_type_of_property,
368
+ componentName, currentType);
366
369
isInvalid = true ;
367
370
break ;
368
371
}
369
372
370
373
// We cannot refer to a generic type.
371
374
if (type->getDeclaredInterfaceType ()->hasTypeParameter ()) {
372
- diagnose (componentNameLoc, diag::expr_keypath_generic_type,
373
- componentName);
375
+ diags. diagnose (componentNameLoc, diag::expr_keypath_generic_type,
376
+ componentName);
374
377
isInvalid = true ;
375
378
break ;
376
379
}
@@ -392,9 +395,9 @@ Optional<Type> TypeChecker::checkObjCKeyPathExpr(DeclContext *dc,
392
395
}
393
396
394
397
// Declarations that cannot be part of a key-path.
395
- diagnose (componentNameLoc, diag::expr_keypath_not_property,
396
- found->getDescriptiveKind (), found->getFullName (),
397
- /* isForDynamicKeyPathMemberLookup=*/ false );
398
+ diags. diagnose (componentNameLoc, diag::expr_keypath_not_property,
399
+ found->getDescriptiveKind (), found->getFullName (),
400
+ /* isForDynamicKeyPathMemberLookup=*/ false );
398
401
isInvalid = true ;
399
402
break ;
400
403
}
@@ -406,7 +409,7 @@ Optional<Type> TypeChecker::checkObjCKeyPathExpr(DeclContext *dc,
406
409
// Check for an empty key-path string.
407
410
auto keyPathString = keyPathOS.str ();
408
411
if (keyPathString.empty () && !isInvalid)
409
- diagnose (expr->getLoc (), diag::expr_keypath_empty);
412
+ diags. diagnose (expr->getLoc (), diag::expr_keypath_empty);
410
413
411
414
// Set the string literal expression for the ObjC key path.
412
415
if (!expr->getObjCStringLiteralExpr ()) {
0 commit comments