Skip to content

Commit b305324

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 6807569 commit b305324

File tree

2 files changed

+11
-18
lines changed

2 files changed

+11
-18
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2755,24 +2755,17 @@ assessRequirementFailureImpact(ConstraintSystem &cs, Type requirementType,
27552755
}
27562756
}
27572757

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

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

test/Constraints/optional.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,8 @@ 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?'}}
439+
// expected-note@-2 {{overloads for '==' exist}}
440440
}
441441

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

0 commit comments

Comments
 (0)