[FIR] Add constraint to flexible type for declared argument for java parameter

This commit is contained in:
Dmitriy Novozhilov
2020-03-25 18:04:19 +03:00
parent 3acb64c536
commit 48fb279721
24 changed files with 79 additions and 58 deletions
@@ -22,8 +22,7 @@ interface PsiMethod {
interface PsiClass
fun test() {
// TODO: don't forget to implement preservation flexibility of java type parameters in FIR (this is the reason of error here)
val processor = <!INAPPLICABLE_CANDIDATE!>AdapterProcessor<!><PsiMethod, PsiClass>(
val processor = AdapterProcessor<PsiMethod, PsiClass>(
Function { method: PsiMethod? -> method?.containingClass }
)
}
@@ -7,7 +7,7 @@ FILE: main.kt
public abstract interface PsiClass : R|kotlin/Any| {
}
public final fun test(): R|kotlin/Unit| {
lval processor: <ERROR TYPE REF: Inapplicable(INAPPLICABLE): [/AdapterProcessor.AdapterProcessor]> = <Inapplicable(INAPPLICABLE): [/AdapterProcessor.AdapterProcessor]>#<R|PsiMethod|, R|PsiClass|>(R|/Function|<R|PsiMethod?|, R|PsiClass?|>(<L> = Function@fun <anonymous>(method: R|PsiMethod?|): R|PsiClass?| {
lval processor: R|AdapterProcessor<ft<PsiMethod, PsiMethod?>!, ft<PsiClass, PsiClass?>!>| = R|/AdapterProcessor.AdapterProcessor|<R|ft<PsiMethod, PsiMethod?>!|, R|ft<PsiClass, PsiClass?>!|>(R|/Function|<R|ft<PsiMethod, PsiMethod?>!|, R|PsiClass?|>(<L> = Function@fun <anonymous>(method: R|PsiMethod?|): R|PsiClass?| {
^ R|<local>/method|?.R|/PsiMethod.containingClass|
}
))
@@ -20,13 +20,13 @@ FILE: main.kt
}
public final fun test_1(): R|kotlin/Unit| {
lval map: R|util/HashMap<kotlin/Int, kotlin/Int>| = R|util/HashMap.HashMap|<R|kotlin/Int|, R|kotlin/Int|>()
lval map: R|util/HashMap<ft<kotlin/Int, kotlin/Int?>!, ft<kotlin/Int, kotlin/Int?>!>| = R|util/HashMap.HashMap|<R|ft<kotlin/Int, kotlin/Int?>!|, R|ft<kotlin/Int, kotlin/Int?>!|>()
}
public final fun test_2(): R|kotlin/Unit| {
lval set: R|util/HashSet<kotlin/Int>| = R|util/HashSet.HashSet|<R|kotlin/Int|>()
}
public final fun test_3(): R|kotlin/Unit| {
lval list: R|foo/ArrayList<kotlin/Int>| = R|foo/ArrayList.ArrayList|<R|kotlin/Int|>()
lval list: R|foo/ArrayList<ft<kotlin/Int, kotlin/Int?>!>| = R|foo/ArrayList.ArrayList|<R|ft<kotlin/Int, kotlin/Int?>!|>()
}
public final fun test_4(): R|kotlin/Unit| {
lval list: R|foo/LinkedList<kotlin/Int>| = R|foo/LinkedList.LinkedList|<R|kotlin/Int|>()
@@ -13,8 +13,8 @@ FILE: test.kt
lval element: R|DE| = R|<local>/d|.R|/Diagnostic.element|
R|/Fix.Fix|(R|<local>/element|)
}
private final val DERIVED_FACTORY: R|DiagnosticFactory0<DerivedElement>| = R|/DiagnosticFactory0.DiagnosticFactory0|<R|DerivedElement|>()
private get(): R|DiagnosticFactory0<DerivedElement>|
private final val DERIVED_FACTORY: R|DiagnosticFactory0<ft<DerivedElement, DerivedElement?>!>| = R|/DiagnosticFactory0.DiagnosticFactory0|<R|ft<DerivedElement, DerivedElement?>!|>()
private get(): R|DiagnosticFactory0<ft<DerivedElement, DerivedElement?>!>|
public final fun createViaFactory(d: R|EmptyDiagnostic|): R|kotlin/Unit| {
lval casted: R|Diagnostic<ft<DerivedElement, DerivedElement?>!>| = R|/DERIVED_FACTORY|.R|FakeOverride</DiagnosticFactory0.cast: R|Diagnostic<ft<DerivedElement, DerivedElement?>!>|>|(R|<local>/d|)
lval element: R|DerivedElement| = R|<local>/casted|.R|/Diagnostic.element|
@@ -7,10 +7,5 @@ public class JavaClass<T> {
// FILE: main.kt
fun main() {
// See https://github.com/JetBrains/kotlin/commit/437a26684d3529ee2cfdbe54e59d50f4a6f0a611#diff-ba68311bbe28b71196c36a6246000382L176
// In simplifyLowerConstraint, we add constraint Nothing? <: T!, approximating it with Nothing? <: T
// But before it we already had T <: String from the explicit types
// That lead us to constraint contradiction: Nothing? !<: String
// We need to discuss the commit above at some point
<!INAPPLICABLE_CANDIDATE!>JavaClass<!><String>(null).<!UNRESOLVED_REFERENCE!>foo<!>().<!UNRESOLVED_REFERENCE!>length<!>
JavaClass<String>(null).foo().length
}
@@ -1,4 +1,4 @@
FILE: main.kt
public final fun main(): R|kotlin/Unit| {
<Inapplicable(INAPPLICABLE): [/JavaClass.JavaClass]>#<R|kotlin/String|>(Null(null)).<Unresolved name: foo>#().<Unresolved name: length>#
R|/JavaClass.JavaClass|<R|ft<kotlin/String, kotlin/String?>!|>(Null(null)).R|FakeOverride</JavaClass.foo: R|ft<kotlin/String, kotlin/String?>!|>|().R|kotlin/String.length|
}
@@ -1,6 +1,6 @@
FILE: main.kt
public final fun main(): R|kotlin/Unit| {
R|/MyFunction|<R|kotlin/Int|, R|kotlin/String|>(<L> = MyFunction@fun <anonymous>(x: R|ft<kotlin/Int, kotlin/Int?>!|): R|kotlin/String| {
R|/MyFunction|<R|ft<kotlin/Int, kotlin/Int?>!|, R|ft<kotlin/String, kotlin/String?>!|>(<L> = MyFunction@fun <anonymous>(x: R|ft<kotlin/Int, kotlin/Int?>!|): R|kotlin/String| {
^ R|<local>/x|.R|kotlin/Int.toInt|().R|kotlin/Any.toString|()
}
)