Got error "cannot convert value of type '[Base.Type]' to expected argument type '[_.Type]'"
when generic function with `where` clause is called on weak variable.
import Foundation
// Lets create base class and two classes that inherits base class.
class Base {}
class A: Base {}
class B: Base {}
// Lets create class with generic function with `where` clauses
class Printer {
func printAll<T>(classes: [T.Type]) where T: Base {
for c in classes {
print(String(describing: c))
}
}
}
// Lets create the instance
let printer = Printer()
// Compiles
printer.printAll(classes: [A.self, B.self])
// Lets create weak variable
weak var weakPrinter: Printer! = printer
// Compiles
weakPrinter.printAll(classes: [A.self])
// Does not compile with error:
// "cannot convert value of type '[Base.Type]' to expected argument type '[_.Type]'"
weakPrinter.printAll(classes: [A.self, B.self])
Environment
Reproduced on: - Xcode 10.2 Swift 5 - Swift-4.2.1Additional Detail from JIRA
| | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug, TypeChecker | |Assignee | None | |Priority | Medium | md5: eec2bcf4fac3d33b4daaa8c1e24287c3Issue Description:
Got error "cannot convert value of type '[Base.Type]' to expected argument type '[_.Type]'"
when generic function with `where` clause is called on weak variable.