`some/any Protocol` variable type vs `Protocol` variable types

If I understand correctly, having a simple protocol (aka no associated types):

protocol Person {
   var name: String { get }
}

allows the usage of the Person type (does such a type have a name?) without any effort. Is this because the size of the type can be calculated by the compiler?

However, introducing associatedtpye to the equation suddenly causes problems:

protocol Person {
   associatedtype JustaTypeName 
   var name: String { get }
}

(does a type Person have a different name now? )
Now, suddenly variables need to be declared as any or some or generics must be used.
Is this because now the type's size cannot be know at compile-time?

First, one clarification: any Person and Person are exactly the same in this context. The reason any exists is because people kept assuming Person was something much simpler than it actually is.

As to why using Person/any Person has limitations:
Typically you actually use an associated type for something. So a more realistic example is

protocol Person {
   associatedtype JustaTypeName 
   var associatedThing: JustaTypeName { get }
}

Now suppose you have code like this:

func p(_ person: Person) {
  let x = person.associatedThing
}

What is the type of x? The impossibility of answering that is why it can't be simple.

8 Likes