Skip to content

Encountering "Constant strings cannot be deallocated" in Linux foundation #4642

Closed
@dhoepfl

Description

@dhoepfl

Describe the bug
Using Bundle.module.url(forResource:, withExtension:,subdirectory:) results in error message "Foundation/NSCFString.swift:119: Fatal error: Constant strings cannot be deallocated"

Steps To Reproduce
Steps to reproduce the behavior:

  1. Create a new package mkdir swiftbug; cd swiftbug; swift package init
  2. In Package.swift, add a resource to the testTarget:
        .testTarget(
            name: "swiftbugTests",
            dependencies: ["swiftbug"],
            resources: [
               .copy("Resources")
            ]),
  1. Create a resource: mkdir Tests/swiftbugTests/Resources; touch Tests/swiftbugTests/Resources/dummy.png
  2. Modify the test in Tests/swiftbugTests/swiftbugTests.swift to match:
    func testExample() async throws {
        // This is an example of a functional test case.
        // Use XCTAssert and related functions to verify your tests produce the correct
        // results.
        XCTAssertEqual(swiftbug().text, "Hello, World!")

        _ = Bundle.module.url(forResource: "filename", withExtension: nil, subdirectory: "Resources")
    }
  1. Run the test: swift test

Expected behavior
Tests should finish without an error.

Actual result

Building for debugging...
[20/20] Linking swiftbugPackageTests.xctest
Build complete! (4.82s)
Test Suite 'All tests' started at 2022-10-10 17:57:06.166
Test Suite 'debug.xctest' started at 2022-10-10 17:57:06.171
Test Suite 'swiftbugTests' started at 2022-10-10 17:57:06.171
Test Case 'swiftbugTests.testExample' started at 2022-10-10 17:57:06.172
Foundation/NSCFString.swift:119: Fatal error: Constant strings cannot be deallocated
error: Exited with signal code 4

Environment (please fill out the following information)

  • OS: Debian Linux
  • Self compiled swiftc: LLVM c205842748e1789, Swift 1f8a5d6045262bb

Additional context
Might be related to/regression of #3785

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions