[swift-dev] prefix map ambiguous

Kelvin Ma kelvin13ma at gmail.com
Fri Jan 12 00:49:51 CST 2018


it happens when the n is a literal

let a:[Int] = [1, 2, 3]
let f:(Int) -> Int = { $0 + 5 }

print(a.prefix(5).map(f))


ab.swift:4:7: error: ambiguous use of 'prefix'
print(a.prefix(5).map(f))
      ^
Swift.Collection:85:17: note: found this candidate
    public func prefix(_ maxLength: Int) -> Self.SubSequence
                ^
Swift.Sequence:81:17: note: found this candidate
    public func prefix(_ maxLength: Int) -> AnySequence<Self.Element>


On Thu, Jan 11, 2018 at 11:30 PM, Ben Cohen <ben_cohen at apple.com> wrote:

> Hi Kelvin,
>
> Can you give a bit more detail on the type of the sequence, and which
> compiler version you’re seeing this on?
>
> I can’t reproduce this with a recent Xcode or a recent master toolchain
> with this code:
>
> let sequence = 0..<10
> let n = 5
> let f = { $0*2 }
>
> sequence.prefix(n).map(f)
>
> Thanks
> Ben
>
> On Jan 11, 2018, at 19:11, Kelvin Ma via swift-dev <swift-dev at swift.org>
> wrote:
>
> when I write sequence.prefix(n).map(f) the compiler complains that .prefix
> is ambiguous. If I replace it with [..<n] it works fine. Why is this
> happening? I found SR-1856 <https://bugs.swift.org/browse/SR-1856> which
> looks like a similar issue but it’s marked fixed.
> _______________________________________________
> swift-dev mailing list
> swift-dev at swift.org
> https://lists.swift.org/mailman/listinfo/swift-dev
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20180112/f590166a/attachment.html>


More information about the swift-dev mailing list