Skip to content

Commit 791a1bd

Browse files
committed
Adjust types for @preconcurrency in the @_implementationOnly override
Fixes rdar://96338926.
1 parent f13a521 commit 791a1bd

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

lib/Sema/TypeCheckAttr.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3602,6 +3602,13 @@ AttributeChecker::visitImplementationOnlyAttr(ImplementationOnlyAttr *attr) {
36023602
overrideInterfaceFuncTy->getResult(), overrideInterfaceInfo);
36033603
}
36043604

3605+
// If @preconcurrency is involved, strip concurrency from the types before
3606+
// comparing them.
3607+
if (overridden->preconcurrency() || VD->preconcurrency()) {
3608+
derivedInterfaceTy = derivedInterfaceTy->stripConcurrency(true, false);
3609+
overrideInterfaceTy = overrideInterfaceTy->stripConcurrency(true, false);
3610+
}
3611+
36053612
if (!derivedInterfaceTy->isEqual(overrideInterfaceTy)) {
36063613
diagnose(VD, diag::implementation_only_override_changed_type,
36073614
overrideInterfaceTy);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
open class BSuper {
2+
public init() { }
3+
}
4+
5+
open class BSub: BSuper {
6+
public override init() { }
7+
}
8+
9+
open class C {
10+
@preconcurrency open func f(_: @escaping @Sendable () -> Void) { }
11+
@preconcurrency open func g(_: @escaping @Sendable () -> Void) -> BSuper { BSuper() }
12+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/ImplementationOnlyDefs.swiftmodule -module-name ImplementationOnlyDefs %S/Inputs/ImplementationOnlyDefs.swift
3+
// RUN: %target-typecheck-verify-swift -disable-availability-checking -I %t
4+
5+
// REQUIRES: concurrency
6+
7+
@_implementationOnly import ImplementationOnlyDefs
8+
9+
class D: C {
10+
@_implementationOnly
11+
override func f(_: @escaping () -> Void) { }
12+
13+
@_implementationOnly
14+
override func g(_: @escaping () -> Void) -> BSub { BSub() }
15+
// expected-error@-1{{'@_implementationOnly' override must have the same type as the declaration it overrides ('(@escaping () -> Void) -> BSuper')}}
16+
}

0 commit comments

Comments
 (0)