Initialization error when forwarding the initializers required by protocol ExpressibleByArrayLiteral or ExpressibleByDictionaryLiteral

This is the well-known variadic forwarding issue. A minimal example of your situation is:

struct Foo<T> {
  var base: T
}

extension Foo: ExpressibleByArrayLiteral where T: ExpressibleByArrayLiteral {
  init(arrayLiteral elements: T.ArrayLiteralElement...) {
    // Cannot invoke 'init' with an argument list of type '(arrayLiteral: [T.ArrayLiteralElement])'
    base = T.init(arrayLiteral: elements)
  }
}

Here are some previous threads about the topic:

[Idea] Passing an Array to Variadic Functions (55 comments, April 2016)
[Discussion] Variadics as an Attribute (7 comments, February 2017)
Explicit array splat for variadic functions (29 comments, March 2018)
Variadic Parameters that Accept Array Inputs (52 comments, May 2018)
Another attempt at passing arrays as varargs (with implementation) (126 comments, July 2019)
Yet another varargs “splat” proposal (9 comments, September 2019)

2 Likes