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-14564] "\(Self.self)" causes issue on Xcode 12.5 when Swift is optimized #398
Comments
Comment by Matteo Longeri (JIRA) UPDATE: To be sure that this issue is directly related to Xcode 12.5 I have created a simple project, defining: class MyClass {
var classname: String {
"\(Self.self)"
}
} and calling it from the class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
let c = MyClass()
print(c.classname)
}
} When I activate Just to confirm that this issue is not directly related to the app I am working on, but it is reproducible in any context. Matteo |
@swift-ci create |
Thanks for reporting. This is already fixed in Swift 5.5: apple/swift#36717 |
Comment by Matteo Longeri (JIRA) Thanks for your answer @eeckstein! Best regards, Matteo |
Comment by Andrey Yakushev (JIRA) Issue appears only in classes. It's fine to write "\(Self.self)" inside structs. |
Don't transform `Optional<T>` -> `T?` if it would cause a performance issue
Additional Detail from JIRA
md5: 4cc049e4929f10d973d6a2409610d84f
Issue Description:
Using Xcode 12.5 I have identified an issue with this instruction
"(Self.self)"
when it runs on a build created settingSWIFT_OPTIMIZATION_LEVEL
to-O
(Optimize for speed).The instruction above is executed in a superclass (subclass of
UIView
) when it to load a NIB:Instead of getting the right subclass name, it simply returns
"Self"
and this generate the following error:This never happens before with previous versions of Xcode, and it still does not happen when the build is generate without using optimization
-Onone
.To fix it I have changed
"(Self.self)"
with"(type(of: self))"
. This way it works, but I think that it should be investigate why the original version causes that kind of issue when Swift is optimized.Forcing optimization in Debug, I was able to reproduce the issue. I have also tried to insert a breakpoint before the crash, trying to execute the instruction in Console with
po
command, but it works as expected, printing the right class name.The text was updated successfully, but these errors were encountered: