Compiler incorrectly gives 'missing argument label error'

Originator:michael
Number:rdar://18919562 Date Originated:11/8/2014
Status:Open Resolved:
Product:XCode Swift Compiler Product Version:XCode 6.1
Classification: Reproducible:Yes
 
Summary:
I believe the compiler is incorrectly giving a "missing argument label error" in the following situation:

public func flip<A, B, C>(f: A -> B -> C)(b: B)(a: A) -> C {
    return f(a)(b)
}

public func useFlip() {
    let subtract = { (x:Int) in { y in x-y }}
    let result = flip(subtract)(5)(3);

    subtract(4)(3);
}

The compiler complains about no b label in front of the 5 and no a label in front of the 3. If I put an underscore in front of the a and b parameters in flip then in addition to the compiler errors I get compiler warnings.

Errors:
/Users/mgwelch/Documents/Projects/thirdparty/swiftz/swiftz_core/swiftz_coreTests/FunctionSpecs.swift:7:33: Missing argument label 'b:' in call
/Users/mgwelch/Documents/Projects/thirdparty/swiftz/swiftz_core/swiftz_coreTests/FunctionSpecs.swift:7:36: Missing argument label 'a:' in call

Steps to Reproduce:
I've attached a complete file.

1. Create a playground
2. Paste the code

Or

1. Create a Swift project
2. Add the attached file
3. Compile



Expected Results:
I expect that I could call the following without labels

flip(subtract)(5)(3)

Actual Results:
I get errors and need to add labels. Normally whenever you have a parameter that requires labels you can "fix" the problem by adding underscores in front of the parameter name in the function definition. But that doesn't fix the problem in this case and instead you end up with 2 compiler warnings in addition to the compiler errors.

Version:
XCode 6.1
OS X 10.10

Notes:


Configuration:


Attachments:
'FunctionSpecs.swift' was successfully uploaded.
public func flip<A, B, C>(f: A -> B -> C)(b: B)(a: A) -> C {
    return f(a)(b)
}

public func useFlip() {
    let subtract = { (x:Int) in { y in x-y }}
    let result = flip(subtract)(5)(3);

    subtract(4)(3);
}

Comments

Apple Response

Marked as a duplicate

Giving a link to the specific commit might be easier to see the change I made:

https://github.com/michaelgwelch/swiftz/commit/ea2566ccd6a45a8a1a41c91ee51377f66bfd5737

Changing the definition of the function to be public func flip(f: A->B->C) -> B -> A -> C { return { b in { a in f(a)(b) } } }

fixes the problem see: https://github.com/typelift/swiftz/issues/123 https://github.com/typelift/swiftz/pull/124


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!