Swift

Swift

Made by DeepSource

The initializers declared in compiler protocols such as ExpressibleByArrayLiteral shouldn’t be called directly SW-W1027

Bug risk
Major

Compiler protocols like ExpressibleByArrayLiteral define a contract that types adopting the protocol must adhere to. By calling the initializer directly, you bypass this contract and can potentially create instances that do not conform to the expected behavior defined by the protocol. This can lead to runtime errors and unpredictable results.

Compiler protocols often provide a convenient way to initialize instances of a type using literals. By calling the initializer directly, you lose the type safety that the protocol provides. This can lead to code that is harder to understand, maintain, and debug.

Bad Practice

let set = Set(arrayLiteral: 1, 2)

Recommended

let set: Set<Int> = [1, 2]