Skip to content

[SR-12538] Optimization level bug #54981

@swift-ci

Description

@swift-ci
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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itself

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions