Skip to content

Commit b07b700

Browse files
authored
Merge pull request #41936 from slavapestov/rqm-preserve-sugar-fix
RequirementMachine: Try harder to preserve sugar
2 parents 5fbd9b4 + 3571fa8 commit b07b700

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

include/swift/AST/TypeMatcher.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,9 +419,8 @@ class TypeMatcher {
419419

420420
bool visitBoundGenericType(CanBoundGenericType firstBGT,
421421
Type secondType, Type sugaredFirstType) {
422-
auto _secondBGT = secondType->getCanonicalType();
423-
if (firstBGT->getKind() == _secondBGT->getKind()) {
424-
auto secondBGT = cast<BoundGenericType>(_secondBGT);
422+
if (firstBGT->getKind() == secondType->getDesugaredType()->getKind()) {
423+
auto secondBGT = secondType->castTo<BoundGenericType>();
425424
if (firstBGT->getDecl() != secondBGT->getDecl())
426425
return mismatch(firstBGT.getPointer(), secondBGT, sugaredFirstType);
427426

lib/AST/RequirementMachine/RequirementLowering.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ static void desugarSameTypeRequirement(Type lhs, Type rhs, SourceLoc loc,
7373

7474
if (secondType->isTypeParameter()) {
7575
result.emplace_back(RequirementKind::SameType,
76-
secondType, firstType);
76+
secondType, sugaredFirstType);
7777
recordedRequirements = true;
7878
return true;
7979
}
8080

8181
errors.push_back(
82-
RequirementError::forConcreteTypeMismatch(firstType,
82+
RequirementError::forConcreteTypeMismatch(sugaredFirstType,
8383
secondType,
8484
loc));
8585
recordedErrors = true;

test/Generics/requirement_machine_diagnostics.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ typealias NotAnInt = Double
1919

2020
protocol X {}
2121

22-
// expected-error@+1{{generic signature requires types 'Double' and 'Int' to be the same}}
22+
// expected-error@+1{{generic signature requires types 'NotAnInt' (aka 'Double') and 'Int' to be the same}}
2323
extension X where NotAnInt == Int {}
2424

2525
protocol EqualComparable {
@@ -194,3 +194,7 @@ func inferred3<T : P11>(_: T) where T.X : Hashable, T.Z == Set<T.Y>, T.X == T.Y
194194
func inferred4<T : P11>(_: T) where T.Z == Set<T.Y>, T.X : Hashable, T.X == T.Y {}
195195
func inferred5<T : P11>(_: T) where T.Z == Set<T.X>, T.Y : Hashable, T.X == T.Y {}
196196
func inferred6<T : P11>(_: T) where T.Y : Hashable, T.Z == Set<T.X>, T.X == T.Y {}
197+
198+
func typeMatcherSugar<T>(_: T) where Array<Int> == Array<T>, Array<Int> == Array<T> {}
199+
// expected-warning@-1 2{{redundant same-type constraint 'Array<Int>' == 'Array<T>'}}
200+
// expected-warning@-2{{redundant same-type constraint 'T' == 'Int'}}

0 commit comments

Comments
 (0)