Skip to content

Commit 1a304e2

Browse files
committed
[CSApply] Attempt value-to-opaque-result abstraction only after canonicalization
`ExprRewriter::coerceToType` should canonicalize contextual type before attempting to use it for value abstraction, because sugared type could have typealias references that hide their underlying opaque result types. Resolves: rdar://98577451
1 parent 633cc34 commit 1a304e2

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

lib/Sema/CSApply.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6850,11 +6850,11 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
68506850
// below is just an approximate check since the above would be expensive to
68516851
// verify and still relies on the type checker ensuing `fromType` is
68526852
// compatible with any opaque archetypes.
6853-
if (toType->hasOpaqueArchetype() &&
6853+
if (toType->getCanonicalType()->hasOpaqueArchetype() &&
68546854
cs.getConstraintLocator(locator)->isForContextualType()) {
68556855
// Find the opaque type declaration. We need its generic signature.
68566856
OpaqueTypeDecl *opaqueDecl = nullptr;
6857-
bool found = toType.findIf([&](Type type) {
6857+
bool found = toType->getCanonicalType().findIf([&](Type type) {
68586858
if (auto opaqueType = type->getAs<OpaqueTypeArchetypeType>()) {
68596859
opaqueDecl = opaqueType->getDecl();
68606860
return true;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
protocol P {
4+
associatedtype T
5+
func f() -> T
6+
}
7+
8+
struct S: P {
9+
func f() -> some Any { return 3 }
10+
}
11+
12+
struct G<T> {
13+
typealias Foo = (T?, S.T)
14+
}
15+
16+
func f<T>(t: T) -> G<T>.Foo {
17+
return (t, S().f())
18+
}

0 commit comments

Comments
 (0)