2

I've found a strange swift generic behaviour:

protocol Textable {}

class Test { 
    init<T: NSObject>(values: [T]) where T: Textable {}
}

func test<T: NSObject>(value: T) where T: Textable {
    let values = [value]
    Test(values: [value]) // Cannot convert value of type '[T]' to expected argument type '[_]'
}

This code with error:

Cannot convert value of type '[T]' to expected argument type '[_]'.

But if I change Test(values: [value]) to Test(values: values), it works fine. Maybe am I doing something wrong? Or it's just a swift's bug...

Created issue at Swift JIRA.

Nikita Ermolenko
  • 2,139
  • 2
  • 19
  • 41

0 Answers0