Unexpected compilation error filtering swift array by enum

This is an example of what I am trying to do:

public enum Foo
{
    case VALID
    case INVALID
}

public class FooContainer
{
    let foo: Foo
    let name: String
    
    public init(foo: Foo, name: String)
    {
        self.foo = foo
        self.name = name
    }
}

let theFoos = [
    FooContainer(foo: Foo.VALID, name: "The valid one"),
    FooContainer(foo: Foo.INVALID, name: "The invalid one")
]

if let validFoo = theFoos.filter({$0.foo == .VALID}).first
{
    print("Valid foo: " + validFoo.name)
}

This gives these compilation errors on the if let validFoo... line on Fire build 1925. (Project: FilterFail.zip (306.0 KB))

Program.swift(24,19): error E62: Type mismatch, cannot assign "<error>" to "Boolean"
Program.swift(24,19): error E513: Parenthesis are required to call method first()

It is okay in Xcode so I guess there is a missing feature in Fire’s compiler?

Thanks, logged as bugs://74879

Sounds like a bug yes. I’ve logged it.

The second error sounds legit? first is a method, not a property…

the latest release (8.3) gives:

Parenthesis are required to call method first()

If I add them as marc suggests, it works.

bugs://74879 got closed with status nochangereq.

Great to hear the E62 is already fixed! Sorry to waste your time about that one.

However I am confused about first. It is a property on CollectionType: https://developer.apple.com/library/ios/documentation/Swift/Reference/Swift_CollectionType_Protocol/index.html#//apple_ref/swift/intfp/CollectionType/s:vPs14CollectionType5firstGSqWx9Generator7Element__

If I try to use first() in Xcode I get:

error: invalid use of '()' to call a value of non-function type 'FooContainer?'

This would make it difficult to write code that interoperates with Fire. Is that intended behaviour?

Hm, damn. is it me or does Apple change around what’s a property and what;'s a function, every second release? I’ll adjust, and make first a property…

1 Like

Fixed in github.

Thanks very much!

Logged as bugs://i62914.

bugs://i62914 was closed as fixed.