Reflect Kotlin's declaration-site variance in Java signatures

This commit is contained in:
Andrey Breslav
2012-11-21 22:30:59 +04:00
parent da2f886bee
commit 889ea107f6
24 changed files with 243 additions and 22 deletions
@@ -0,0 +1,10 @@
class M<in K, out V>
class X
fun f(m: M<X, X>): M<X, X> = throw Exception()
// method: namespace::f
// jvm signature: (LM;)LM;
// generic signature: (LM<-LX;+LX;>;)LM<LX;LX;>;
// kotlin signature: (LM<LX;LX;>;)LM<LX;LX;>;
@@ -0,0 +1,8 @@
class In<in T>
fun f(p: In<String>) {}
// method: namespace::f
// jvm signature: (LIn;)V
// generic signature: (LIn<-Ljava/lang/String;>;)V
// kotlin signature: (LIn<Ljava/lang/String;>;)V
@@ -0,0 +1,8 @@
class In<in T>
fun f(): In<String> = throw Exception()
// method: namespace::f
// jvm signature: ()LIn;
// generic signature: ()LIn<Ljava/lang/String;>;
// kotlin signature: ()LIn<Ljava/lang/String;>;
@@ -0,0 +1,9 @@
class In<in T>
class X
fun f(p: In<In<X>>) {}
// method: namespace::f
// jvm signature: (LIn;)V
// generic signature: (LIn<-LIn<-LX;>;>;)V
// kotlin signature: (LIn<LIn<LX;>;>;)V
@@ -0,0 +1,9 @@
class In<in T>
class X
fun f(): In<In<X>> = throw Exception()
// method: namespace::f
// jvm signature: ()LIn;
// generic signature: ()LIn<LIn<-LX;>;>;
// kotlin signature: ()LIn<LIn<LX;>;>;
@@ -0,0 +1,10 @@
class In<in T>
class Out<out T>
class X
fun f(p: In<Out<X>>) {}
// method: namespace::f
// jvm signature: (LIn;)V
// generic signature: (LIn<-LOut<+LX;>;>;)V
// kotlin signature: (LIn<LOut<LX;>;>;)V
@@ -0,0 +1,10 @@
class In<in T>
class Out<out T>
class X
fun f(): In<Out<X>> = throw Exception()
// method: namespace::f
// jvm signature: ()LIn;
// generic signature: ()LIn<LOut<+LX;>;>;
// kotlin signature: ()LIn<LOut<LX;>;>;
@@ -0,0 +1,6 @@
fun f(p: List<String>) {}
// method: namespace::f
// jvm signature: (Ljava/util/List;)V
// generic signature: (Ljava/util/List<+Ljava/lang/String;>;)V
// kotlin signature: (Ljet/List<Ljava/lang/String;>;)V
@@ -0,0 +1,6 @@
fun f(): List<String> = throw Exception()
// method: namespace::f
// jvm signature: ()Ljava/util/List;
// generic signature: ()Ljava/util/List<Ljava/lang/String;>;
// kotlin signature: ()Ljet/List<Ljava/lang/String;>;
@@ -0,0 +1,10 @@
class In<in T>
class Out<out T>
class X
fun f(p: Out<In<X>>) {}
// method: namespace::f
// jvm signature: (LOut;)V
// generic signature: (LOut<+LIn<-LX;>;>;)V
// kotlin signature: (LOut<LIn<LX;>;>;)V
@@ -0,0 +1,10 @@
class In<in T>
class Out<out T>
class X
fun f(): Out<In<X>> = throw Exception()
// method: namespace::f
// jvm signature: ()LOut;
// generic signature: ()LOut<LIn<-LX;>;>;
// kotlin signature: ()LOut<LIn<LX;>;>;
@@ -0,0 +1,9 @@
class Out<out T>
class X
fun f(p: Out<Out<X>>) {}
// method: namespace::f
// jvm signature: (LOut;)V
// generic signature: (LOut<+LOut<+LX;>;>;)V
// kotlin signature: (LOut<LOut<LX;>;>;)V
@@ -0,0 +1,19 @@
class Out<out T>
class X
// Why we want this to be translated to 'Out<Out<? extends X>> f()' instead of 'Out<Out<X>> f()'
// There are two instantiations of 'In' in this test: outer Out<...> and inner Out<X>
// So why do we want to put a wildcard on the inner one and not the outer?
// People don't want wildcards in return types, because they are _long_. So we try our best to remove wildcards where possible
// Not putting a wildcard on the outer occurrence is not imposing a restriction, actually it is removing one:
// anything that can be done with Out<? extends X> in Java can be done with Out<X>
// But omitting the wildcard on the inner occurrence is restrictive:
// one can add a List<String> to a List<List<? extends CharSequence>>,
// but not to a List<List<CharSequence>>,
// thus removing the wildcard would be restricting the use of the return value of the method, and we don't want do this.
fun f(): Out<Out<X>> = throw Exception()
// method: namespace::f
// jvm signature: ()LOut;
// generic signature: ()LOut<LOut<+LX;>;>;
// kotlin signature: ()LOut<LOut<LX;>;>;
@@ -0,0 +1,9 @@
class M<in V>
class X
val p: M<X> = throw Exception()
// method: namespace::getP
// jvm signature: ()LM;
// generic signature: ()LM<LX;>;
// kotlin signature: null
@@ -0,0 +1,9 @@
class M<out V>
class X
val p: M<X> = throw Exception()
// method: namespace::getP
// jvm signature: ()LM;
// generic signature: ()LM<LX;>;
// kotlin signature: null
@@ -0,0 +1,9 @@
class M<in K, out V>
class X
val p: M<X, X> = throw Exception()
// method: namespace::getP
// jvm signature: ()LM;
// generic signature: ()LM<LX;LX;>;
// kotlin signature: null
@@ -0,0 +1,9 @@
class M<in V>
class X
var p: M<X> = throw Exception()
// method: namespace::setP
// jvm signature: (LM;)V
// generic signature: (LM<-LX;>;)V
// kotlin signature: null
@@ -0,0 +1,9 @@
class M<out V>
class X
var p: M<X> = throw Exception()
// method: namespace::setP
// jvm signature: (LM;)V
// generic signature: (LM<+LX;>;)V
// kotlin signature: null