Skip to content

Commit 17d8f1f

Browse files
committed
[CS] Remove obsolete check for a type variable
We no longer need to check for a type variable here, it no longer regresses diagnostics. Also, while here, let's bump the impact for an Any/AnyObject missing conformance, as that's unlikely going to be helpful since they cannot conform to protocols even if the user wanted them to.
1 parent 03e5c9f commit 17d8f1f

File tree

2 files changed

+10
-18
lines changed

2 files changed

+10
-18
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2763,24 +2763,17 @@ assessRequirementFailureImpact(ConstraintSystem &cs, Type requirementType,
27632763
}
27642764
}
27652765

2766-
// Increase the impact of a conformance fix for a standard library
2767-
// or foundation type, as it's unlikely to be a good suggestion.
2768-
//
2769-
// Also do the same for the builtin compiler types Any and AnyObject,
2770-
// which cannot conform to protocols.
2771-
//
2772-
// FIXME: We ought not to have the is<TypeVariableType>() condition here, but
2773-
// removing it currently regresses the diagnostic for the test case for
2774-
// rdar://60727310. Once we better handle the separation of conformance fixes
2775-
// from argument mismatches in cases like
2776-
// https://github.com/apple/swift/issues/54877, we should be able to remove
2777-
// it from the condition.
2778-
if ((requirementType->is<TypeVariableType>() && resolvedTy->isStdlibType()) ||
2779-
resolvedTy->isAny() || resolvedTy->isAnyObject() ||
2780-
getKnownFoundationEntity(resolvedTy->getString())) {
2781-
if (locator.isForRequirement(RequirementKind::Conformance)) {
2766+
if (locator.isForRequirement(RequirementKind::Conformance)) {
2767+
// Increase the impact of a conformance fix for a standard library
2768+
// or foundation type, as it's unlikely to be a good suggestion.
2769+
if (resolvedTy->isStdlibType() ||
2770+
getKnownFoundationEntity(resolvedTy->getString())) {
27822771
impact += 2;
27832772
}
2773+
// Also do the same for the builtin compiler types Any and AnyObject, but
2774+
// bump the impact even higher as they cannot conform to protocols at all.
2775+
if (resolvedTy->isAny() || resolvedTy->isAnyObject())
2776+
impact += 4;
27842777
}
27852778

27862779
// If this requirement is associated with an overload choice let's

test/Constraints/optional.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,7 @@ func test_force_unwrap_not_being_too_eager() {
435435
// rdar://problem/57097401
436436
func invalidOptionalChaining(a: Any) {
437437
a == "="? // expected-error {{cannot use optional chaining on non-optional value of type 'String'}}
438-
// expected-error@-1 {{type 'Any' cannot conform to 'Equatable'}}
439-
// expected-note@-2 {{requirement from conditional conformance of 'Any?' to 'Equatable'}} expected-note@-2 {{only concrete types such as structs, enums and classes can conform to protocols}}
438+
// expected-error@-1 {{binary operator '==' cannot be applied to operands of type 'Any' and 'String?'}}
440439
}
441440

442441
/// https://github.com/apple/swift/issues/54739

0 commit comments

Comments
 (0)