SwiftQuiz
#19

Overload Resolution in a Generic Context

  • generics
  • overload-resolution
  • protocols
Swift 6.3.2 Report an issue

Verified quizzes have their expected answer checked by compiling and running the code with the listed Swift toolchain during the site build.

protocol A {}

protocol B {}

struct Test: A, B {}

func outer<T: A>(_ val: T.Type) {
    inner(val)
}

func inner<T: A>(_: T.Type) {
    print("A only")
}

func inner<T: A & B>(_: T.Type) {
    print("A & B")
}

outer(Test.self)
Hint

Test conforms to both A and B. What would inner see when it's called?

Your answer

What does this program do?