mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Diagnostics] Treat type requirement failures associated with Self = Any as unrelated
This helps us to filter out cases like operator overloads where
`Self` type comes from e.g. default for collection element -
`[1, "hello"].map { $0 + 1 }`. Main problem here is that
collection type couldn't be determined without unification to
`Any` and `+` failing for all numeric overloads is just a consequence.
This commit is contained in:
@@ -3832,8 +3832,8 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
|
|||||||
ConstraintKind kind,
|
ConstraintKind kind,
|
||||||
ConstraintLocatorBuilder locator,
|
ConstraintLocatorBuilder locator,
|
||||||
TypeMatchOptions flags) {
|
TypeMatchOptions flags) {
|
||||||
|
auto *typeVar = type->getAs<TypeVariableType>();
|
||||||
if (shouldAttemptFixes()) {
|
if (shouldAttemptFixes()) {
|
||||||
auto *typeVar = type->getAs<TypeVariableType>();
|
|
||||||
// If type variable, associated with this conformance check,
|
// If type variable, associated with this conformance check,
|
||||||
// has been determined to be a "hole" in constraint system,
|
// has been determined to be a "hole" in constraint system,
|
||||||
// let's consider this check a success without recording
|
// let's consider this check a success without recording
|
||||||
@@ -3983,6 +3983,23 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
|
|||||||
return SolutionKind::Error;
|
return SolutionKind::Error;
|
||||||
|
|
||||||
if (path.back().is<LocatorPathElt::AnyRequirement>()) {
|
if (path.back().is<LocatorPathElt::AnyRequirement>()) {
|
||||||
|
// If this is a requirement associated with `Self` which is bound
|
||||||
|
// to `Any`, let's consider this "too incorrect" to continue.
|
||||||
|
//
|
||||||
|
// This helps us to filter out cases like operator overloads where
|
||||||
|
// `Self` type comes from e.g. default for collection element -
|
||||||
|
// `[1, "hello"].map { $0 + 1 }`. Main problem here is that
|
||||||
|
// collection type couldn't be determined without unification to
|
||||||
|
// `Any` and `+` failing for all numeric overloads is just a consequence.
|
||||||
|
if (typeVar && type->isAny()) {
|
||||||
|
auto *GP = typeVar->getImpl().getGenericParameter();
|
||||||
|
if (auto *GPD = GP->getDecl()) {
|
||||||
|
auto *DC = GPD->getDeclContext();
|
||||||
|
if (DC->isTypeContext() && DC->getSelfInterfaceType()->isEqual(GP))
|
||||||
|
return SolutionKind::Error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (auto *fix =
|
if (auto *fix =
|
||||||
fixRequirementFailure(*this, type, protocolTy, anchor, path)) {
|
fixRequirementFailure(*this, type, protocolTy, anchor, path)) {
|
||||||
if (!recordFix(fix)) {
|
if (!recordFix(fix)) {
|
||||||
|
|||||||
@@ -182,8 +182,7 @@ func r22162441(_ lines: [String]) {
|
|||||||
|
|
||||||
func testMap() {
|
func testMap() {
|
||||||
let a = 42
|
let a = 42
|
||||||
[1,a].map { $0 + 1.0 } // expected-error {{binary operator '+' cannot be applied to operands of type 'Any' and 'Double'}}
|
[1,a].map { $0 + 1.0 } // expected-error {{cannot convert value of type 'Int' to expected element type 'Double'}}
|
||||||
// expected-note @-1 {{expected an argument list of type '(Double, Double)'}}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// <rdar://problem/22414757> "UnresolvedDot" "in wrong phase" assertion from verifier
|
// <rdar://problem/22414757> "UnresolvedDot" "in wrong phase" assertion from verifier
|
||||||
|
|||||||
Reference in New Issue
Block a user