[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|()
}
)
@@ -5,8 +5,8 @@ FILE: concurrentMapOfAliases.kt
super<R|kotlin/Any|>()
}
private final val foo: R|java/util/concurrent/ConcurrentHashMap<kotlin/String, kotlin/CharSequence>| = Q|java/util/concurrent|.R|java/util/concurrent/ConcurrentHashMap.ConcurrentHashMap|<R|kotlin/String|, R|kotlin/CharSequence|>()
private get(): R|java/util/concurrent/ConcurrentHashMap<kotlin/String, kotlin/CharSequence>|
private final val foo: R|java/util/concurrent/ConcurrentHashMap<ft<kotlin/String, kotlin/String?>!, ft<kotlin/CharSequence, kotlin/CharSequence?>!>| = Q|java/util/concurrent|.R|java/util/concurrent/ConcurrentHashMap.ConcurrentHashMap|<R|ft<kotlin/String, kotlin/String?>!|, R|ft<kotlin/CharSequence, kotlin/CharSequence?>!|>()
private get(): R|java/util/concurrent/ConcurrentHashMap<ft<kotlin/String, kotlin/String?>!, ft<kotlin/CharSequence, kotlin/CharSequence?>!>|
private final fun bar(): R|kotlin/Unit| {
(this@R|/A|, this@R|/A|.R|/A.foo|.R|FakeOverride<java/util/concurrent/ConcurrentHashMap.get: R|kotlin/CharSequence?|>|(String(dd)))?.R|/A.baz|()
@@ -4,5 +4,5 @@ FILE: main.kt
public final typealias ImmutableLinkedHashSet<E> = R|imm/LinkedHashSet<E>|
private final typealias ImmutableMultimap<K, V> = R|ImmutableMap<K, ImmutableSet<V>>|
private final fun <K, V> R|ImmutableMultimap<K, V>|.put(key: R|K|, value: R|V|): R|kotlin/Unit| {
this@R|/put|.R|FakeOverride<imm/Map.get: R|ft<imm/Option<ft<ImmutableSet<V>, ImmutableSet<V>?>!>, imm/Option<ft<ImmutableSet<V>, ImmutableSet<V>?>!>?>!|>|(R|<local>/key|).R|FakeOverride<imm/Option.getOrElse: R|ft<ImmutableSet<V>, ImmutableSet<V>?>!|>|(Q|ImmutableLinkedHashSet|.R|imm/LinkedHashSet.empty|<R|V|>())
this@R|/put|.R|FakeOverride<imm/Map.get: R|ft<imm/Option<ft<ImmutableSet<V>, ImmutableSet<V>?>!>, imm/Option<ft<ImmutableSet<V>, ImmutableSet<V>?>!>?>!|>|(R|<local>/key|).R|FakeOverride<imm/Option.getOrElse: R|ft<ImmutableSet<V>, ImmutableSet<V>?>!|>|(Q|ImmutableLinkedHashSet|.R|imm/LinkedHashSet.empty|<R|ft<V, V?>!|>())
}
@@ -1,6 +1,6 @@
FILE: javaLangComparator.kt
public final fun test_2(list: R|kotlin/collections/List<kotlin/Int>|): R|kotlin/Unit| {
lval comp: R|java/util/Comparator<kotlin/Int>| = Q|java/util|.R|java/util/Comparator|<R|kotlin/Int|>(<L> = Comparator@fun <anonymous>(x: R|ft<kotlin/Int, kotlin/Int?>!|, y: R|ft<kotlin/Int, kotlin/Int?>!|): R|kotlin/Int| {
lval comp: R|java/util/Comparator<ft<kotlin/Int, kotlin/Int?>!>| = Q|java/util|.R|java/util/Comparator|<R|ft<kotlin/Int, kotlin/Int?>!|>(<L> = Comparator@fun <anonymous>(x: R|ft<kotlin/Int, kotlin/Int?>!|, y: R|ft<kotlin/Int, kotlin/Int?>!|): R|kotlin/Int| {
^ Int(1)
}
)
@@ -1,6 +1,6 @@
FILE: kotlinComparatorAlias.kt
public final fun test_1(): R|kotlin/Unit| {
lval comp: R|java/util/Comparator<kotlin/Int>| = R|java/util/Comparator|<R|kotlin/Int|>(<L> = Comparator@fun <anonymous>(x: R|ft<kotlin/Int, kotlin/Int?>!|, y: R|ft<kotlin/Int, kotlin/Int?>!|): R|kotlin/Int| {
lval comp: R|java/util/Comparator<ft<kotlin/Int, kotlin/Int?>!>| = R|java/util/Comparator|<R|ft<kotlin/Int, kotlin/Int?>!|>(<L> = Comparator@fun <anonymous>(x: R|ft<kotlin/Int, kotlin/Int?>!|, y: R|ft<kotlin/Int, kotlin/Int?>!|): R|kotlin/Int| {
^ Int(1)
}
)
@@ -1,6 +1,6 @@
FILE: weakHashMap.kt
public final val someMap: R|java/util/WeakHashMap<kotlin/Any?, kotlin/Any?>| = R|java/util/WeakHashMap.WeakHashMap|<R|kotlin/Any?|, R|kotlin/Any?|>()
public get(): R|java/util/WeakHashMap<kotlin/Any?, kotlin/Any?>|
public final val someMap: R|java/util/WeakHashMap<ft<kotlin/Any, kotlin/Any?>!, ft<kotlin/Any, kotlin/Any?>!>| = R|java/util/WeakHashMap.WeakHashMap|<R|ft<kotlin/Any, kotlin/Any?>!|, R|ft<kotlin/Any, kotlin/Any?>!|>()
public get(): R|java/util/WeakHashMap<ft<kotlin/Any, kotlin/Any?>!, ft<kotlin/Any, kotlin/Any?>!>|
public final fun foo(): R|kotlin/Unit| {
R|/someMap|.R|FakeOverride<java/util/WeakHashMap.get: R|kotlin/Any?|>|(String())
}
@@ -9,7 +9,7 @@ FILE: typeAliasWithForEach.kt
}
public final typealias Arguments = R|kotlin/collections/Map<kotlin/String, ArgsInfo>|
public final fun R|Arguments|.deepCopy(): R|Arguments| {
lval result: R|java/util/HashMap<kotlin/String, ArgsInfo>| = R|java/util/HashMap.HashMap|<R|kotlin/String|, R|ArgsInfo|>()
lval result: R|java/util/HashMap<ft<kotlin/String, kotlin/String?>!, ft<ArgsInfo, ArgsInfo?>!>| = R|java/util/HashMap.HashMap|<R|ft<kotlin/String, kotlin/String?>!|, R|ft<ArgsInfo, ArgsInfo?>!|>()
this@R|/deepCopy|.R|FakeOverride<java/util/Map.forEach: R|kotlin/Unit|>|(<L> = forEach@fun <anonymous>(key: R|ft<kotlin/String, kotlin/String?>!|, value: R|ft<ArgsInfo, ArgsInfo?>!|): R|kotlin/Unit| {
R|<local>/result|.R|kotlin/collections/set|<R|ft<kotlin/String, kotlin/String?>!|, R|ft<ArgsInfo, ArgsInfo?>!|>(R|<local>/key|, R|/ArgsInfoImpl.ArgsInfoImpl|(R|<local>/value|))
}