mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
This patch is follow-up work from #78942 and imports non-public members, which were previously not being imported. Those members can be accessed in a Swift file blessed by the SWIFT_PRIVATE_FILEID annotation. As a consequence of this patch, we are also now importing inherited members that are inaccessible from the derived classes, because they were declared private, or because they were inherited via nested private inheritance. We import them anyway but mark them unavailable, for better diagnostics and to (somewhat) simplify the import logic for inheritance. Because non-public base class members are now imported too, this patch inflames an existing issue where a 'using' declaration on an inherited member with a synthesized name (e.g., operators) produces duplicate members, leading to miscompilation (resulting in a runtime crash). This was not previously noticed because a 'using' declaration on a public inherited member is not usually necessary, but is a common way to expose otherwise non-public members. This patch puts in a workaround to prevent this from affecting the behavior of MSVC's std::optional implementation, which uses this pattern of 'using' a private inherited member. That will be fixed in a follow-up patch. Follow-up work is also needed to correctly diagnose ambiguous overloads in cases of multiple inheritance, and to account for virtual inheritance. rdar://137764620
28 lines
1.4 KiB
Swift
28 lines
1.4 KiB
Swift
// RUN: %target-swift-ide-test -print-module -module-to-print=NonPublicShadow -print-access -I %S/Inputs -source-filename=x -cxx-interoperability-mode=default | %FileCheck %s
|
|
|
|
// We only check the module interface of Shadow to keep this test concise
|
|
|
|
// CHECK: public struct Shadow {
|
|
// CHECK-NEXT: public init()
|
|
// CHECK-NEXT: public func publPublShadowed() -> Return
|
|
// CHECK-NEXT: public func protPublShadowed() -> Return
|
|
// CHECK-NEXT: public func privPublShadowed() -> Return
|
|
// CHECK-NEXT: private func publPrivShadowed() -> Return
|
|
// CHECK-NEXT: private func protPrivShadowed() -> Return
|
|
// CHECK-NEXT: private func privPrivShadowed() -> Return
|
|
|
|
// Currently, ImportDecl.cpp::loadAllMembersOfRecordDecl() does not correctly
|
|
// handle multiple inheritance, so it only loads one of each ambiguous member.
|
|
|
|
// TODO: public func publOrPriv() -> Return
|
|
// TODO: @available(*, unavailable, message: "this base member is not accessible because it is private")
|
|
// TODO: private func publOrPriv() -> Return
|
|
|
|
// TODO: private func protOrPriv() -> Return
|
|
// TODO: @available(*, unavailable, message: "this base member is not accessible because it is private")
|
|
// TODO: private func protOrPriv() -> Return
|
|
|
|
// TODO: public func publOrProt() -> Return
|
|
// TODO: private func publOrProt() -> Return
|
|
// CHECK: }
|