Skip to content

[CSApply] Don't attempt covariant result type erasure when parameters use dynamic Self. #59853

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/Sema/CSApply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1720,7 +1720,8 @@ namespace {
return forceUnwrapIfExpected(result, memberLocator);
}

if (member->getInterfaceType()->hasDynamicSelfType()) {
auto *func = dyn_cast<FuncDecl>(member);
if (func && func->getResultInterfaceType()->hasDynamicSelfType()) {
refTy = refTy->replaceCovariantResultType(containerTy, 2);
adjustedRefTy = adjustedRefTy->replaceCovariantResultType(
containerTy, 2);
Expand Down
11 changes: 11 additions & 0 deletions test/SILGen/dynamic_self.swift
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,17 @@ public class CaptureTwoValuesTest {
}
}


final class Final {
static func useSelf(_ body: (Self) -> ()) {}
}

// CHECK-LABEL: sil hidden [ossa] @$s12dynamic_self13testNoErasureyyyAA5FinalCXEF : $@convention(thin) (@noescape @callee_guaranteed (@guaranteed Final) -> ()) -> () {
func testNoErasure(_ body: (Final) -> ()) {
// CHECK: function_ref @$s12dynamic_self5FinalC7useSelfyyyACXDXEFZ : $@convention(method) (@noescape @callee_guaranteed (@guaranteed Final) -> (), @thick Final.Type) -> ()
return Final.useSelf(body)
}

// CHECK-LABEL: sil_witness_table hidden X: P module dynamic_self {
// CHECK: method #P.f: {{.*}} : @$s12dynamic_self1XCAA1PA2aDP1f{{[_0-9a-zA-Z]*}}FTW

Expand Down
7 changes: 7 additions & 0 deletions test/Sema/dynamic_self_implicit_conversions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,10 @@ extension Generic where T == Never {
_ = Generic()[]
}
}

final class Final {
static func useSelf(_ body: (Self) -> ()) {}
}
func testNoErasure(_ body: (Final) -> ()) {
return Final.useSelf(body)
}