Protected function that returns this

It seems that it isn’t possible to use the return value of protected functions that return this in subclasses. When trying to chain method calls, you’ll get an error on the second call stating that the method is protected and can’t be called here. Can anyone explain me why it behaves in this way?

Simple example explaining the situation: play.kotlinlang.org

In Kotlin protected is more restrictive than in Java. Protected is really only available within the same instance.

protected — same as private + visible in subclasses too;

https://kotlinlang.org/docs/reference/visibility-modifiers.html#classes-and-interfaces

A isn’t a subclass of B.