Kotlin / kotlin-spec

Kotlin Language Specification:
https://kotlinlang.org/spec
Apache License 2.0
387 stars 80 forks source link

Kotlin language specification type constraint reduction error #117

Closed HjalteSkovrup closed 1 year ago

HjalteSkovrup commented 1 year ago

In the kotlin language specification, chapter 13 under the reduction phase, it is explained that when we encounter a type constraint S < T we can hit the following case

image

Imagine that S takes the form

G

and T takes the form

G

then the constraint would be is G < G

As described in the example, this would mean A1 takes the form out Any, and B1 takes the form out Integer. However, now the documentation describes that this results in a type argument constraint of the from

A1 ⪯ B1

Which when both type arguments are covariant results in the constraint

A1 < B1 which in the example I propose would be Any < Integer

This would result in a constraint error. I think the relation should simply be reversed, such that the type argument constraint generated is

B1 ⪯ A1

The oracle java specification backs this proposition, as I double checked in their specification.

image

This confused me a lot as I was reading the definition :)