[swift-dev] Needs better error msg?

Kevin Choi code.kchoi at gmail.com
Tue Sep 20 15:45:54 CDT 2016


b.sw:
func findIndex<T: Equatable>(array: [T], _ valueToFind: T) -> Int? {
    for (index, value) in array.enumerated() {
        if value == valueToFind {
            return index
        }
    }
    return nil
}

let foundAtIndex = findIndex([1, 2, 3, 4], 3)
print(foundAtIndex == 2) // true

===================
~/git/swift-source$
build/Ninja-RelWithDebInfoAssert/swift-linux-x86_64/bin/swift b.sw
b.sw:10:44: error: unnamed argument #2 must precede unnamed argument #1
let foundAtIndex = findIndex([1, 2, 3, 4], 3)
                             ~~~~~~~~~~~~  ^
                             3             [1, 2, 3, 4]

The error seems to arise from the requirement:
> If a parameter has an argument label, the argument *must* be labeled when
you call the function.

Instead the shown error assumes the order is swapped because first argument
was unnamed. Should the former (from requirement) be shown as the error
here?

-Kevin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20160920/41776843/attachment.html>


More information about the swift-dev mailing list