Skip to content

[ConstraintSystem] Record generic fix if destination of a pointer con… #33809

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<DependentMemberType>();
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
Expand Down
6 changes: 6 additions & 0 deletions test/Constraints/valid_pointer_conversions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,9 @@ func SR12382(_ x: UnsafeMutablePointer<Double>??) {}
var i = 0
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}}

//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'}}
Copy link
Contributor Author

@xedin xedin Sep 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New HoleType allows us to deal with this issue and avoid producing member diagnostic here. I'm going to implement that in a follow-up PR to separate concerns here...

}