Skip to content

Commit 380e370

Browse files
authored
Merge pull request #59853 from hborla/invalid-covariant-erasure
[CSApply] Don't attempt covariant result type erasure when parameters use dynamic `Self`.
2 parents 1d2b044 + 9ab1628 commit 380e370

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

lib/Sema/CSApply.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1720,7 +1720,8 @@ namespace {
17201720
return forceUnwrapIfExpected(result, memberLocator);
17211721
}
17221722

1723-
if (member->getInterfaceType()->hasDynamicSelfType()) {
1723+
auto *func = dyn_cast<FuncDecl>(member);
1724+
if (func && func->getResultInterfaceType()->hasDynamicSelfType()) {
17241725
refTy = refTy->replaceCovariantResultType(containerTy, 2);
17251726
adjustedRefTy = adjustedRefTy->replaceCovariantResultType(
17261727
containerTy, 2);

test/SILGen/dynamic_self.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,17 @@ public class CaptureTwoValuesTest {
519519
}
520520
}
521521

522+
523+
final class Final {
524+
static func useSelf(_ body: (Self) -> ()) {}
525+
}
526+
527+
// CHECK-LABEL: sil hidden [ossa] @$s12dynamic_self13testNoErasureyyyAA5FinalCXEF : $@convention(thin) (@noescape @callee_guaranteed (@guaranteed Final) -> ()) -> () {
528+
func testNoErasure(_ body: (Final) -> ()) {
529+
// CHECK: function_ref @$s12dynamic_self5FinalC7useSelfyyyACXDXEFZ : $@convention(method) (@noescape @callee_guaranteed (@guaranteed Final) -> (), @thick Final.Type) -> ()
530+
return Final.useSelf(body)
531+
}
532+
522533
// CHECK-LABEL: sil_witness_table hidden X: P module dynamic_self {
523534
// CHECK: method #P.f: {{.*}} : @$s12dynamic_self1XCAA1PA2aDP1f{{[_0-9a-zA-Z]*}}FTW
524535

test/Sema/dynamic_self_implicit_conversions.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,10 @@ extension Generic where T == Never {
7474
_ = Generic()[]
7575
}
7676
}
77+
78+
final class Final {
79+
static func useSelf(_ body: (Self) -> ()) {}
80+
}
81+
func testNoErasure(_ body: (Final) -> ()) {
82+
return Final.useSelf(body)
83+
}

0 commit comments

Comments
 (0)