Skip to content

Commit f3fcc44

Browse files
committed
Sema: Handle PackElement locator in repairFailures()
1 parent afbf844 commit f3fcc44

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5881,6 +5881,19 @@ bool ConstraintSystem::repairFailures(
58815881
break;
58825882
}
58835883

5884+
case ConstraintLocator::PackElement: {
5885+
path.pop_back();
5886+
5887+
if (!path.empty() && path.back().is<LocatorPathElt::PackType>())
5888+
path.pop_back();
5889+
5890+
if (!path.empty() && path.back().is<LocatorPathElt::PackType>())
5891+
path.pop_back();
5892+
5893+
return repairFailures(lhs, rhs, matchKind, conversionsOrFixes,
5894+
getConstraintLocator(anchor, path));
5895+
}
5896+
58845897
case ConstraintLocator::SequenceElementType: {
58855898
// This is going to be diagnosed as `missing conformance`,
58865899
// so no need to create duplicate fixes.

lib/Sema/ConstraintSystem.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6708,7 +6708,17 @@ SourceRange constraints::getSourceRange(ASTNode anchor) {
67086708

67096709
static Optional<Requirement> getRequirement(ConstraintSystem &cs,
67106710
ConstraintLocator *reqLocator) {
6711-
auto reqLoc = reqLocator->getLastElementAs<LocatorPathElt::AnyRequirement>();
6711+
ArrayRef<LocatorPathElt> path = reqLocator->getPath();
6712+
6713+
// If we have something like ... -> type req # -> pack element #, we're
6714+
// solving a requirement of the form T : P where T is a type parameter pack
6715+
if (!path.empty() && path.back().is<LocatorPathElt::PackElement>())
6716+
path = path.drop_back();
6717+
6718+
if (path.empty())
6719+
return None;
6720+
6721+
auto reqLoc = path.back().getAs<LocatorPathElt::AnyRequirement>();
67126722
if (!reqLoc)
67136723
return None;
67146724

test/Constraints/variadic_generic_constraints.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,12 @@ func takesC<T...: C>(_: T...) {} // expected-note {{where 'T' = 'NotSubclassOfC
2626
takesC() // ok
2727
takesC(SubclassOfC(), SubclassOfC(), SubclassOfC()) // ok
2828

29-
takesC(SubclassOfC(), NotSubclassOfC(), SubclassOfC()) // expected-error {{global function 'takesC' requires that 'NotSubclassOfC' inherit from 'C'}}
29+
takesC(SubclassOfC(), NotSubclassOfC(), SubclassOfC()) // expected-error {{global function 'takesC' requires that 'NotSubclassOfC' inherit from 'C'}}
30+
31+
func takesParallelSequences<T..., U...>(t: T..., u: U...) where T: Sequence, U: Sequence, T.Element == U.Element {}
32+
// expected-note@-1 {{where 'T.Element' = 'String', 'U.Element' = 'Int'}}
33+
34+
takesParallelSequences() // ok
35+
takesParallelSequences(t: Array<Int>(), u: Set<Int>()) // ok
36+
takesParallelSequences(t: Array<String>(), Set<Int>(), u: Set<String>(), Array<Int>()) // ok
37+
takesParallelSequences(t: Array<String>(), Set<Int>(), u: Array<Int>(), Set<String>()) // expected-error {{global function 'takesParallelSequences(t:u:)' requires the types 'String' and 'Int' be equivalent}}

0 commit comments

Comments
 (0)