Skip to content

Add unit test for surfacing potential regression from #5728 #5991

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 1 commit into from
Apr 21, 2023
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// swift-tools-version:5.8
import PackageDescription

// This package acts as a regression test for the FoundationlessPackages to
// assert that Swift targets with resources are not affected by using
// `@_implementationOnly import Foundation` in the generated resource accessor.
let package = Package(
name: "UtilsWithFoundationPkg",
targets: [
.target(
name: "UtilsWithFoundationPkg",
resources: [
.copy("foo.txt"),
]
)
]
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Foundation

@frozen
public enum FooUtils { }

extension FooUtils {
public static let foo: String = "Hello, World!"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foo
9 changes: 9 additions & 0 deletions Tests/FunctionalTests/ResourcesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@ class ResourcesTests: XCTestCase {
}
}

func testSwiftResourceAccessorDoesNotCauseInconsistentImportWarning() throws {
try fixture(name: "Resources/FoundationlessClient/UtilsWithFoundationPkg") { fixturePath in
XCTAssertBuilds(
fixturePath,
Xswiftc: ["-warnings-as-errors"]
Copy link
Contributor Author

@ncooke3 ncooke3 Dec 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Starting a thread to discuss...

@xwu: I'm not sure this warning should be triggered at all when the imports do not match exactly... Or, we should have some way to silence it in code, defaulting to parens.

I did some researching and there is some good discussion in https://forums.swift.org/t/update-on-implementation-only-imports/26996/12 as to why the warning is triggered in the first place. What makes this tricky is that I do not think there is a way to pass a flag to silence only this warning.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understand the rationale, but this issue points to a use case where the current design doesn’t serve our needs (and, incidentally, if it were ever stabilized as an “access level” on import like once pitched, wouldn’t behave like access modifiers do elsewhere).

I posted some thoughts over in the linked PR about why even import scanning would be brittle, and I think possibly the most resilient solution here is to come up with a new “flavor” of @_implementationOnly (rather than a flag) that explicitly acknowledges that it can be overridden or “upgraded.”

)
}
}

func testResourceBundleInClangPackageWhenRunningSwiftTest() throws {
#if !os(macOS)
// Running swift-test fixtures on linux is not yet possible.
Expand Down