Skip to content

[SR-11778] Callable types do not respect default argument values #54185

@xedin

Description

@xedin
Previous ID SR-11778
Radar rdar://problem/56998726
Original Reporter @xedin
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee @hamishknight
Priority Medium

md5: db8faab81e6ef687c92bbc71a7ec459b

Issue Description:

Default argument values are not respected when using the newly added callAsFunction/static callable feature of Swift 5.1. See example playground. I would expect the code to execute without an error, but instead the compiler wants me to provide a value for “completion:” even though I define a default value in the callAsFunction method.

struct DoubleANumber {
  func callAsFunction(_ x: Int, completion: (Int) -> Void = { _ in }) {
    completion(x + x)
  }
}

let x = DoubleANumber()
x(3)

Metadata

Metadata

Assignees

Labels

bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itself

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions