Kotlin / KEEP

Kotlin Evolution and Enhancement Process
Apache License 2.0
3.42k stars 362 forks source link

KEEP for Self types #356

Open maxim092001 opened 1 year ago

maxim092001 commented 1 year ago

PR

mgroth0 commented 1 year ago

I really like this. Are there any corresponding YouTrack issues or other conversations that we can link to?

maxim092001 commented 1 year ago

mgroth0

Hi!

There is KT-6494 and PR

He-Pin commented 1 year ago

Cool to have this, reduce a lots of boilerplates

Laxystem commented 1 year ago

I would replace the annotation with a modifier. Gate-locking a language feature behind an annotation isn't a common Kotlin thing to do - annotations are usually used for metadata (e.g., @PublishedApi).

class A<this Self>

class B<this Self, T>

class C<T, this Self>

class D<out this Self>

That way, you reduce the confusion from the explicit-self-generic syntax (the C<Int, C<Int, *>> instead of C<Int> part), remove the need for an annotation (therefore increasing readability and beginner-approachability), and allows using whatever name (and order) you want for the generic instead of forcing it by language.

The modifier's name could also be self, current or dynamic.