Skip to content

Commit 5d3b3a6

Browse files
authored
[Sema] Remove TypeChecker::diagnose[WithNotes] (swiftlang#28146)
[Sema] Remove TypeChecker::diagnose[WithNotes]
2 parents b12923a + 82565e8 commit 5d3b3a6

File tree

4 files changed

+100
-96
lines changed

4 files changed

+100
-96
lines changed

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2881,7 +2881,7 @@ bool TypeChecker::typeCheckPatternBinding(PatternBindingDecl *PBD,
28812881

28822882
opaque->setUnderlyingTypeSubstitutions(underlyingSubs);
28832883
} else {
2884-
diagnose(var->getLoc(), diag::opaque_type_var_no_underlying_type);
2884+
var->diagnose(diag::opaque_type_var_no_underlying_type);
28852885
}
28862886
}
28872887
}
@@ -3081,9 +3081,10 @@ bool TypeChecker::typeCheckStmtCondition(StmtCondition &cond, DeclContext *dc,
30813081

30823082
// If the binding is not refutable, and there *is* an else, reject it as
30833083
// unreachable.
3084-
if (!hadAnyFalsable && !hadError)
3085-
diagnose(cond[0].getStartLoc(), diagnosticForAlwaysTrue);
3086-
3084+
if (!hadAnyFalsable && !hadError) {
3085+
auto &diags = dc->getASTContext().Diags;
3086+
diags.diagnose(cond[0].getStartLoc(), diagnosticForAlwaysTrue);
3087+
}
30873088
return false;
30883089
}
30893090

