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-12538] Optimization level bug #54981

Closed
swift-ci opened this issue Apr 7, 2020 · 2 comments
Closed

[SR-12538] Optimization level bug #54981

swift-ci opened this issue Apr 7, 2020 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Apr 7, 2020

Previous ID SR-12538
Radar rdar://problem/61911112
Original Reporter spring (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Xcode 11.2.1
Swift 5 or Swift 4.2
Optimization Level

  • Debug: -Onone

  • Release: -Osize

Additional Detail from JIRA
Votes 1
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 2287c0b1c6f1f2b96e703e1408ce4835

Issue Description:

Hi, the below code result is different if it runs in Debug build configuration and Release build configuration.

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        Maker<Child>.hello()
    }
}

class GrandFather {

    required init() {
        print("GrandFather init")
    }

    class func instance() -> GrandFather {
        print("should be overridden by subclass")
        return self.init()
    }
}

class Parent: GrandFather {

    required init() {
        super.init()
        print("Parent init")
    }

    override class func instance() -> Parent {
        return self.init()
    }
}

class Child: Parent {

    required init() {
        super.init()
        print("Child init")
    }

}

class Maker<ModelClass: GrandFather> {

    static func hello() {
        print(ModelClass.instance())
    }
}

If I run it under Debug configuration, I get this:

GrandFather init
Parent init
Child init
Demo.Child

But, if Release configuration, the result is:

GrandFather init
Parent init
Demo.Parent

I don't know why Maker.hello() get the different instance types?

@jckarter
Copy link
Member

jckarter commented Apr 7, 2020

@swift-ci create

@eeckstein
Copy link
Member

Thanks for reporting!

Fixed in #31151

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 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
Projects
None yet
Development

No branches or pull requests

3 participants