[swift-users] Type inference issue with map and filter chained

Vladimir.S svabox at gmail.com
Tue Oct 3 13:50:37 CDT 2017


On 03.10.2017 21:32, Will Stanton via swift-users wrote:
> Is this a REPL-only issue perhaps? The code below compiles `swift build` without error for me (pasted into Sources/main.swift, Ubuntu 17.04, Swift 4 release; haven’t tried in Xcode).
> 
> 
> A similar issue, but apparently not REPL-only:
> https://bugs.swift.org/browse/SR-1856
> 
> Regards,
> Will Stanton
> 
> 
> Code compiles fine:
> class test {
>      let id = 11
> }
> 
> var dict: [Int: test] = [10: test()]
> 
> let filtered = dict.filter({ $0.value.id > 10 })
> let sorted = filtered.sorted(by: {$0.value.id > $1.value.id })
> 
> print(sorted)
> 
> let filteredAndSorted = dict.filter({ $0.value.id > 10 }).sorted(by: {$0.value.id > $1.value.id })

Just checked:

XCode 9: "Ambiguous use of 'filter'" error for this line

Vladimir.

> print(filteredAndSorted)
> 
> 
>> On Sep 24, 2017, at 4:52 AM, Trevör ANNE DENISE via swift-users <swift-users at swift.org> wrote:
>>
>> Hello everyone, I found this on StackOverflow : https://stackoverflow.com/questions/46381752/swift-4-methods-chaining/
>>
>> Is this a bug of Swift 4 or is this normal ? I don't understand why the problem only happens when methods are chained !
> 
> 
> .
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
> 


More information about the swift-users mailing list