Skip to content
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

Attempt to copy noncopyable type leads to error asking to submit a bug. #78590

Open
nashysolutions opened this issue Jan 12, 2025 · 0 comments
Open
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels

Comments

@nashysolutions
Copy link

Description

I encountered a compiler error when implementing a protocol I named File with a ~Copyable constraint. The error occurs in the following MockResource struct, which conforms to the File protocol and attempts to initialise with a noncopyable enclosing folder type.

Specifically, the compiler throws an error. “Copy of noncopyable typed value. This is a compiler bug. Please file a bug with a small example of the bug".

Reproduction

// Minimal reproduction

public protocol Directory {
    var location: URL { get }
}

struct MockFolder: Directory {
    let location: URL
}

public protocol File: ~Copyable {
    var name: String { get }
    var enclosingFolder: any Directory { get }
}

struct MockResource: File, ~Copyable {
    let name: String
    let enclosingFolder: any Directory

    init(name: String, enclosingFolder: any Directory) {
        self.name = name
        self.enclosingFolder = enclosingFolder
    }

    // This line produces the compiler error
    init(name: String, enclosingFolderLocation url: URL) {
        let folder = MockFolder(location: url)
        self.init(name: name, enclosingFolder: folder)
    }
}

Error message: Copy of noncopyable typed value. This is a compiler bug. Please file a bug with a small example of the bug.

Expected behavior

The compiler doesn't ask me to file a bug.

Environment

swift-driver version: 1.115.1 Apple Swift version 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1)
Target: arm64-apple-macosx15.0

Additional information

No response

@nashysolutions nashysolutions added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Jan 12, 2025
@nashysolutions nashysolutions changed the title Copy of noncopyable typed value results in incorrect compiler error Copy of noncopyable typed value results in compiler error Jan 12, 2025
@nashysolutions nashysolutions changed the title Copy of noncopyable typed value results in compiler error Unsure what issue is: Compiler is asking me to file a bug... Jan 12, 2025
@nashysolutions nashysolutions changed the title Unsure what issue is: Compiler is asking me to file a bug... Attempt to copy noncopyable type leads to error asking to submit a bug. Jan 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

1 participant