Skip to content
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

[SR-504] Functions with default values cannot be called as parameters #43121

Open
swift-ci opened this issue Jan 9, 2016 · 0 comments
Open
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself type checker Area → compiler: Semantic analysis

Comments

@swift-ci
Copy link
Contributor

swift-ci commented Jan 9, 2016

Previous ID SR-504
Radar rdar://problem/51939453
Original Reporter Yoontsaw (JIRA User)
Type Bug

Attachment: Download

Environment

OS X 10.11, Xcode(swift 2.1)/REPL(swift 2.2-dev)

Additional Detail from JIRA
Votes 1
Component/s Compiler
Labels Bug, TypeChecker
Assignee None
Priority Medium

md5: b01e85e40f3b2a14293af5843699a96c

is duplicated by:

  • SR-4878 Allow mapping of signatures with defaulted arguments
  • SR-749 References to functions do not include default parameters

Issue Description:

When I create a function like the codes below, when I call this function, the IDE actually gives two candidates, one of which is of type Int -> Int, and the other of type (Int, Int) -> Int.
But when I want to feed this function as a parameter of another function, the "Int -> Int" one is not working and produces the error as below.

  1> func tested(x: Int, y: Int = 0) -> Int { return x + y } 
  2. func testor(f: (Int) -> Int, x: Int) -> Int { return f(x) } 
  3. testor(tested, x: 0)
rep.swift:3:8: error: cannot convert value of type '(Int, y: Int) -> Int' to expected argument type '(Int) -> Int'
testor(tested, x: 0)
       ^~~~~~

This bug causes big problem when the parameter function is pre-defined with default values. When you see multiple overloads of that function e.g. Int tested(x: Int) and Int tested(x: Int, y: Int), you don't know if they were DEFINED by overloading or by default values. But when put it as parameter, the former works while the latter doesn't.
This behaviour is also demonstrated by the snapshots attached.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

1 participant