Skip to content

Commit dca1373

Browse files
committed
[ConstraintSystem] Don't fail in matchTypes when two primary archetype types
are not equal when part of a type requirement. This allows the SkipSameTypeRequirement constraint fix to be applied instead.
1 parent 04637ad commit dca1373

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3354,8 +3354,10 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
33543354
if (shouldAttemptFixes()) {
33553355
auto last = locator.last();
33563356
// If this happens as part of the argument-to-parameter
3357-
// conversion, there is a tailored fix/diagnostic.
3358-
if (last && last->is<LocatorPathElt::ApplyArgToParam>())
3357+
// conversion or type requirement, there is a tailored
3358+
// fix/diagnostic.
3359+
if (last && (last->is<LocatorPathElt::ApplyArgToParam>() ||
3360+
last->is<LocatorPathElt::AnyRequirement>()))
33593361
break;
33603362
}
33613363
// If two module types or archetypes were not already equal, there's

test/Generics/conditional_conformances.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ protocol P6: P2 {}
1111

1212
protocol Assoc { associatedtype AT }
1313

14-
func takes_P2<X: P2>(_: X) {} // expected-note {{in call to function 'takes_P2'}}
14+
func takes_P2<X: P2>(_: X) {}
1515
func takes_P5<X: P5>(_: X) {}
1616

1717
// Skip the first generic signature declcontext dump
@@ -87,6 +87,7 @@ struct SameTypeGeneric<T, U> {}
8787
extension SameTypeGeneric: P2 where T == U {}
8888
// expected-note@-1 {{requirement from conditional conformance of 'SameTypeGeneric<U, Int>' to 'P2'}}
8989
// expected-note@-2 {{requirement from conditional conformance of 'SameTypeGeneric<Int, Float>' to 'P2'}}
90+
// expected-note@-3 {{requirement from conditional conformance of 'SameTypeGeneric<U, V>' to 'P2'}}
9091
func same_type_generic_good<U, V>(_: U, _: V)
9192
where U: Assoc, V: Assoc, U.AT == V.AT
9293
{
@@ -96,7 +97,7 @@ func same_type_generic_good<U, V>(_: U, _: V)
9697
}
9798
func same_type_bad<U, V>(_: U, _: V) {
9899
takes_P2(SameTypeGeneric<U, V>())
99-
// expected-error@-1{{generic parameter 'X' could not be inferred}}
100+
// expected-error@-1{{global function 'takes_P2' requires the types 'U' and 'V' be equivalent}}
100101
takes_P2(SameTypeGeneric<U, Int>())
101102
// expected-error@-1{{global function 'takes_P2' requires the types 'U' and 'Int' be equivalent}}
102103
takes_P2(SameTypeGeneric<Int, Float>())

validation-test/compiler_crashers_2_fixed/0158-rdar40165062.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ struct Foo<T, U> {
44
var value: U
55
func bar() -> Foo<T, U> {
66
return Foo(value)
7-
// expected-error@-1 {{'Foo<T, U>' requires the types 'T' and 'U' be equivalent}}
7+
// expected-error@-1 {{referencing initializer 'init(_:)' on 'Foo' requires the types 'T' and 'U' be equivalent}}
88
}
99
}
1010

11-
extension Foo where T == U {
11+
extension Foo where T == U { // expected-note {{where 'T' = 'T', 'U' = 'U'}}
1212
init(_ value: U) {
1313
self.value = value
1414
}

0 commit comments

Comments
 (0)