Try required for call to filter

I don’t quite understand the error message here. What is it trying to tell me?

extension Swift.Array {
    #if ELEMENTS
    typealias Element = T
    #endif

    func `where`(_ condition: ((Element) -> Bool)) -> [Int] {
        return self.enumerated().filter({ condition($0.1) }).map({ $0.0 })
        // E: "try" required for call to "static func IEnumerable<Tuple<Int,T>>!.filter(_ includeElement: func (_ arg0: Tuple<Int,T>) -> Bool) -> IEnumerable<Tuple<Int,T>>"
    }
}

map works as expected, it’s just filter that has problems. Is this an SBL issue?

iirc try is required if the method is marked as throws, no?

If the argument of the function that rethrows is not marked as throws, then try is not needed. Here, condition is not marked as throws. The following works in both Silver and Xcode, but Xcode gives warning No calls to throwing functions occur within 'try' expression:

extension Swift.Array {
    #if ELEMENTS
    typealias Element = T
    #endif

    func `where`(_ condition: ((Element) -> Bool)) -> [Int] {
        let filtered = try! self.enumerated().filter({ condition($0.1) })  // Xcode warns for unnecessary try
        return filtered.map({ $0.0 })
    }
}

Any chance you can re-create/illustrate this issue with a simple test-case that does not depend on SBL or LINQ? I.e. just a function you declare yourself and a call to it, that shows the problem?

thanx,
marc

Sure, I thought, but it turned out to be more difficult than I anticipated:

func without_throw() -> Int {
    return 0
}

func with_throw() throws -> Int {
    return 0
}

public func test(_ arg: (() throws -> Int)) rethrows -> () {
    let _ = try! arg()
    return
}

// These all work with Apple's compiler:
test(without_throw)  // E: No matching overload
test { return 0 }  // E: No overload that accepts a trailing closure
try! test(with_throw)

print("pass")

Thanx. I’ll have a look tomorrow!

The above was with Toffee V1. With Toffee V2, I get another set of errors (this time including the one for which I was trying to add the test):

func without_throw() -> Int {
    return 0
}

func with_throw() throws -> Int {
    return 0
}

public func test(_ arg: (() throws -> Int)) rethrows -> () {
    let _ = try! arg()
    return
}

// These all work with Apple's compiler:
test(without_throw)  // E: Parenthesis required for call
try! test(with_throw)  // E: Parenthesis required for call
test { return 0 }  // E: "try" required for call to "func ConsoleApplication.test(_ arg: () -> Int throws)

// This gives warning with Apple's compiler:
try! test { return 0 }  // Works in Silver

print("pass")