From e4f6041dba818a82fcc918bc29cdd1a9ba8e63e8 Mon Sep 17 00:00:00 2001 From: Pavel Yaskevich Date: Fri, 4 Sep 2020 13:22:08 -0700 Subject: [PATCH] [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 --- lib/Sema/CSSimplify.cpp | 7 +++++-- test/Constraints/valid_pointer_conversions.swift | 6 ++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/Sema/CSSimplify.cpp b/lib/Sema/CSSimplify.cpp index a6563aa7fa550..86ae993fb893d 100644 --- a/lib/Sema/CSSimplify.cpp +++ b/lib/Sema/CSSimplify.cpp @@ -3829,8 +3829,11 @@ bool ConstraintSystem::repairFailures( // If this is an implicit 'something-to-pointer' conversion // it's going to be diagnosed by specialized fix which deals // with generic argument mismatches. - if (matchKind == ConstraintKind::BindToPointerType) - break; + if (matchKind == ConstraintKind::BindToPointerType) { + auto *member = rhs->getAs(); + if (!(member && member->getBase()->hasHole())) + break; + } // 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 diff --git a/test/Constraints/valid_pointer_conversions.swift b/test/Constraints/valid_pointer_conversions.swift index 3a3bd9ea9cbc4..1cb1fb4ff1887 100644 --- a/test/Constraints/valid_pointer_conversions.swift +++ b/test/Constraints/valid_pointer_conversions.swift @@ -41,3 +41,9 @@ func SR12382(_ x: UnsafeMutablePointer??) {} var i = 0 SR12382(&i) // expected-error {{cannot convert value of type 'UnsafeMutablePointer' to expected argument type 'UnsafeMutablePointer'}} // 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) { + _ = String(decodingCString: ptr, as: .utf8) // expected-error {{generic parameter 'Encoding' could not be inferred}} + // expected-error@-1 {{type '_.Type' has no member 'utf8'}} +}