You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SR-11688 Swift should consider functions with default args ambiguous when there is another function with an identical signature
Issue Description:
When a method in a class that has arguments with default values clashes with other methods in a superclass, the compiler should warn the user that the method won't ever be called with those default arguments.
A common scenario is with init in UIKit code.
classSubview:UIView{overrideinit(frame:CGRect){
super.init(frame: frame)print("init frame")}init(other:Int=0){
super.init(frame:.zero)print("init other \(other)")}requiredinit?(coder aDecoder:NSCoder){fatalError("init(coder:) has not been implemented")}}letsub=Subview()
In the above example the second init won't ever be called with the default argument, as Swift will always prefer the superclass (UIView) init with zero arguments. This can be misleading and a cause of bugs.
As Jordan pointed out on Twitter the general case is tricky but it may be worth adding some diagnostics to the simple case.
The text was updated successfully, but these errors were encountered:
Additional Detail from JIRA
md5: fba846f6e7aaee6895be1ba7ece60135
relates to:
Issue Description:
When a method in a class that has arguments with default values clashes with other methods in a superclass, the compiler should warn the user that the method won't ever be called with those default arguments.
A common scenario is with init in UIKit code.
In the above example the second init won't ever be called with the default argument, as Swift will always prefer the superclass (UIView) init with zero arguments. This can be misleading and a cause of bugs.
As Jordan pointed out on Twitter the general case is tricky but it may be worth adding some diagnostics to the simple case.
The text was updated successfully, but these errors were encountered: