Skip to content

[ConstraintSystem] Allow binding metatypes to succeed if one contains a hole #28116

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
Nov 7, 2019
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: 7 additions & 0 deletions lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3399,6 +3399,13 @@ bool ConstraintSystem::repairFailures(
break;
}

case ConstraintLocator::InstanceType: {
if (lhs->hasUnresolvedType() || rhs->hasUnresolvedType())
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of checking unresolved type directly should be actually frame it in terms of a hole e.g. ->hasHole()?

Copy link
Member Author

@hborla hborla Nov 6, 2019

Choose a reason for hiding this comment

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

I can add hasHole that does the same thing as hasUnresolvedType. I considered that for the last PR, but didn't know if it was worth having two methods that do the same thing. I do think we should rename it at least once CSDiag is gone, as the only use for UnresolvedType will be for holes. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we better introduce hasHole sooner than later because that gives up a clear distinction here. We can then remove hasUnresolvedType completely when the time comes.

Copy link
Member Author

Choose a reason for hiding this comment

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

Though, if I do add hasHole now, I'd prefer to do that in my refactoring PR, so that this specific PR isn't renaming a bunch of stuff

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, no problem!

return true;

break;
}

default:
break;
}
Expand Down
13 changes: 13 additions & 0 deletions test/Constraints/same_types.swift
Original file line number Diff line number Diff line change
Expand Up @@ -320,3 +320,16 @@ struct Bar<A: P1, B: P1> where A.Assoc == B.Assoc {
fatalError()
}
}

protocol P7 {
associatedtype A
static func fn(args: A)
}

class R<T>: P7 where T: P7, T.A == T.Type { // expected-note {{'T' declared as parameter to type 'R'}}
typealias A = T.Type
static func fn(args: T.Type) {}
}

R.fn(args: R.self) // expected-error {{generic parameter 'T' could not be inferred}}
// expected-note@-1 {{explicitly specify the generic arguments to fix this issue}}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ protocol P {
}

class R<T> : P where T : P, T.A == T.Type {
// expected-note@-1 {{'T' declared as parameter to type 'R'}}
typealias A = T.Type
static func fn(args: T.Type) {}
}

R.fn(args: R.self)
// expected-error@-1 {{type of expression is ambiguous without more context}}
// expected-error@-1 {{generic parameter 'T' could not be inferred}}
// expected-note@-2 {{explicitly specify the generic arguments to fix this issue}}