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

Will Stanton willstanton1 at yahoo.com
Tue Oct 3 13:32:27 CDT 2017


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 })
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 !


.


More information about the swift-users mailing list