-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Closed
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itself
Description
| 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.ChildBut, if Release configuration, the result is:
GrandFather init
Parent init
Demo.ParentI don't know why Maker.hello() get the different instance types?
Metadata
Metadata
Assignees
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itself