dc42b20ae3
The new inference uses inferred intersection types normally, unlike the old inference.
However, intersection types in public declarations are approximated to supertype, which
potentially may give a less presice type, then it would be with the OI.
For non-related T1, T2 the NI approximates {T1 & T2} to Any in public declarations,
and if the OI was inferring T1 instead of the intersection type, it may lead to
less precise declaration type and related errors.
The solution is to remember an alternative for an intersection type when present.
Before approximation the alternative replaces the intersection type.
^KT-36249 Fixed
26 lines
786 B
Kotlin
Vendored
26 lines
786 B
Kotlin
Vendored
// !LANGUAGE: +NewInference
|
|
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
|
|
|
interface Bound1
|
|
interface Bound2
|
|
object First : Bound1, Bound2
|
|
object Second : Bound1, Bound2
|
|
|
|
interface WithParam1<out T>
|
|
interface WithParam2<out T>
|
|
class ClsWithParam1<out T> : WithParam1<T>, WithParam2<T>
|
|
class ClsWithParam2<out T> : WithParam1<T>, WithParam2<T>
|
|
|
|
fun <S : Bound1> intersect(vararg elements: S): S = TODO()
|
|
fun <T: Bound1, P : WithParam1<T>> combineParams(first: T, vararg args: P): P = TODO()
|
|
|
|
fun topLevel() = <!DEBUG_INFO_EXPRESSION_TYPE("{WithParam1<{Bound1 & Bound2}> & WithParam2<{Bound1 & Bound2}>}")!>combineParams(
|
|
intersect(First, Second),
|
|
ClsWithParam1<First>(),
|
|
ClsWithParam2<Second>()
|
|
)<!>
|
|
|
|
fun test() {
|
|
<!DEBUG_INFO_EXPRESSION_TYPE("WithParam1<Bound1>")!>topLevel()<!>
|
|
}
|