Generics: Type argument is not within its bounds

Hi,

So I’d like to sort a list of elements according to the natural order, where each element type (Int, Long, etc) should implement a Comparable interface:

fun <T : Comparable<T>> naturalSort(list: List<T>): List<T> {
    val natComparator = naturalOrder<T>() // results in the compiler error: "Type argument is not within its bounds: should be subtype of 'Comparable<T>'"
    return list.sortedWith(natComparator)
}

But the second line result in the compiler error (see above). Why? As I see it, T has been defined as <T : Comparable<T>>, that is T is a subtype of Comparable<T>.

Any ideas? Thanks

Well, your code snipped works for me (tested with kotlin 1.3.41-1 in repl).
What is your Kotlin version?