-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Open
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 itselfdefault argumentsFeature: default arguments for value parametersFeature: default arguments for value parametersexpressionsFeature: expressionsFeature: expressionsfunction parametersFeature → declarations: function parametersFeature → declarations: function parametersfunction typesFeature → types: function typesFeature → types: function typesfunction valuesFeature → expressions: function valuesFeature → expressions: function valuesnot a bugResolution → not a bug: Reported as a bug but turned out to be expected behavior or programmer errorResolution → not a bug: Reported as a bug but turned out to be expected behavior or programmer errorswift 5.8type checkerArea → compiler: Semantic analysisArea → compiler: Semantic analysis
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
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 itselfdefault argumentsFeature: default arguments for value parametersFeature: default arguments for value parametersexpressionsFeature: expressionsFeature: expressionsfunction parametersFeature → declarations: function parametersFeature → declarations: function parametersfunction typesFeature → types: function typesFeature → types: function typesfunction valuesFeature → expressions: function valuesFeature → expressions: function valuesnot a bugResolution → not a bug: Reported as a bug but turned out to be expected behavior or programmer errorResolution → not a bug: Reported as a bug but turned out to be expected behavior or programmer errorswift 5.8type checkerArea → compiler: Semantic analysisArea → compiler: Semantic analysis