I think required metatype .self
feels weirder now that identity key paths finally started working last year.
Enum.self[keyPath: \.self] // Compiles, as it should.
Enum[keyPath: \.self] // Expected member name or initializer call after type name
I see the argument about array literal syntax. If that's not involved, I don't think extra .self
helps people.
func takeArguments<each T>(_: repeat each T) { }
enum Enum { case `case` }
takeArguments( // All of these compile.
Enum.self.case.self,
Enum.self.case,
Enum.case.self,
Enum.case,
Enum.self
)
f(Enum) // Expected member name or initializer call after type name
Am I wrong to feel like the main usage of .self
is metatype arguments? I'm open to it being considered disambiguating elsewhere, but I really don't think it does anything to help mentally parse arguments. The compiler won't let you try to use a nested instance of a metatype when defining an instance of an outer metatype.
// This all compiles, as it should.
func f(_: (some Any).Type) { }
f([Int].self)
f([Int.Type].self)
_ = [Int.self].self as [Int.Type]
f([Int.self].self) // Cannot convert value of type '[Int.Type]' to expected argument type 'some Any.Type'