-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
Missing compiler warning #70630
Comments
Is the typo init (form sender : String) vs init (from sender : String, as name : String = "Bastie")
|
@msrutek-paylocity Thanks!!! I like my German "Autokorrektur"... //
// main.swift
// MissingInitInfo
//
// Created by Sebastian Ritter on 26.12.23.
//
import Foundation
// ✅ expected error
//let _ = Printable ()
// ✅ expected result
let _ = Printable (from: "Sebastian")
// ✅ expected result
let _ = Printable (from: "Sebastian", as: "Mr. Ritter")
public class Printable {
public init (from sender : String) {
print ("Hello from \(sender)!")
}
public init (from sender : String, as name : String = "Bastie") { // 🆘 in result of init with one parameter unusable default value "Bastie" from init method
print ("Hello from \(name)?")
}
} |
This is expected behavior currently. See https://github.com/apple/swift/blob/main/docs/ReferenceGuides/UnderscoredAttributes.md#_disfavoredoverload and there is some great forum posts discussing the issue. Suggestion 1:
Suggestion 2:
@_disfavoredOverload
public init(from sender: String) {
print("Hello from \(sender)!")
}
_ = Printable(from: "Sebastian") // Hello from Bastie? |
Feel free to ask further. If no reply is received, I think we can close it later. |
Per Swift overload ranking rules the function that best matches the let _ = Printable.init(from:as:)("Sebastian")
Important Whether any of this is reasonable depends on the actual use case. |
Thanks for sharing the |
I do not think a warning is justified here. The API design expectation behind this sort of overloading is that |
The second way can be compiled, and the former will report a compiler error - |
Right, thanks. Function values do not retain default arguments. |
typo - see error description 2 days later 🥺
Description
In result of overload functions / methods with same name but more parameters and these parameters get default values (line 23) the "simple" function (line 20) appears uncallable.
Reproduction
Expected behavior
Compiler warning at line 20 as uncallable method / function
Environment
swift-driver version: 1.87.3 Apple Swift version 5.9.2 (swiftlang-5.9.2.2.56 clang-1500.1.0.2.5)
Target: arm64-apple-macosx14.0
Additional information
No response
The text was updated successfully, but these errors were encountered: