Skip to content

[5.8][ConstraintSystem] Teach getCalleeLocator about pattern matching #63526

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
Feb 17, 2023
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
9 changes: 9 additions & 0 deletions lib/Sema/ConstraintSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,15 @@ ConstraintLocator *ConstraintSystem::getCalleeLocator(
}
}

{
// Pattern match is always a callee regardless of what comes after it.
auto iter = path.rbegin();
if (locator->findLast<LocatorPathElt::PatternMatch>(iter)) {
auto newPath = path.drop_back(iter - path.rbegin());
return getConstraintLocator(anchor, newPath);
}
}

if (locator->findLast<LocatorPathElt::DynamicCallable>()) {
return getConstraintLocator(anchor, LocatorPathElt::ApplyFunction());
}
Expand Down
17 changes: 17 additions & 0 deletions test/Constraints/patterns.swift
Original file line number Diff line number Diff line change
Expand Up @@ -540,3 +540,20 @@ func f60503() {
let (key, _) = settings.enumerate() // expected-error{{cannot find 'settings' in scope}}
let (_, _) = settings.enumerate() // expected-error{{cannot find 'settings' in scope}}
}

// rdar://105089074
enum EWithIdent<Id> where Id: P { // expected-note 2 {{where 'Id' = 'Int'}}
case test(Id)
}

extension [EWithIdent<Int>] {
func test() {
sorted { lhs, rhs in
switch (rhs, rhs) {
case let (.test(x), .test(y)): break
// expected-error@-1 2 {{generic enum 'EWithIdent' requires that 'Int' conform to 'P'}}
case (_, _): break
}
}
}
}