Files
Dmitry Timofeev e27e45f867 [kotlin] Quick fix to add a non-nullable upper bound to type parameter
Starting from 1.6.20, passing nullable arguments of generic types (`T`)
to the Java methods where the corresponding arguments are annotated with
`@NotNull` causes warnings (they are to be replaced with errors in
future releases, see KT-36770 for details):
  * NULLABLE_TYPE_PARAMETER_AGAINST_NOT_NULL_TYPE_PARAMETER
  * WRONG_NULLABILITY_FOR_JAVA_OVERRIDE.

This quick fix allows users to fix most cases of these warnings by
adding a non-nullable upper bound to the type parameter in question.

If the parameter has no upper bound, the `Any` upper bound is added:
`fun <T> foo() { … }` →  `fun <T : Any> foo() { … }`

If the type parameter already has an explicitly nullable upper bound,
this bound is replaced with its non-nullable subtype:
`fun <T : Foo?> foo() { … }` →  `fun <T : Foo> foo() { … }`

The quick fix provides actions for TYPE_MISMATCH and NOTHING_TO_OVERRIDE
errors that the compiler generates instead of nullability warnings If
loading of `@NotNull` Java values as definitely non-nullable types is
enabled.

^KTIJ-20557 Fixed

(cherry picked from commit 12fe8257c052574488e44147aaa09d646c4f7204)

GitOrigin-RevId: 79e445a8e47feb6fc8e7a5f9eda637a38237477f
2022-02-08 08:52:53 +00:00

7 lines
163 B
Kotlin

// "Add 'Any' as upper bound for T to make it non-nullable" "true"
// LANGUAGE_VERSION: 1.6
class FooChild<T> : Foo<T>() {
override<caret> fun foo(x: T) {}
}