Skip to content

Commit 927b846

Browse files
authored
Merge pull request #61672 from xedin/rdar-101412179
[CSSimplify] Diagnose contextual mismatch between fully resolved depe…
2 parents 8828f1a + a796c45 commit 927b846

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6394,6 +6394,23 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
63946394
if (desugar1->isEqual(desugar2))
63956395
return getTypeMatchSuccess();
63966396

6397+
if (shouldAttemptFixes()) {
6398+
if (!desugar1->hasTypeVariable() && !desugar2->hasTypeVariable()) {
6399+
auto *loc = getConstraintLocator(locator);
6400+
6401+
auto *fix =
6402+
loc->isLastElement<LocatorPathElt::TypeParameterRequirement>()
6403+
? fixRequirementFailure(*this, type1, type2, loc->getAnchor(),
6404+
loc->getPath())
6405+
: ContextualMismatch::create(*this, type1, type2, loc);
6406+
6407+
if (!fix || recordFix(fix))
6408+
return getTypeMatchFailure(locator);
6409+
6410+
return getTypeMatchSuccess();
6411+
}
6412+
}
6413+
63976414
// If one of the dependent member types has no type variables,
63986415
// this comparison is effectively illformed, because dependent
63996416
// member couldn't be simplified down to the actual type, and

test/Constraints/generics.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -983,3 +983,16 @@ func testOverloadGenericVarFn() {
983983
S<((String) -> Void)?>().foo?("")
984984
S<((String) -> Void)?>().foo!("")
985985
}
986+
987+
do {
988+
func foo<T, U>(_: T, _: U) where T: Sequence, U: Sequence, T.Element == U.Element {}
989+
// expected-note@-1 {{required by local function 'foo' where 'T' = 'Set<Int>.Type'}}
990+
// expected-note@-2 {{required by local function 'foo' where 'U' = 'Array<String>.Type'}}
991+
// expected-note@-3 {{where 'T.Element' = 'Set<Int>.Type.Element', 'U.Element' = 'Array<String>.Type.Element'}}
992+
993+
foo(Set<Int>, Array<String>)
994+
// expected-error@-1 {{type 'Set<Int>.Type' cannot conform to 'Sequence'}}
995+
// expected-error@-2 {{type 'Array<String>.Type' cannot conform to 'Sequence'}}
996+
// expected-error@-3 {{local function 'foo' requires the types 'Set<Int>.Type.Element' and 'Array<String>.Type.Element' be equivalent}}
997+
// expected-note@-4 2 {{only concrete types such as structs, enums and classes can conform to protocols}}
998+
}

0 commit comments

Comments
 (0)