Open
Description
Description
- There is a function that takes a default value for a parameter
- Let's define a variable as a function type by assigning the function above to the variable
- When the variable is called without a parameter, it does not leverage the default parameter
Steps to reproduce
func showNumber(num: Int = 10) {
print(num)
}
var showNum = showNumber
showNum() // throws an error ("Missing argument for parameter #1 in call")
// modified to take an optional Int? argument
func showNumber(num: Int? = 10) {
if let num = num {
print(num)
} else {
print("num is nil")
}
...
showNum() // still throws the same error
Expected behavior
- Expected
showNum()
to print 10
Environment
- Swift compiler version info :
swift-driver version: 1.75.2 Apple Swift version 5.8 (swiftlang-5.8.0.124.2 clang-1403.0.22.11.100) Target: arm64-apple-macosx13.0
- Xcode version info :
Xcode 14.3 Build version 14E222b
- Deployment target: :
macOS
Metadata
Metadata
Assignees
Labels
A deviation from expected or documented behavior. Also: expected but undesirable behavior.The Swift compiler itselfFeature: default arguments for value parametersFeature: expressionsFeature → declarations: function parametersFeature → types: function typesFeature → expressions: function valuesResolution → not a bug: Reported as a bug but turned out to be expected behavior or programmer errorArea → compiler: Semantic analysis