@@ -3112,8 +3113,9 @@ bool TypeChecker::typeCheckExprPattern(ExprPattern *EP, DeclContext *DC,
31123113
lookupOptions |= NameLookupFlags::KnownPrivate;
31133114
auto matchLookup = lookupUnqualified(DC, Context.Id_MatchOperator,
31143115
SourceLoc(), lookupOptions);
3116+
auto &diags = DC->getASTContext().Diags;
31153117
if (!matchLookup) {
3116-
diagnose(EP->getLoc(), diag::no_match_operator);
3118+
diags.diagnose(EP->getLoc(), diag::no_match_operator);
31173119
return true;
31183120
}
31193121

@@ -3123,7 +3125,7 @@ bool TypeChecker::typeCheckExprPattern(ExprPattern *EP, DeclContext *DC,
31233125
}
31243126

31253127
if (choices.empty()) {
3126-
diagnose(EP->getLoc(), diag::no_match_operator);
3128+
diags.diagnose(EP->getLoc(), diag::no_match_operator);
31273129
return true;
31283130
}
31293131

@@ -3868,6 +3870,7 @@ CheckedCastKind TypeChecker::typeCheckCheckedCast(Type fromType,
38683870
// Determine whether we should suppress diagnostics.
38693871
bool suppressDiagnostics = (contextKind == CheckedCastContextKind::None);
38703872

3873+
auto &diags = dc->getASTContext().Diags;
38713874
bool optionalToOptionalCast = false;
38723875

38733876
// Local function to indicate failure.
@@ -3881,7 +3884,8 @@ CheckedCastKind TypeChecker::typeCheckCheckedCast(Type fromType,
38813884
if (optionalToOptionalCast)
38823885
return CheckedCastKind::ValueCast;
38833886

3884-
diagnose(diagLoc, diag::downcast_to_unrelated, origFromType, origToType)
3887+
diags.diagnose(diagLoc, diag::downcast_to_unrelated, origFromType,
3888+
origToType)
38853889
.highlight(diagFromRange)
38863890
.highlight(diagToRange);
38873891

@@ -3897,8 +3901,8 @@ CheckedCastKind TypeChecker::typeCheckCheckedCast(Type fromType,
38973901
auto fromValueType = fromType->getOptionalObjectType();
38983902
if (!fromValueType) {
38993903
if (!suppressDiagnostics) {
3900-
diagnose(diagLoc, diag::downcast_to_more_optional,
3901-
origFromType, origToType)
3904+
diags.diagnose(diagLoc, diag::downcast_to_more_optional,
3905+
origFromType, origToType)
39023906
.highlight(diagFromRange)
39033907
.highlight(diagToRange);
39043908
}
@@ -3937,10 +3941,10 @@ CheckedCastKind TypeChecker::typeCheckCheckedCast(Type fromType,
39373941

39383942
case CheckedCastContextKind::ForcedCast: {
39393943
std::string extraFromOptionalsStr(extraFromOptionals, '!');
3940-
auto diag = diagnose(diagLoc, diag::downcast_same_type,
3941-
origFromType, origToType,
3942-
extraFromOptionalsStr,
3943-
isBridged);
3944+
auto diag = diags.diagnose(diagLoc, diag::downcast_same_type,
3945+
origFromType, origToType,
3946+
extraFromOptionalsStr,
3947+
isBridged);
39443948
diag.highlight(diagFromRange);
39453949
diag.highlight(diagToRange);
39463950

@@ -3969,11 +3973,12 @@ CheckedCastKind TypeChecker::typeCheckCheckedCast(Type fromType,
39693973
if (extraFromOptionals == 1) {
39703974
// A single optional is carried through. It's better to use 'as' to
39713975
// the appropriate optional type.
3972-
auto diag = diagnose(diagLoc, diag::conditional_downcast_same_type,
3973-
origFromType, origToType,
3974-
fromType->isEqual(toType) ? 0
3975-
: isBridged ? 2
3976-
: 1);
3976+
auto diag = diags.diagnose(diagLoc,
3977+
diag::conditional_downcast_same_type,
3978+
origFromType, origToType,
3979+
fromType->isEqual(toType) ? 0
3980+
: isBridged ? 2
3981+
: 1);
39773982
diag.highlight(diagFromRange);
39783983
diag.highlight(diagToRange);
39793984

@@ -4005,8 +4010,8 @@ CheckedCastKind TypeChecker::typeCheckCheckedCast(Type fromType,
40054010
// If we're only unwrapping a single optional, we could have just
40064011
// checked for 'nil'.
40074012
if (extraFromOptionals == 1) {
4008-
auto diag = diagnose(diagLoc, diag::is_expr_same_type,
4009-
origFromType, origToType);
4013+
auto diag = diags.diagnose(diagLoc, diag::is_expr_same_type,
4014+
origFromType, origToType);
40104015
diag.highlight(diagFromRange);
40114016
diag.highlight(diagToRange);
40124017

@@ -4178,7 +4183,8 @@ CheckedCastKind TypeChecker::typeCheckCheckedCast(Type fromType,
41784183
switch (contextKind) {
41794184
case CheckedCastContextKind::ConditionalCast:
41804185
case CheckedCastContextKind::ForcedCast:
4181-
diagnose(diagLoc, diag::downcast_to_unrelated, origFromType, origToType)
4186+
diags.diagnose(diagLoc, diag::downcast_to_unrelated, origFromType,
4187+
origToType)
41824188
.highlight(diagFromRange)
41834189
.highlight(diagToRange);
41844190

@@ -4187,7 +4193,8 @@ CheckedCastKind TypeChecker::typeCheckCheckedCast(Type fromType,
41874193
if (auto DRE = dyn_cast<DeclRefExpr>(fromExpr)) {
41884194
if (auto FD = dyn_cast<FuncDecl>(DRE->getDecl())) {
41894195
if (!FD->getResultInterfaceType()->isVoid()) {
4190-
diagnose(diagLoc, diag::downcast_to_unrelated_fixit, FD->getName())
4196+
diags.diagnose(diagLoc, diag::downcast_to_unrelated_fixit,
4197+
FD->getName())
41914198
.fixItInsertAfter(fromExpr->getEndLoc(), "()");
41924199
}
41934200
}

lib/Sema/TypeCheckExprObjC.cpp

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ Optional<Type> TypeChecker::checkObjCKeyPathExpr(DeclContext *dc,
3030
if (expr->getObjCStringLiteralExpr() && !requireResultType) return None;
3131

3232
// ObjC #keyPath only makes sense when we have the Objective-C runtime.
33+
auto &diags = dc->getASTContext().Diags;
3334
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);
3536

3637
expr->setObjCStringLiteralExpr(
3738
new (Context) StringLiteralExpr("", expr->getSourceRange(),
@@ -212,9 +213,9 @@ Optional<Type> TypeChecker::checkObjCKeyPathExpr(DeclContext *dc,
212213
case KeyPathExpr::Component::Kind::OptionalChain:
213214
case KeyPathExpr::Component::Kind::OptionalForce:
214215
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);
218219
continue;
219220
case KeyPathExpr::Component::Kind::OptionalWrap:
220221
case KeyPathExpr::Component::Kind::Property:
@@ -224,8 +225,8 @@ Optional<Type> TypeChecker::checkObjCKeyPathExpr(DeclContext *dc,
224225

225226
auto componentFullName = component.getUnresolvedDeclName();
226227
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);
229230
continue;
230231
}
231232
auto componentName = componentFullName.getBaseName();
@@ -259,11 +260,11 @@ Optional<Type> TypeChecker::checkObjCKeyPathExpr(DeclContext *dc,
259260
corrections);
260261

261262
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);
264265
else
265-
diagnose(componentNameLoc, diag::use_unresolved_identifier,
266-
componentName, false);
266+
diags.diagnose(componentNameLoc, diag::use_unresolved_identifier,
267+
componentName, false);
267268

268269
// Note all the correction candidates.
269270
corrections.noteAllCandidates();
@@ -300,15 +301,15 @@ Optional<Type> TypeChecker::checkObjCKeyPathExpr(DeclContext *dc,
300301
break;
301302

302303
if (lookupType)
303-
diagnose(componentNameLoc, diag::ambiguous_member_overload_set,
304-
componentName);
304+
diags.diagnose(componentNameLoc, diag::ambiguous_member_overload_set,
305+
componentName);
305306
else
306-
diagnose(componentNameLoc, diag::ambiguous_decl_ref,
307-
componentName);
307+
diags.diagnose(componentNameLoc, diag::ambiguous_decl_ref,
308+
componentName);
308309

309310
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());
312313
}
313314
isInvalid = true;
314315
break;
@@ -327,11 +328,11 @@ Optional<Type> TypeChecker::checkObjCKeyPathExpr(DeclContext *dc,
327328

328329
// Check that the property is @objc.
329330
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);
332333
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())
335336
.fixItInsert(var->getAttributeInsertionLoc(false),
336337
"@objc ");
337338
}
@@ -341,10 +342,12 @@ Optional<Type> TypeChecker::checkObjCKeyPathExpr(DeclContext *dc,
341342
if (attr->isSwift3Inferred() &&
342343
Context.LangOpts.WarnSwift3ObjCInference ==
343344
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())
348351
.fixItInsert(var->getAttributeInsertionLoc(false),
349352
"@objc ");
350353
}
@@ -361,16 +364,16 @@ Optional<Type> TypeChecker::checkObjCKeyPathExpr(DeclContext *dc,
361364
if (auto type = dyn_cast<TypeDecl>(found)) {
362365
// We cannot refer to a type via a property.
363366
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);
366369
isInvalid = true;
367370
break;
368371
}
369372

370373
// We cannot refer to a generic type.
371374
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);
374377
isInvalid = true;
375378
break;
376379
}
@@ -392,9 +395,9 @@ Optional<Type> TypeChecker::checkObjCKeyPathExpr(DeclContext *dc,
392395
}
393396

394397
// 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);
398401
isInvalid = true;
399402
break;
400403
}
@@ -406,7 +409,7 @@ Optional<Type> TypeChecker::checkObjCKeyPathExpr(DeclContext *dc,
406409
// Check for an empty key-path string.
407410
auto keyPathString = keyPathOS.str();
408411
if (keyPathString.empty() && !isInvalid)
409-
diagnose(expr->getLoc(), diag::expr_keypath_empty);
412+
diags.diagnose(expr->getLoc(), diag::expr_keypath_empty);
410413

411414
// Set the string literal expression for the ObjC key path.
412415
if (!expr->getObjCStringLiteralExpr()) {

0 commit comments

Comments
 (0)