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-1117] Overridden function is not being called when sublassing generic class in Release Build with Whole Module Optimization #43730

Closed
swift-ci opened this issue Mar 31, 2016 · 6 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself inheritance Feature → type declarations → class: Subclassing and inheritance of class members optimized only Flag: An issue whose reproduction requires optimized compilation

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-1117
Radar None
Original Reporter devxoul (JIRA User)
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment
  • Xcode 7.3 (7D175)

  • Swift 2.2

  • Build Configuration: Release

  • Swift Optimization Level: Fast, Whole Module Optimization

Additional Detail from JIRA
Votes 2
Component/s Compiler
Labels Bug, Miscompile, OptimizedOnly
Assignee None
Priority Medium

md5: 37aff8fdb9411626e7558c84434aea40

relates to:

  • SR-1179 Compiler bug: initialising subclass skips to super when using Whole Module optimisation

Issue Description:

Gist: https://gist.github.com/devxoul/b5ac688ffcf70fc9222892c267319ce5

/// A generic class
class Parent<T> {

    func printName() {
        print(self.name())
    }

    func name() -> String {
        return "Parent"
    }

}

/// Subclass of generic class
class Child: Parent<String> {

    /// This method is not being called in Release Build with Whole Module Optimization.
    override func name() -> String {
        return "Child"
    }

}

let child = Child()
child.printName() // expected "Child" but prints "Parent" in Release Build with Whole Module Optimization.
@swift-ci
Copy link
Collaborator Author

Comment by Martin Karlgren (JIRA)

The test case fails even without optimization if the "name" method is made private:

/// A generic class
class Parent<T> {

    func printName() {
        print(self.name())
    }

    private func name() -> String {
        return "Parent"
    }

}

/// Subclass of generic class
class Child: Parent<String> {

    /// This method is not being called
    override private func name() -> String {
        return "Child"
    }

}

let child = Child()
child.printName() // expected "Child" but prints "Parent"

@belkadan
Copy link
Contributor

cc nadav (JIRA User)

@belkadan
Copy link
Contributor

Actually, this seems to work in master. I'm not sure what the fix was, so I'll leave it to Nadav to identify whether this is safe to bring into a Swift 2.2.1.

@swift-ci
Copy link
Collaborator Author

swift-ci commented Apr 4, 2016

Comment by Suyeol Jeon (JIRA)

@belkadan Thanks!

@rudkx
Copy link
Member

rudkx commented Apr 20, 2016

I believe this is already fixed in the 7.3.1 beta that was recently posted.

Suyeol, can you see if the issue is resolved for you with that build?

@slavapestov
Copy link
Member

Confirmed as resolved in Xcode 9 (and likely earlier).

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the inheritance Feature → type declarations → class: Subclassing and inheritance of class members label Nov 10, 2022
This issue was closed.
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 inheritance Feature → type declarations → class: Subclassing and inheritance of class members optimized only Flag: An issue whose reproduction requires optimized compilation
Projects
None yet
Development

No branches or pull requests

5 participants