[ConstraintSystem] Record generic fix if destination of a pointer conversion is invalid

If the right-hand side (destination) of value-to-pointer conversion
is incorrect e.g. base type of member is a hole, let's record
a generic "invalid conversion" failure.

Resolves: rdar://problem/68254165
This commit is contained in:
Pavel Yaskevich
2020-09-04 13:22:08 -07:00
parent 309cb93043
commit e4f6041dba
2 changed files with 11 additions and 2 deletions

View File

@@ -3829,8 +3829,11 @@ bool ConstraintSystem::repairFailures(
// If this is an implicit 'something-to-pointer' conversion // If this is an implicit 'something-to-pointer' conversion
// it's going to be diagnosed by specialized fix which deals // it's going to be diagnosed by specialized fix which deals
// with generic argument mismatches. // with generic argument mismatches.
if (matchKind == ConstraintKind::BindToPointerType) if (matchKind == ConstraintKind::BindToPointerType) {
auto *member = rhs->getAs<DependentMemberType>();
if (!(member && member->getBase()->hasHole()))
break; break;
}
// If this is a ~= operator implicitly generated by pattern matching // If this is a ~= operator implicitly generated by pattern matching
// let's not try to fix right-hand side of the operator because it's // let's not try to fix right-hand side of the operator because it's

View File

@@ -41,3 +41,9 @@ func SR12382(_ x: UnsafeMutablePointer<Double>??) {}
var i = 0 var i = 0
SR12382(&i) // expected-error {{cannot convert value of type 'UnsafeMutablePointer<Int>' to expected argument type 'UnsafeMutablePointer<Double>'}} SR12382(&i) // expected-error {{cannot convert value of type 'UnsafeMutablePointer<Int>' to expected argument type 'UnsafeMutablePointer<Double>'}}
// expected-note@-1 {{arguments to generic parameter 'Pointee' ('Int' and 'Double') are expected to be equal}} // expected-note@-1 {{arguments to generic parameter 'Pointee' ('Int' and 'Double') are expected to be equal}}
//problem/68254165 - Bad diagnostic when using String init(decodingCString:) with an incorrect pointer type
func rdar68254165(ptr: UnsafeMutablePointer<Int8>) {
_ = String(decodingCString: ptr, as: .utf8) // expected-error {{generic parameter 'Encoding' could not be inferred}}
// expected-error@-1 {{type '_.Type' has no member 'utf8'}}
}