i had always assumed we cannot overload a property because this is a compiler error:
public
struct S
{
public
var readConcern:Int { 1 }
public
var readConcern:Int? { 1 }
}
// error: invalid redeclaration of 'readConcern'
and yet i am able to provide overloads in a generic context, and access those overloads in a concretely-typed context:
public
protocol SessionCommand
{
var readConcern:Int? { get }
}
public
protocol ReadCommand:SessionCommand
{
var readConcern:Int { get }
}
extension ReadCommand
{
public
var readConcern:Int?
{
.some(self.readConcern)
}
}
public
struct S:ReadCommand
{
public
var readConcern:Int { 1 }
}
func test(s:S) -> Int?
{
if let r:Int = s.readConcern
{
return r
}
else
{
return s.readConcern
}
}
Assuming overload by return value is a good thing (which is questionable) this behaviour is already strange: I can do it with a function and with a subscript, but not with a variable?
it makes it easier to add and remove the access modifiers (public, private, etc.) using editor line operations, which i do quite often. also i personally find it easier to scan for the property names if they all begin at n + 4 columns from the base indent of the type.