Skip to content

[5.9] AST: Inherit access level of an opaque type decl from its naming decl #66516

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
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
6 changes: 6 additions & 0 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3868,6 +3868,12 @@ getAdjustedFormalAccess(const ValueDecl *VD, const DeclContext *useDC,
}

AccessLevel ValueDecl::getEffectiveAccess() const {
// Opaque type decls inherit accessibility from their naming decl.
if (auto *opaqueType = dyn_cast<OpaqueTypeDecl>(this)) {
if (auto *namingDecl = opaqueType->getNamingDecl())
return namingDecl->getEffectiveAccess();
}

auto effectiveAccess =
getAdjustedFormalAccess(this, /*useDC=*/nullptr,
/*treatUsableFromInlineAsPublic=*/true);
Expand Down
13 changes: 13 additions & 0 deletions test/IRGen/Inputs/AlwaysInlineIntoWithOpaque.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,16 @@ public func testInlineWithOpaque() -> some P {
}
return 2.0
}

@_alwaysEmitIntoClient
public func testInlineWithOpaqueUsableFromInline() -> some P {
if #available(macOS 9.0, *) {
return usableFromInline()
}
return 4.0
}

@usableFromInline
func usableFromInline() -> some P {
return 3
}
5 changes: 5 additions & 0 deletions test/IRGen/Inputs/AlwaysInlineIntoWithOpaqueReplacement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ extension Int : P {

extension Double : P {
}

@usableFromInline
func usableFromInline() -> some P {
return 3
}
12 changes: 10 additions & 2 deletions test/IRGen/opaque_result_alwaysInlineIntoClient.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// RUN: %empty-directory(%t)
// RUN: %target-build-swift -target %target-cpu-apple-macosx10.15 -parse-as-library -emit-library -emit-module-path %t/AlwaysInlineIntoWithOpaque.swiftmodule -module-name AlwaysInlineIntoWithOpaque %S/Inputs/AlwaysInlineIntoWithOpaque.swift -o %t/%target-library-name(AlwaysInlineIntoWithOpaque)
// RUN: %target-build-swift -target %target-cpu-apple-macosx10.15 -parse-as-library -emit-library -emit-module-path %t/AlwaysInlineIntoWithOpaque.swiftmodule -module-name AlwaysInlineIntoWithOpaque -enable-library-evolution %S/Inputs/AlwaysInlineIntoWithOpaque.swift -o %t/%target-library-name(AlwaysInlineIntoWithOpaque)
// RUN: %target-codesign %t/%target-library-name(AlwaysInlineIntoWithOpaque)
// RUN: %target-build-swift -target %target-cpu-apple-macosx10.15 -lAlwaysInlineIntoWithOpaque -module-name main -I %t -L %t %s -o %t/a.out
// RUN: %target-codesign %t/a.out
// RUN: %target-run %t/a.out | %FileCheck %s

// RUN: %target-build-swift -target %target-cpu-apple-macosx10.15 -parse-as-library -emit-library -emit-module-path %t/AlwaysInlineIntoWithOpaque.swiftmodule -module-name AlwaysInlineIntoWithOpaque %S/Inputs/AlwaysInlineIntoWithOpaqueReplacement.swift -o %t/%target-library-name(AlwaysInlineIntoWithOpaque)
// RUN: %target-build-swift -target %target-cpu-apple-macosx10.15 -parse-as-library -emit-library -emit-module-path %t/AlwaysInlineIntoWithOpaque.swiftmodule -module-name AlwaysInlineIntoWithOpaque -enable-library-evolution %S/Inputs/AlwaysInlineIntoWithOpaqueReplacement.swift -o %t/%target-library-name(AlwaysInlineIntoWithOpaque)
// RUN: %target-codesign %t/a.out
// RUN: %target-run %t/a.out | %FileCheck %s

Expand All @@ -27,3 +27,11 @@ public func test() {

test()
// CHECK: 1

public func testUsableFromInline() {
let p = testInlineWithOpaqueUsableFromInline()
print(p)
}

testUsableFromInline()
// CHECK: 3
5 changes: 5 additions & 0 deletions test/TBD/opaque_result_type.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ public func dynReplacement(x: String) -> some P {
return "replaced"
}

@usableFromInline
func ufi() -> some O {
return 1
}

extension String: P {
public func poo() -> some O {
return 0
Expand Down