Skip to content

Commit e081154

Browse files
committed
RequirementMachine: Fix for FunctionType canonicalization subtlety
We assumed that replacing a subcomponent of a CanType with another CanType always produces a CanType. This is no longer true because () throws(Never) -> () canonicalizes down to () -> ().
1 parent 0a4807b commit e081154

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

lib/AST/RequirementMachine/TypeDifference.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,13 +348,13 @@ swift::rewriting::buildTypeDifference(
348348
auto resultSymbol = [&]() {
349349
switch (symbol.getKind()) {
350350
case Symbol::Kind::Superclass:
351-
return Symbol::forSuperclass(CanType(resultType),
351+
return Symbol::forSuperclass(resultType->getCanonicalType(),
352352
resultSubstitutions, ctx);
353353
case Symbol::Kind::ConcreteType:
354-
return Symbol::forConcreteType(CanType(resultType),
354+
return Symbol::forConcreteType(resultType->getCanonicalType(),
355355
resultSubstitutions, ctx);
356356
case Symbol::Kind::ConcreteConformance:
357-
return Symbol::forConcreteConformance(CanType(resultType),
357+
return Symbol::forConcreteConformance(resultType->getCanonicalType(),
358358
resultSubstitutions,
359359
symbol.getProtocol(),
360360
ctx);

test/Generics/typed_throws.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// RUN: %target-typecheck-verify-swift -debug-generic-signatures -enable-experimental-feature TypedThrows 2>&1 | %FileCheck %s
2+
3+
protocol P1 {
4+
associatedtype A
5+
}
6+
7+
// CHECK-LABEL: typed_throws.(file).f1@
8+
// CHECK-NEXT: Generic signature: <T where T : P1, T.[P1]A == Never>
9+
func f1<T: P1>(_: T) where () throws(T.A) -> () == () -> () {}
10+
11+
// CHECK-LABEL: typed_throws.(file).f2@
12+
// CHECK-NEXT: Generic signature: <T where T : P1, T.[P1]A == any Error>
13+
func f2<T: P1>(_: T) where () throws(T.A) -> () == () throws -> () {}
14+
15+
protocol P2 {
16+
associatedtype A where A == () throws(E) -> ()
17+
associatedtype E
18+
}
19+
20+
// CHECK-LABEL: typed_throws.(file).f3@
21+
// CHECK-NEXT: Generic signature: <T where T : P2, T.[P2]E == Never>
22+
func f3<T: P2>(_: T) where T.A == () -> () {}
23+
24+
// CHECK-LABEL: typed_throws.(file).f4@
25+
// CHECK-NEXT: Generic signature: <T where T : P2, T.[P2]E == any Error>
26+
func f4<T: P2>(_: T) where T.A == () throws -> () {}

0 commit comments

Comments
 (0)