Skip to content

Commit b4949a0

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 b4949a0

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: %target-typecheck-verify-swift -target %target-cpu-apple-macosx10.15
2+
3+
// REQUIRES: objc_interop
4+
// REQUIRES: OS=macosx
5+
6+
protocol P {
7+
associatedtype T
8+
func f() -> T
9+
}
10+
11+
struct S: P {
12+
func f() -> some Any { return 3 }
13+
}
14+
15+
struct G<T> {
16+
typealias Foo = (T?, S.T)
17+
}
18+
19+
func f<T>(t: T) -> G<T>.Foo {
20+
return (t, S().f()) // Ok
21+
}

0 commit comments

Comments
 (0)