Post

Replies

Boosts

Views

Activity

Reply to Int?(nil) is compiled, Int?.init(nil) is not compiled
thank you. i am continuing to analyze this problem, such a interesting one. I made a custom type that conforms ExpressibleByNilLiteral and tested some expressions. struct A: ExpressibleByNilLiteral { init(nilLiteral: ()) {} } let a0: A? = nil // nil let a1 = A?(nil) // nil let a2 = A?(nilLiteral: ()) // nil let a3 = A?.init(nil) // compile error let a4 = A?.init(nilLiteral: ()) // nil let a5 = A??(nil) // nil let a6 = A??.init(nil) // Optional(nil) let a7 = A???(nil) // nil let a8 = A???.init(nil) // Optional(nil) so i just thought that passing a nil literal without specifying init is equivalent to calling init(nilLiteral:), but specifying init and passing a nil literal is equivalent to calling init(_:). in nested optional case, result of A??(nil) is nil, because it is guessed that it called init(nilLiteral:). and result of A??.init(nil) is Optional(nil), because it is guessed that it called init(_:). it is just an assumption, i also wonder if this inference makes sense
May ’22