New J2K: separate nullability inference from common one & nullability bug fixes

It will be needed for structure mutability inference

#KT-21467 fixed
#KT-32609 fixed
#KT-32572 fixed
#KT-24677 fixed
This commit is contained in:
Ilya Kirillov
2019-07-25 00:31:50 +03:00
parent d7960caf89
commit 2bd5a1f196
234 changed files with 3940 additions and 1983 deletions
+1 -1
View File
@@ -3,7 +3,7 @@
// ERROR: Type argument is not within its bounds: should be subtype of 'String?'
import java.util.HashMap
internal class G<T : String?>(t: T?)
internal class G<T : String?>(t: T)
class Java {
internal fun test() {
val m: HashMap<*, *> = HashMap<Any?, Any?>()
+3 -6
View File
@@ -1,10 +1,7 @@
// ERROR: Unresolved reference: stream
// ERROR: Unresolved reference: stream
// ERROR: Unresolved reference: Collectors
import java.util.stream.Collectors
internal class JavaCode {
fun toJSON(collection: Collection<Int?>): String {
return "[" + collection.stream().map({ obj: Object -> obj.toString() }).collect(Collectors.joining(", ")).toString() + "]"
fun toJSON(collection: Collection<Int>): String {
return "[" + collection.stream().map { obj: Int -> obj.toString() }.collect(Collectors.joining(", ")).toString() + "]"
}
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
class TestReturnsArray {
fun strings(n: Int): Array<String?> {
val result = arrayOfNulls<String>(n)
val result = arrayOfNulls<String?>(n)
for (i in 0 until n) {
result[i] = Integer.toString(i)
}
+1 -1
View File
@@ -2,7 +2,7 @@ package test
class TestAssignmentInReturn {
private var last: String? = null
fun foo(s: String): String? {
fun foo(s: String): String {
return s.also { last = it }
}
}
+1 -1
View File
@@ -14,7 +14,7 @@ class TestMutltipleCtorsWithJavadoc
* @param x
* @param y
*/
constructor(x: String?, y: String?) : this(x!!) {
constructor(x: String, y: String?) : this(x) {
this.y = y
}
+1 -1
View File
@@ -3,7 +3,7 @@ package test
import java.util.HashMap
class TestPrimitiveFromMap {
fun foo(map: HashMap<String, Int?>): Int {
fun foo(map: HashMap<String, Int>): Int {
return map["zzz"]!!
}
}
+1 -1
View File
@@ -1,7 +1,7 @@
package test
class TestMapGetAsReceiver {
fun foo(map: Map<String, String?>): Int {
fun foo(map: Map<String, String>): Int {
return map["zzz"]!!.length
}
}
+1 -1
View File
@@ -3,7 +3,7 @@ package test
class TestValReassign(private val s1: String) {
private var s2: String? = null
constructor(s1: String?, s2: String?) : this(s1!!) {
constructor(s1: String, s2: String?) : this(s1) {
this.s2 = s2
}
+3 -3
View File
@@ -3,15 +3,15 @@ class TestToStringReturnsNullable {
var string: String? = null
}
open class Ctor(string: String?) : Base() {
open class Ctor(string: String) : Base() {
init {
this.string = string
}
}
class Derived(string: String?) : Ctor(string) {
class Derived(string: String) : Ctor(string) {
override fun toString(): String {
return string!!
}
}
}
}
+5 -5
View File
@@ -1,13 +1,13 @@
// ERROR: Type mismatch: inferred type is Enumeration<(raw) Any!>! but Enumeration<DefaultMutableTreeNode?>? was expected
// ERROR: Type mismatch: inferred type is Enumeration<(raw) Any!>! but Enumeration<DefaultMutableTreeNode> was expected
import java.util.Enumeration
import javax.swing.tree.DefaultMutableTreeNode
class TestJavaExpectedTypeInference {
fun test(node: DefaultMutableTreeNode) {
val e: Enumeration<DefaultMutableTreeNode?>? = node.children()
while (e!!.hasMoreElements()) {
val child = e.nextElement()
val name = child!!.userObject as String
val e: Enumeration<DefaultMutableTreeNode> = node.children()
while (e.hasMoreElements()) {
val child: DefaultMutableTreeNode = e.nextElement()
val name = child.userObject as String
println(name)
}
}
+16
View File
@@ -0,0 +1,16 @@
import java.util.ArrayList;
interface FooInterface {
ArrayList<? extends Foo.SomeClass> foo();
}
public class Foo implements FooInterface {
@Override
public ArrayList<SomeClass> foo() {
return null;
}
public static class SomeClass {
}
}
+13
View File
@@ -0,0 +1,13 @@
import java.util.ArrayList
internal interface FooInterface {
fun foo(): ArrayList<out Foo.SomeClass>?
}
class Foo : FooInterface {
override fun foo(): ArrayList<SomeClass>? {
return null
}
class SomeClass
}
+7
View File
@@ -0,0 +1,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class TestClass {
private Map<String, List<Integer>> hashMap = new HashMap<>();
}
+5
View File
@@ -0,0 +1,5 @@
import java.util.HashMap
class TestClass {
private val hashMap: Map<String, List<Int>> = HashMap()
}
+8
View File
@@ -0,0 +1,8 @@
import org.jetbrains.annotations.NotNull;
public class Book implements Comparable<Book> {
@Override
public int compareTo(@NotNull Book o) {
return 0;
}
}
+5
View File
@@ -0,0 +1,5 @@
class Book : Comparable<Book> {
override fun compareTo(o: Book): Int {
return 0
}
}
+4 -3
View File
@@ -17,13 +17,14 @@ class Identifier<T> {
myHasDollar = hasDollar
myNullable = isNullable
}
}
object User {
@JvmStatic
fun main(args: Array<String>) {
val i1: Identifier<*> = Identifier<String?>("name", false, true)
val i2: Identifier<*> = Identifier<String?>("name", false)
val i3: Identifier<*> = Identifier<String?>("name")
val i1: Identifier<*> = Identifier("name", false, true)
val i2: Identifier<*> = Identifier("name", false)
val i3: Identifier<*> = Identifier("name")
}
}
+1 -2
View File
@@ -1,7 +1,6 @@
package demo
internal class Test(i: Int?) {
internal class Test(i: Int) {
fun test() {
val i = 10
Test(i)
+1 -1
View File
@@ -13,7 +13,7 @@ internal object FileRead {
val fstream = FileInputStream(File("file.txt"))
val `in` = DataInputStream(fstream)
val br = BufferedReader(InputStreamReader(`in`))
var strLine: String?
var strLine: String
while (br.readLine().also { strLine = it } != null) {
println(strLine)
}
+1 -2
View File
@@ -8,8 +8,7 @@ internal object One {
var myContainer = Container()
}
internal class StringContainer(s: String?)
internal class StringContainer(s: String)
internal class Test {
fun putString(s: String) {}
fun test() {
+2 -2
View File
@@ -2,12 +2,12 @@ object ArrayNullable {
@JvmStatic
fun main(args: Array<String>) {
val notNull = 0
val a1 = arrayOfNulls<Int>(2)
val a1 = arrayOfNulls<Int?>(2)
a1[0] = null
a1[1] = notNull
println(a1[0])
println(a1[1])
val a2 = arrayOfNulls<Int>(2)
val a2 = arrayOfNulls<Int?>(2)
a2[0] = nullable()
a2[1] = notNull
println(a2[0])