Parameter name expectations are erratic in Curried functions

Originator:juan.montemayor
Number:rdar://17157220 Date Originated:04-Jun-2014
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode 6A215l, swift-600.0.34.4.5
Classification: Reproducible:Always
 
Juan C Montemayor Elosua04-Jun-2014 03:25 PM

Summary:
Curried functions are covered in the Swift iBook, and so I started playing around with them. 

One example from the book, namely `addTwoNumbers(4)(5)` does not compile, since apparently the second argument in the curried function requires a label.

Local parameter names work, but curried functions do not work (read: ignore) external parameter names.

Furthermore, doing something like:

var add4 = addTwoNumbers(4)
add4(10)

doesn't work, since apparently the add4 call requires a label for the parameter, even though in theory it is the first parameter.

Steps to Reproduce:
Install Xcode 6.0 (6A215l)

Open the attached file. There should be one call that works, and three calls that do not work (corresponding to the three points I have laid out)

Here's the code for good measure:

// Playground - noun: a place where people can play

func addTwoNumbers(a: Int)(to b: Int) -> Int {
    return a + b
}

// Works:
addTwoNumbers(4)(b: 4) // Returns 8

// BUG:
// Expected: No errors. First param name should not require param name (from iBook)
// Actual: "Missing argument label 'b' in call"
var add4 = addTwoNumbers(4)
add4(10)

// BUG:
// Expected: No errors, lets us use the external param name
// Actual: "Incorrect argument label in call (have 'to:', expected 'b:')"
addTwoNumbers(4)(to: 6) // Result: 10

// This won't compile, since names are required for any param that's not the first
// This is code from the Swift iBook

// BUG:
// Expected: No errors
// Actual: "Missing argument label 'b' in call"
addTwoNumbers(4)(5) // Returns 9


Expected Results:
There should be no errors when opening the file.

Actual Results:
There are three distinct errors:

- Not able to use external parameter names in curried functions
- Forced to use parameter name even when it is the first parameter in a newly created curried function
- The iBook example `addTwoNumbers(4)(5)` doesn't compile. That may be an issue with the book itself though... (please file radar? :)

Version:
Xcode Version 6.0 (6A215l)
OS X 10.9.3 13D65

Notes:
Thanks for all your work! Xcode and Swift are lookin' fine ;)

Configuration:


Attachments:
'curry_bug.playground.zip' was successfully uploaded.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!