Strange compilation error when calling required initializer on generic type parameter

(Christos Chryssochoidis) #1

Hi everyone,

I'm using the new Xcode 8/Swift 3 and I'm trying to figure out why the
first function in the snippet below compiles correctly, while the other one
does not.

import Foundation

import CoreData

protocol P {

    init?(i: Int)


class C {

    func f<T: NSObject>(i: Int) -> T? where T: P {

        return T(i: i) // compiles OK


    func g<T: NSManagedObject>(i: Int) -> T? where T: P {

        return T(i: i) // doesn't compile: "Incorrect argument label in

                 ^ // (have: 'i:', expected 'context:')



Is this some bug of the Swift compiler or am I missing something about
NSManagedObject being different in some way from other classes?

Thanks very much for any help on this.

– Christos