Skip to content

Commit 7cc67db

Browse files
authored
Merge pull request #63526 from xedin/rdar-105089074-5.8
[5.8][ConstraintSystem] Teach `getCalleeLocator` about pattern matching
2 parents abbaaa9 + 74fb8c1 commit 7cc67db

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

lib/Sema/ConstraintSystem.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,15 @@ ConstraintLocator *ConstraintSystem::getCalleeLocator(
496496
}
497497
}
498498

499+
{
500+
// Pattern match is always a callee regardless of what comes after it.
501+
auto iter = path.rbegin();
502+
if (locator->findLast<LocatorPathElt::PatternMatch>(iter)) {
503+
auto newPath = path.drop_back(iter - path.rbegin());
504+
return getConstraintLocator(anchor, newPath);
505+
}
506+
}
507+
499508
if (locator->findLast<LocatorPathElt::DynamicCallable>()) {
500509
return getConstraintLocator(anchor, LocatorPathElt::ApplyFunction());
501510
}

test/Constraints/patterns.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,3 +540,20 @@ func f60503() {
540540
let (key, _) = settings.enumerate() // expected-error{{cannot find 'settings' in scope}}
541541
let (_, _) = settings.enumerate() // expected-error{{cannot find 'settings' in scope}}
542542
}
543+
544+
// rdar://105089074
545+
enum EWithIdent<Id> where Id: P { // expected-note 2 {{where 'Id' = 'Int'}}
546+
case test(Id)
547+
}
548+
549+
extension [EWithIdent<Int>] {
550+
func test() {
551+
sorted { lhs, rhs in
552+
switch (rhs, rhs) {
553+
case let (.test(x), .test(y)): break
554+
// expected-error@-1 2 {{generic enum 'EWithIdent' requires that 'Int' conform to 'P'}}
555+
case (_, _): break
556+
}
557+
}
558+
}
559+
}

0 commit comments

Comments
 (0)