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

[SR-2634] Private types collide when in extensions of the same base type in the same file #45239

Open
swift-ci opened this issue Sep 14, 2016 · 3 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-2634
Radar None
Original Reporter WeZZard (JIRA User)
Type Bug

Attachment: Download

Environment

OS X 10.11
iOS 10
Xcode 8.0 (8A218a)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash
Assignee None
Priority Medium

md5: 28edbd025d39c8d19d8ae3cd298fc229

is duplicated by:

  • SR-2930 Private nested structs cause segfault if there is a name collision

relates to:

  • SR-2323 Conflicting scope-private members causes crash

Issue Description:

With following code, we can get a Segmentation Fault 11 during the compiling.

import AppKit

extension NSView {
    @objc
    private static func functionA() {
        let a = PrivateStruct(value: "a")
        NSLog(a.value)
    }
    
    private struct PrivateStruct {
        fileprivate let value: String
    }
}

extension NSView {
    @objc
    private static func functionB() {
        let b = PrivateStruct(value: "b")
        NSLog(b.value)
    }
    
    private struct PrivateStruct {
        fileprivate let value: String
    }
}

I'm guessing that calling a private type in an `@objc` qualified function makes it access control level changed, and since there two private `PrivateStruct` defined in `NSView` and both called in an `@objc` qualified function, so they are collided with each other by itself's name during the compiling.

We can change the code to be:

import AppKit

extension NSView {
    @objc
    private static func functionA() {
        let a = PrivateStruct(value: "a")
        NSLog(a.value)
    }
    
    private struct PrivateStruct {
        fileprivate let value: String
    }
}

extension NSView {
    @objc
    private static func functionB() {
        let b = PrivateStruct2(value: "b")
        NSLog(b.value)
    }
    
    private struct PrivateStruct2 {
        fileprivate let value: String
    }
}

And at this time, the Segmentation Fault 11 has gone.

@belkadan
Copy link
Contributor

This actually happens regardless of whether the methods are @objc. It's just the two structs.

@belkadan
Copy link
Contributor

We need some way to disambiguate the two private types in our mangling, and then a way to recover that difference when we look them up later. Failing that, we should reject this code for now.

@Dante-Broggi
Copy link
Contributor

I believe this is fixed (as an error) in the Xcode 9.4.1 toolchain. If so it should be closed.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 2022
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. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software
Projects
None yet
Development

No branches or pull requests

4 participants