[swift-dev] prefix map ambiguous

Martin R martinr448 at gmail.com
Fri Jan 12 11:02:08 CST 2018


This seems to be https://bugs.swift.org/browse/SR-1856, which is resolved in Swift 4.1.

Martin

> Am 12.01.2018 um 07:49 schrieb Kelvin Ma via swift-dev <swift-dev at swift.org>:
> 
> 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 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
> 
> 
> _______________________________________________
> swift-dev mailing list
> swift-dev at swift.org
> https://lists.swift.org/mailman/listinfo/swift-dev



More information about the swift-dev mailing list