[FIR-TEST] Add new testdata generated after changes in previous commit
This commit is contained in:
+12
@@ -0,0 +1,12 @@
|
||||
// One of the two passes is making a scope and turning vals into functions
|
||||
// See KT-76
|
||||
|
||||
package x
|
||||
|
||||
val b : Foo = Foo()
|
||||
val a1 = b.compareTo(2)
|
||||
|
||||
class Foo() {
|
||||
fun compareTo(other : Byte) : Int = 0
|
||||
fun compareTo(other : Char) : Int = 0
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
fun test() {
|
||||
var a : Any? = null
|
||||
if (a is Any) else a = null;
|
||||
while (a is Any) a = null
|
||||
while (true) a = null
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fun foo(u : Unit) : Int = 1
|
||||
|
||||
fun test() : Int {
|
||||
<!INAPPLICABLE_CANDIDATE!>foo<!>(1)
|
||||
val a : () -> Unit = {
|
||||
<!INAPPLICABLE_CANDIDATE!>foo<!>(1)
|
||||
}
|
||||
return 1
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
import java.util.*
|
||||
|
||||
import java.io.*
|
||||
|
||||
fun takeFirst(expr: StringBuilder): Char {
|
||||
val c = expr.get(0)
|
||||
expr.deleteCharAt(0)
|
||||
return c
|
||||
}
|
||||
|
||||
fun evaluateArg(expr: CharSequence, numbers: ArrayList<Int>): Int {
|
||||
if (expr.length == 0) throw Exception("Syntax error: Character expected");
|
||||
val c = <!INAPPLICABLE_CANDIDATE!>takeFirst<!>(expr)
|
||||
if (c >= '0' && c <= '9') {
|
||||
val n = c <!UNRESOLVED_REFERENCE!>-<!> '0'
|
||||
if (!numbers.contains(n)) throw Exception("You used incorrect number: " + n)
|
||||
numbers.<!AMBIGUITY!>remove<!>(n)
|
||||
return n
|
||||
}
|
||||
throw Exception("Syntax error: Unrecognized character " + c)
|
||||
}
|
||||
|
||||
fun evaluateAdd(expr: StringBuilder, numbers: ArrayList<Int>): Int {
|
||||
val lhs = evaluateArg(expr, numbers)
|
||||
if (expr.length > 0) {
|
||||
|
||||
}
|
||||
return lhs
|
||||
}
|
||||
|
||||
fun evaluate(expr: StringBuilder, numbers: ArrayList<Int>): Int {
|
||||
val lhs = evaluateAdd(expr, numbers)
|
||||
if (expr.length > 0) {
|
||||
val c = expr.get(0)
|
||||
expr.deleteCharAt(0)
|
||||
}
|
||||
return lhs
|
||||
}
|
||||
|
||||
fun main() {
|
||||
System.out.println("24 game")
|
||||
val numbers = ArrayList<Int>(4)
|
||||
val rnd = Random();
|
||||
val prompt = StringBuilder()
|
||||
for(i in 0..3) {
|
||||
val n = rnd.nextInt(9) + 1
|
||||
numbers.add(n)
|
||||
if (i > 0) prompt.append(" ");
|
||||
prompt.append(n)
|
||||
}
|
||||
System.out.println("Your numbers: " + prompt)
|
||||
System.out.println("Enter your expression:")
|
||||
val reader = BufferedReader(InputStreamReader(System.`in`))
|
||||
val expr = StringBuilder(reader.readLine()!!)
|
||||
try {
|
||||
val result = evaluate(expr, numbers)
|
||||
if (result != 24)
|
||||
System.out.println("Sorry, that's " + result)
|
||||
else
|
||||
System.out.println("You won!");
|
||||
}
|
||||
catch(e: Throwable) {
|
||||
System.out.println(e.message)
|
||||
}
|
||||
}
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
fun foo(a : Any) {}
|
||||
|
||||
fun test() {
|
||||
foo(object {});
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
// JET-11 Redeclaration & Forward reference for classes cause an exception
|
||||
open class NoC
|
||||
class NoC1 : NoC()
|
||||
open class NoC
|
||||
@@ -0,0 +1,14 @@
|
||||
package jet121
|
||||
|
||||
fun box() : String {
|
||||
val answer = apply("OK") {
|
||||
get(0)
|
||||
length
|
||||
}
|
||||
|
||||
return if (answer == 2) "OK" else "FAIL"
|
||||
}
|
||||
|
||||
fun apply(arg:String, f : String.() -> Int) : Int {
|
||||
return arg.<!UNRESOLVED_REFERENCE!>f<!>()
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fun foo1() : (Int) -> Int = { x: Int -> x }
|
||||
|
||||
fun foo() {
|
||||
val h : (Int) -> Int = foo1();
|
||||
h(1)
|
||||
val m : (Int) -> Int = {a : Int -> 1}//foo1()
|
||||
m(1)
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fun set(key : String, value : String) {
|
||||
val a : String? = ""
|
||||
when (a) {
|
||||
"" -> a.get(0)
|
||||
is String, is Any -> a.compareTo("")
|
||||
else -> a.toString()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// JET-17 Do not infer property types by the initializer before the containing scope is ready
|
||||
|
||||
class WithC() {
|
||||
val a = 1
|
||||
val b = a
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
enum class ProtocolState {
|
||||
WAITING {
|
||||
override fun signal() = ProtocolState.TALKING
|
||||
},
|
||||
|
||||
TALKING {
|
||||
override fun signal() = ProtocolState.WAITING
|
||||
};
|
||||
|
||||
abstract fun signal() : ProtocolState
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
var x: ProtocolState = ProtocolState.WAITING
|
||||
x = x.signal()
|
||||
if (x != ProtocolState.TALKING) return "fail 1"
|
||||
x = x.signal()
|
||||
if (x != ProtocolState.WAITING) return "fail 2"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
enum class ProtocolState {
|
||||
WAITING {
|
||||
override fun signal() = ProtocolState.TALKING
|
||||
},
|
||||
|
||||
TALKING {
|
||||
override fun signal() = ProtocolState.WAITING
|
||||
};
|
||||
|
||||
abstract fun signal() : ProtocolState
|
||||
}
|
||||
|
||||
fun box() {
|
||||
val x: ProtocolState = ProtocolState.WAITING
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
import java.util.Collections
|
||||
|
||||
val ab = checkSubtype<List<Int>?>(Collections.emptyList<Int>())
|
||||
@@ -0,0 +1,4 @@
|
||||
abstract class XXX {
|
||||
abstract val a : Int get
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
class Foo()
|
||||
|
||||
fun test() {
|
||||
val f : Foo? = null
|
||||
if (f == null) {
|
||||
|
||||
}
|
||||
if (f != null) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
class Command() {}
|
||||
|
||||
fun parse(cmd: String): Command? { return null }
|
||||
|
||||
fun Any.equals(other : Any?) : Boolean = this === other
|
||||
|
||||
fun main() {
|
||||
val command = parse("")
|
||||
if (command == null) 1 // error on this line, but must be OK
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// JET-72 Type inference doesn't work when iterating over ArrayList
|
||||
|
||||
import java.util.ArrayList
|
||||
|
||||
abstract class Item(val room: Object) {
|
||||
abstract val name : String
|
||||
}
|
||||
|
||||
val items: ArrayList<Item> = ArrayList<Item>()
|
||||
|
||||
fun test(room : Object) {
|
||||
for(item: Item? in items) {
|
||||
if (item?.room === room) {
|
||||
// item?.room is not null
|
||||
System.out.println("You see " + item?.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// NI_EXPECTED_FILE
|
||||
// JET-81 Assertion fails when processing self-referring anonymous objects
|
||||
|
||||
class Test {
|
||||
private val y = object {
|
||||
val a = y;
|
||||
}
|
||||
|
||||
val z = y.<!UNRESOLVED_REFERENCE!>a<!>;
|
||||
|
||||
}
|
||||
|
||||
object A {
|
||||
val x = A
|
||||
}
|
||||
|
||||
class Test2 {
|
||||
private val a = object {
|
||||
init {
|
||||
b + 1
|
||||
}
|
||||
val x = b
|
||||
val y = 1
|
||||
}
|
||||
|
||||
val b = a.x
|
||||
val c = a.y
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
class B {}
|
||||
|
||||
val b : B<*> = 1
|
||||
@@ -0,0 +1,22 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
class Point() {
|
||||
}
|
||||
|
||||
class G<T>() {}
|
||||
|
||||
fun <T> f(expression : T) : G<out T> = G<T>()
|
||||
|
||||
|
||||
fun foo() : G<Point> {
|
||||
val p = Point()
|
||||
return f<Point>(p)
|
||||
}
|
||||
|
||||
class Out<out T>() {}
|
||||
|
||||
fun <T> fout(expression : T) : Out<out T> = Out<T>()
|
||||
|
||||
fun fooout() : Out<Point> {
|
||||
val p = Point();
|
||||
return fout<Point>(p);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
fun box(c : C) {
|
||||
val a : C = c
|
||||
a.foo()
|
||||
}
|
||||
|
||||
open class A {
|
||||
open fun foo() {}
|
||||
}
|
||||
|
||||
open class B : A() {
|
||||
override fun foo() {}
|
||||
}
|
||||
|
||||
open class C : B() {
|
||||
override fun foo() {}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fun Any.equals(other : Any?) : Boolean = true
|
||||
|
||||
fun main() {
|
||||
|
||||
val command : Any = 1
|
||||
|
||||
command?.equals(null)
|
||||
command.equals(null)
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
fun main() {
|
||||
val a : Int? = null;
|
||||
var v = 1
|
||||
val b : String = v;
|
||||
val f : String = a!!;
|
||||
val g : String = v++;
|
||||
val g1 : String = ++v;
|
||||
val h : String = v--;
|
||||
val h1 : String = --v;
|
||||
val i : String = !true;
|
||||
val j : String = foo@ true;
|
||||
val k : String = foo@ bar@ true;
|
||||
val l : String = -1;
|
||||
val m : String = +1;
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
class A<T> : <!OTHER_ERROR!>T<!> {}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
interface Iterator<out T> {
|
||||
fun next() : T
|
||||
val hasNext : Boolean
|
||||
|
||||
fun <R> map(transform: (element: T) -> R) : Iterator<R> =
|
||||
object : Iterator<R> {
|
||||
override fun next() : R = transform(this@map.<!UNRESOLVED_REFERENCE!>next<!>())
|
||||
|
||||
override val hasNext : Boolean
|
||||
// There's no 'this' associated with the map() function, only this of the Iterator class
|
||||
get() = this@map.<!UNRESOLVED_REFERENCE!>hasNext<!>
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
open class Foo {}
|
||||
open class Bar {}
|
||||
|
||||
fun <T : Bar, T1> foo(x : Int) {}
|
||||
fun <T1, T : Foo> foo(x : Long) {}
|
||||
|
||||
fun f(): Unit {
|
||||
<!INAPPLICABLE_CANDIDATE!>foo<!><Int, Int>(1)
|
||||
}
|
||||
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
fun test(a: Int, b: Boolean) {
|
||||
<!INAPPLICABLE_CANDIDATE!>bar<!>(a.<!INAPPLICABLE_CANDIDATE!>foo<!>(b))
|
||||
}
|
||||
|
||||
fun <T, R> T.foo(l: (T) -> R): R = TODO()
|
||||
|
||||
fun <S> bar(a: S) {}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
class MyMetadata<in T, R>(val default: R) {
|
||||
operator fun getValue(thisRef: T, desc: KProperty<*>): R = TODO()
|
||||
operator fun setValue(thisRef: T, desc: KProperty<*>, value: R) {}
|
||||
}
|
||||
|
||||
interface Something
|
||||
class MyReceiver
|
||||
var MyReceiver.something: Something? by MyMetadata(default = null)
|
||||
@@ -0,0 +1,8 @@
|
||||
package checkFiles
|
||||
|
||||
import java.util.HashMap
|
||||
|
||||
fun main() {
|
||||
val hashMap = HashMap<String, String>()
|
||||
hashMap[<!SYNTAX!><!>]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
import A.<!SYNTAX!><!>;
|
||||
|
||||
class A
|
||||
@@ -0,0 +1,7 @@
|
||||
class A : Function0<Int> {
|
||||
override fun invoke(): Int = 1
|
||||
}
|
||||
|
||||
fun main() {
|
||||
A()()
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// !DIAGNOSTICS: -FUNCTION_DECLARATION_WITH_NO_NAME
|
||||
class ClassB() {
|
||||
private inner class ClassC: <!SYNTAX!>super<!><!SYNTAX!>.<!>@ClassA()<!SYNTAX!><!> {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
// !DIAGNOSTICS: -NO_VALUE_FOR_PARAMETER
|
||||
class Tree<T>(T <!SYNTAX!>element<!>, <!SYNTAX!><!>Tree<T><!SYNTAX!><!> left<!SYNTAX!><!>, <!SYNTAX!><!>Tree<T><!SYNTAX!><!> right<!SYNTAX!><!>) {}
|
||||
@@ -0,0 +1,5 @@
|
||||
enum class MyEnum {
|
||||
// Here we have a problem
|
||||
// while checking on a deprecated super constructor
|
||||
FIRST<!SYNTAX!><!SYNTAX!><!>:<!>
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
fun <T> g(x: T) = 1
|
||||
fun h(x: () -> Unit) = 1
|
||||
|
||||
fun foo() {
|
||||
<!UNRESOLVED_REFERENCE!>f<!>(::<!SYNTAX!><!>)
|
||||
<!INAPPLICABLE_CANDIDATE!>g<!>(::<!SYNTAX!><!>)
|
||||
<!INAPPLICABLE_CANDIDATE!>h<!>(::<!SYNTAX!><!>)
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
// StackOverflow
|
||||
val p = ::p
|
||||
|
||||
fun foo() = ::foo
|
||||
@@ -0,0 +1 @@
|
||||
val x: Char = '1'.plus(1)
|
||||
@@ -0,0 +1,3 @@
|
||||
// !DIAGNOSTICS: -MUST_BE_INITIALIZED -TYPE_PARAMETER_OF_PROPERTY_NOT_USED_IN_RECEIVER
|
||||
fun <T: T?> foo() {}
|
||||
val <T: T?> prop
|
||||
+1
@@ -0,0 +1 @@
|
||||
class MyClass<T: T?>
|
||||
+1
@@ -0,0 +1 @@
|
||||
class MyClass<T: T>
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
fun bar() {
|
||||
fun <T: T?> foo() {}
|
||||
foo()
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
// !DIAGNOSTICS: -MUST_BE_INITIALIZED_OR_BE_ABSTRACT -TYPE_PARAMETER_OF_PROPERTY_NOT_USED_IN_RECEIVER
|
||||
class My {
|
||||
fun <T: T?> foo() {}
|
||||
val <T: T?> prop: T
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
// !DIAGNOSTICS: -MUST_BE_INITIALIZED -TYPE_PARAMETER_OF_PROPERTY_NOT_USED_IN_RECEIVER
|
||||
fun <T: T> foo() {}
|
||||
val <T: T?> prop: T
|
||||
@@ -0,0 +1,17 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
val f: Boolean = true
|
||||
private fun doUpdateRegularTasks() {
|
||||
try {
|
||||
while (f) {
|
||||
val xmlText = <!UNRESOLVED_REFERENCE!>getText<!>()
|
||||
if (xmlText == null) {}
|
||||
else {
|
||||
xmlText.<!UNRESOLVED_REFERENCE!>value<!> = 0 // !!!
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
finally {
|
||||
fun execute() {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
var x: Int
|
||||
fun foo(f: Boolean) {
|
||||
try {
|
||||
if (f) {
|
||||
x = 0
|
||||
}
|
||||
}
|
||||
finally {
|
||||
fun bar() {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
var count = 0
|
||||
|
||||
operator fun Int.get(s: Int): Int {
|
||||
count++
|
||||
return this + s
|
||||
}
|
||||
|
||||
operator fun Int.set(s: Int, x: String = "", z: Int) {
|
||||
}
|
||||
|
||||
fun main() {
|
||||
<!INAPPLICABLE_CANDIDATE!>1[2] = 1<!>
|
||||
1.set(2, z = 1)
|
||||
1[2] += 1
|
||||
|
||||
1.<!INAPPLICABLE_CANDIDATE!>set<!>(2, 1)
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
// See KT-10824: Smart cast depending on control flow does not work inside `if`
|
||||
class A
|
||||
fun foo(a: A?, aOther: A?): A {
|
||||
return if (a == null) {
|
||||
A()
|
||||
}
|
||||
else {
|
||||
var newA = aOther
|
||||
if (newA == null) {
|
||||
newA = A()
|
||||
}
|
||||
newA
|
||||
}
|
||||
}
|
||||
fun bar(a: A?, aOther: A?): A {
|
||||
return if (a == null) {
|
||||
A()
|
||||
}
|
||||
else {
|
||||
if (aOther == null) {
|
||||
return A()
|
||||
}
|
||||
|
||||
aOther
|
||||
}
|
||||
}
|
||||
fun foo1(a: A?, aOther: A?): A {
|
||||
val result = if (a == null) {
|
||||
A()
|
||||
}
|
||||
else {
|
||||
var newA = aOther
|
||||
if (newA == null) {
|
||||
newA = A()
|
||||
}
|
||||
newA
|
||||
}
|
||||
return result
|
||||
}
|
||||
fun bar1(a: A?, aOther: A?): A {
|
||||
val result = if (a == null) {
|
||||
A()
|
||||
}
|
||||
else {
|
||||
if (aOther == null) {
|
||||
return A()
|
||||
}
|
||||
|
||||
aOther
|
||||
}
|
||||
return result
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// NI_EXPECTED_FILE
|
||||
// See EA-76890 / KT-10843: NPE during analysis
|
||||
fun lambda(x : Int?) = x?.<!UNRESOLVED_REFERENCE!>let<!> <!UNRESOLVED_REFERENCE!>l<!> {
|
||||
y ->
|
||||
if (y > 0) return@l x
|
||||
y
|
||||
}!!
|
||||
@@ -0,0 +1,18 @@
|
||||
// KT-127 Support extension functions in when expressions
|
||||
|
||||
class Foo() {}
|
||||
|
||||
fun Any?.equals1(other : Any?) : Boolean = true
|
||||
|
||||
fun main() {
|
||||
|
||||
val command : Foo? = null
|
||||
|
||||
// Commented for KT-621
|
||||
// when (command) {
|
||||
// .equals(null) => 1; // must be resolved
|
||||
// ?.equals(null) => 1 // same here
|
||||
// }
|
||||
command.equals1(null)
|
||||
command?.equals(null)
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// KT-128 Support passing only the last closure if all the other parameters have default values
|
||||
|
||||
fun div(c : String = "", f : () -> Unit) {}
|
||||
fun f() {
|
||||
div { // Nothing passed, but could have been...
|
||||
// ...
|
||||
}
|
||||
|
||||
div (c = "foo") { // More things could have been passed
|
||||
// ...
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !DIAGNOSTICS: -UNREACHABLE_CODE
|
||||
|
||||
fun foo() {
|
||||
val text: List<Any> = null!!
|
||||
text.<!UNRESOLVED_REFERENCE!>map<!> <!UNRESOLVED_REFERENCE!>Any<!><!SYNTAX!>?<!>::toString
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// FILE: foo/A.kt
|
||||
|
||||
package foo
|
||||
|
||||
class A(val c: C)
|
||||
|
||||
// FILE: foo/B.kt
|
||||
|
||||
package foo
|
||||
|
||||
class B {
|
||||
interface D {
|
||||
fun foo(): E
|
||||
}
|
||||
|
||||
class E
|
||||
}
|
||||
|
||||
// FILE: foo/C.java
|
||||
|
||||
package foo;
|
||||
|
||||
import static foo.B.D.*;
|
||||
|
||||
@SuppressWarnings("RedundantTypeArguments")
|
||||
public class C {}
|
||||
@@ -0,0 +1,20 @@
|
||||
// FILE: Foo.java
|
||||
public abstract class Foo {
|
||||
|
||||
public interface Transformer<T, R> {}
|
||||
public interface LifecycleTransformer<T> extends Transformer<T, T> {}
|
||||
|
||||
public class Observable<T> {
|
||||
public <R> Observable<R> compose(Transformer<? super T, ? extends R> transformer) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public final <T> LifecycleTransformer<T> bindToLifecycle() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: 1.kt
|
||||
fun <T> Foo.Observable<T>.bindTo(a: Foo): Foo.Observable<T> = compose(a.bindToLifecycle())
|
||||
@@ -0,0 +1,31 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
package kt606_dependents
|
||||
|
||||
//KT-1489 Code analyzer fails with assertion
|
||||
interface AutoCloseable{
|
||||
fun close()
|
||||
}
|
||||
|
||||
class C {
|
||||
class Resource : AutoCloseable {
|
||||
override fun close() {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
}
|
||||
|
||||
fun <X : AutoCloseable> foo(x : X, body : (X) -> Unit) {
|
||||
}
|
||||
|
||||
fun p() : Resource? = null
|
||||
|
||||
fun bar() {
|
||||
foo(p()) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//KT-1728 Can't invoke extension property as a function
|
||||
|
||||
val Int.ext : () -> Int get() = { 5 }
|
||||
val x = 1.ext()
|
||||
@@ -0,0 +1,12 @@
|
||||
package foo
|
||||
|
||||
import java.util.*
|
||||
|
||||
fun main()
|
||||
{
|
||||
val c = ArrayList<Int>()
|
||||
c.add(3)
|
||||
System.out.println(++(c[0]))
|
||||
System.out.println((c[1])--)
|
||||
System.out.println(-(c[2]))
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// JAVAC_EXPECTED_FILE
|
||||
// FILE: com/winterbe/domain/IEntity.java
|
||||
package com.winterbe.domain;
|
||||
import com.winterbe.observer.ObserverSupport;
|
||||
|
||||
public interface IEntity {
|
||||
ObserverSupport getObserverSupport();
|
||||
}
|
||||
|
||||
// FILE: 1.kt
|
||||
package com.winterbe.observer
|
||||
import com.winterbe.domain.IEntity
|
||||
|
||||
abstract class Observer : List<IEntity>
|
||||
|
||||
|
||||
// FILE: 2.kt
|
||||
package com.winterbe.observer
|
||||
import com.winterbe.domain.IEntity
|
||||
|
||||
class ObserverSupport<T : IEntity>(private val observers: List<Observer>)
|
||||
@@ -0,0 +1,13 @@
|
||||
// FILE: 1.kt
|
||||
package a
|
||||
import b.ObserverSupport
|
||||
|
||||
interface IEntity
|
||||
|
||||
fun IEntity(f: ObserverSupport<IEntity>) {}
|
||||
|
||||
// FILE: 2.kt
|
||||
package b
|
||||
import a.IEntity
|
||||
|
||||
class ObserverSupport<T : IEntity>
|
||||
@@ -0,0 +1,12 @@
|
||||
// FULL_JDK
|
||||
// SKIP_TXT
|
||||
|
||||
package test
|
||||
|
||||
import javax.swing.JFrame
|
||||
|
||||
class KFrame() : JFrame() {
|
||||
init {
|
||||
val x = this.rootPaneCheckingEnabled // make sure field is visible
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// KT-1647 Pattern matching doesn't work with generics
|
||||
|
||||
open class Abs
|
||||
class Bar : Abs()
|
||||
|
||||
fun <F : Abs> patternMatchingAndGenerics(arg : F) : String {
|
||||
if(arg is Bar){
|
||||
return "Bar";
|
||||
}
|
||||
return "else";
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
//KT-1736 AssertionError in CallResolver
|
||||
|
||||
package kt1736
|
||||
|
||||
object Obj {
|
||||
fun method() {
|
||||
}
|
||||
}
|
||||
|
||||
val x = Obj.<!INAPPLICABLE_CANDIDATE!>method<!>{ -> }
|
||||
@@ -0,0 +1,7 @@
|
||||
// KT-174 Nullability info for extension function receivers
|
||||
interface Tree {}
|
||||
|
||||
fun Any?.TreeValue() : Tree {
|
||||
if (this is Tree) return this
|
||||
throw Exception()
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// KT-201 Allow to call extension with nullable receiver with a '.'
|
||||
|
||||
fun <T : Any> T?.npe() : T = if (this == null) throw NullPointerException() else this
|
||||
|
||||
fun foo() {
|
||||
val i : Int? = 1
|
||||
i.npe() // error!
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
//KT-235 Illegal assignment return type
|
||||
|
||||
package kt235
|
||||
|
||||
fun main() {
|
||||
val array = MyArray()
|
||||
val f: () -> String = {
|
||||
array[2] = 23 //error: Type mismatch: inferred type is Int (!!!) but String was expected
|
||||
}
|
||||
val g: () -> String = {
|
||||
var x = 1
|
||||
x += 2 //no error, but it should be here
|
||||
}
|
||||
val h: () -> String = {
|
||||
var x = 1
|
||||
x = 2 //the same
|
||||
}
|
||||
val array1 = MyArray1()
|
||||
val i: () -> String = {
|
||||
array1[2] = 23
|
||||
}
|
||||
|
||||
val fi: () -> String = {
|
||||
array[2] = 23
|
||||
}
|
||||
val gi: () -> String = {
|
||||
var x = 1
|
||||
x += 21
|
||||
}
|
||||
|
||||
var m: MyNumber = MyNumber()
|
||||
val a: () -> MyNumber = {
|
||||
m++
|
||||
}
|
||||
}
|
||||
|
||||
class MyArray() {
|
||||
operator fun get(i: Int): Int = 1
|
||||
operator fun set(i: Int, value: Int): Int = 1
|
||||
}
|
||||
|
||||
class MyArray1() {
|
||||
operator fun get(i: Int): Int = 1
|
||||
operator fun set(i: Int, value: Int) {}
|
||||
}
|
||||
|
||||
class MyNumber() {
|
||||
operator fun inc(): MyNumber = MyNumber()
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// FILE: main.kt
|
||||
//KT-2376 java.lang.Number should be visible in Kotlin as kotlin.Number
|
||||
fun main() {
|
||||
Test().number(5.toInt())
|
||||
}
|
||||
|
||||
// FILE: Test.java
|
||||
public class Test {
|
||||
void number(Number n){}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// SKIP_TXT
|
||||
|
||||
class Bar {
|
||||
val a: Array<String>? = null
|
||||
}
|
||||
|
||||
fun foo(bar: Bar) = bar.a?.asIterable() ?: emptyArray()
|
||||
|
||||
fun <T> Array<out T>.asIterable(): Iterable<T> = TODO()
|
||||
|
||||
fun testFrontend() {
|
||||
val bar = Bar()
|
||||
foo(bar)
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
class A() {
|
||||
var x: Int = 0
|
||||
get() = "s"
|
||||
set(value: String) {
|
||||
field = value
|
||||
}
|
||||
val y: Int
|
||||
get(): String = "s"
|
||||
val z: Int
|
||||
get() {
|
||||
return "s"
|
||||
}
|
||||
|
||||
var a: Any = 1
|
||||
set(v: String) {
|
||||
field = v
|
||||
}
|
||||
val b: Int
|
||||
get(): Any = "s"
|
||||
val c: Int
|
||||
get() {
|
||||
return 1
|
||||
}
|
||||
val d = 1
|
||||
get() {
|
||||
return field
|
||||
}
|
||||
val e = 1
|
||||
get(): String {
|
||||
return field
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// KT-258 Support equality constraints in type inference
|
||||
|
||||
import java.util.*
|
||||
|
||||
fun test() {
|
||||
val attributes : HashMap<String, String> = HashMap()
|
||||
attributes["href"] = "1" // inference fails, but it shouldn't
|
||||
}
|
||||
|
||||
operator fun <K, V> MutableMap<K, V>.set(key : K, value : V) {}//= this.put(key, value)
|
||||
@@ -0,0 +1,9 @@
|
||||
// FILE: this.kt
|
||||
|
||||
// KT-26 Import namespaces defined in this file
|
||||
package foo
|
||||
|
||||
import bar.* // Must not be an error
|
||||
|
||||
// FILE: other.kt
|
||||
package bar
|
||||
@@ -0,0 +1,12 @@
|
||||
// FILE: a.kt
|
||||
// KT-26 Import namespaces defined in this file
|
||||
|
||||
import html.* // Must not be an error
|
||||
|
||||
// FILE: b.kt
|
||||
|
||||
package html
|
||||
|
||||
abstract class Factory<T: Any> {
|
||||
fun create() : T? = null
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// FILE: a.kt
|
||||
|
||||
package foo
|
||||
|
||||
operator fun Int.invoke() = null
|
||||
fun Int.foo() = null
|
||||
|
||||
// FILE: b.kt
|
||||
|
||||
package bar
|
||||
|
||||
import foo.foo as invoke
|
||||
import foo.invoke
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
<!AMBIGUITY!>42()<!>
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
fun <T> assertEquals(a: T, b: T) {
|
||||
if (a != b) throw AssertionError("$a != $b")
|
||||
}
|
||||
|
||||
fun main() {
|
||||
val bytePos = 128.toByte() // Byte.MAX_VALUE + 1
|
||||
assertEquals(-128, bytePos.toInt()) // correct, wrapped to Byte.MIN_VALUE
|
||||
|
||||
val byteNeg: Byte = -bytePos // should not compile, byteNeg should be Int
|
||||
assertEquals(128, byteNeg.toInt()) // passes, should not be possible
|
||||
|
||||
val shortPos = 32768.toShort() // Short.MAX_VALUE + 1
|
||||
assertEquals(-32768, shortPos.toInt()) // correct, wrapped to Short.MIN_VALUE
|
||||
|
||||
val shortNeg: Short = -shortPos // should not compile, shortNeg should be Int
|
||||
assertEquals(32768, shortNeg.toInt()) // passes, should not be possible
|
||||
|
||||
(-128).toByte()
|
||||
-128.toByte()
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
|
||||
private object Case1 {
|
||||
interface Validator<in T>
|
||||
|
||||
class CharSequenceValidator: Validator<CharSequence>
|
||||
|
||||
class PredicateValidator<T>(val predicate: (T) -> Boolean): Validator<T>
|
||||
|
||||
class CompositeValidator<T>(vararg val validators: Validator<T>)
|
||||
|
||||
fun process(input: String) = true
|
||||
|
||||
fun main() {
|
||||
val validators1 = CompositeValidator(CharSequenceValidator(), PredicateValidator(::process))
|
||||
val validators2 = CompositeValidator<String>(CharSequenceValidator(), PredicateValidator(::process))
|
||||
val validators3 = CompositeValidator(CharSequenceValidator(), PredicateValidator { it: String -> process(it) })
|
||||
}
|
||||
}
|
||||
|
||||
private object Case2 {
|
||||
interface Expr<out T>
|
||||
data class Add(val left: Expr<Int>, val right: Expr<Int>): Expr<Int>
|
||||
data class Subtract(val left: Expr<Int>, val right: Expr<Int>): Expr<Int>
|
||||
|
||||
fun f() {
|
||||
val operators1 = listOf(::Add, ::Subtract)
|
||||
val operators2 = listOf<(Expr<Int>, Expr<Int>) -> Expr<Int>>(::Add, ::Subtract)
|
||||
}
|
||||
|
||||
fun <T> listOf(vararg elements: T): List<T> = TODO()
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// KT-282 Nullability in extension functions and in binary calls
|
||||
|
||||
class Set {
|
||||
operator fun contains(x : Int) : Boolean = true
|
||||
}
|
||||
|
||||
operator fun Set?.plus(x : Int) : Int = 1
|
||||
|
||||
operator fun Int?.contains(x : Int) : Boolean = false
|
||||
|
||||
fun f(): Unit {
|
||||
var set : Set? = null
|
||||
val i : Int? = null
|
||||
i <!INAPPLICABLE_CANDIDATE!>+<!> 1
|
||||
set + 1
|
||||
1 <!INAPPLICABLE_CANDIDATE!>in<!> set
|
||||
1 in 2
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// KT-287 Infer constructor type arguments
|
||||
|
||||
import java.util.*
|
||||
|
||||
fun attributes() : Map<String, String> = HashMap() // Should be inferred;
|
||||
val attributes : Map<String, String> = HashMap() // Should be inferred;
|
||||
|
||||
fun foo(m : Map<String, String>) {}
|
||||
|
||||
fun test() {
|
||||
foo(HashMap())
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
val a: String = Nothing
|
||||
@@ -0,0 +1,13 @@
|
||||
// KT-302 Report an error when inheriting many implementations of the same member
|
||||
|
||||
package kt302
|
||||
|
||||
interface A {
|
||||
open fun foo() {}
|
||||
}
|
||||
|
||||
interface B {
|
||||
open fun foo() {}
|
||||
}
|
||||
|
||||
class C : A, B {} //should be error here
|
||||
@@ -0,0 +1,23 @@
|
||||
// KT-306 Ambiguity when different this's have same-looking functions
|
||||
|
||||
fun test() {
|
||||
(fun Foo.() {
|
||||
<!UNRESOLVED_REFERENCE!>bar<!>()
|
||||
(fun Barr.() {
|
||||
this.<!UNRESOLVED_REFERENCE!>bar<!>()
|
||||
<!UNRESOLVED_REFERENCE!>bar<!>()
|
||||
})
|
||||
})
|
||||
(fun Barr.() {
|
||||
this.<!UNRESOLVED_REFERENCE!>bar<!>()
|
||||
<!UNRESOLVED_REFERENCE!>bar<!>()
|
||||
})
|
||||
}
|
||||
|
||||
class Foo {
|
||||
fun bar() {}
|
||||
}
|
||||
|
||||
class Barr {
|
||||
fun bar() {}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// KT-307 Unresolved reference
|
||||
|
||||
open class AL {
|
||||
fun get(i : Int) : Any? = i
|
||||
}
|
||||
|
||||
interface ALE<T> : AL {
|
||||
fun getOrNull(index: Int, value: T) : T {
|
||||
return get(index) as? T ?: value
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// KT-312 Nullability problem when a nullable version of a generic type is returned
|
||||
|
||||
fun <T> Array<out T>.safeGet(index : Int) : T? {
|
||||
return if (index < size) this[index] else null
|
||||
}
|
||||
|
||||
val args : Array<String> = Array<String>(1, {""})
|
||||
val name : String = args.safeGet<String>(0) // No error, must be type mismatch
|
||||
val name1 : String? = args.safeGet(0)
|
||||
@@ -0,0 +1,11 @@
|
||||
// KT-313 Bug in substitutions in a function returning its type parameter T
|
||||
|
||||
fun <T> Iterable<T>.join(separator : String?) : String {
|
||||
return separator.npe()
|
||||
}
|
||||
|
||||
fun <T : Any> T?.npe() : T {
|
||||
if (this == null)
|
||||
throw NullPointerException()
|
||||
return this;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// KT-316 Members of traits must be open by default
|
||||
|
||||
interface B {
|
||||
fun bar() {}
|
||||
fun foo() {}
|
||||
}
|
||||
|
||||
open class A() : B{
|
||||
override fun foo() {}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
interface MemoizedFunctionToNotNull<K, V>
|
||||
|
||||
fun <K, V : Any> createMemoizedFunction(compute: (K) -> V): MemoizedFunctionToNotNull<K, V> = TODO()
|
||||
|
||||
interface A
|
||||
|
||||
interface TypeConstructor
|
||||
|
||||
class Refiner {
|
||||
val memoizedFunctionLambda = createMemoizedFunction { it.<!INAPPLICABLE_CANDIDATE!>foo<!>() } // error type infered, no diagnostic, BAD, backend fails
|
||||
val memoizedFunctionReference = createMemoizedFunction(TypeConstructor::foo) // EXTENSION_IN_CLASS_REFERENCE_IS_NOT_ALLOWED, fine
|
||||
val memoizedFunctionTypes = createMemoizedFunction<TypeConstructor, Boolean> { it.foo() } // works fine
|
||||
|
||||
private fun TypeConstructor.foo(): Boolean = true
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// FILE: A.java
|
||||
|
||||
public class A {
|
||||
public static void foo(A... values) {}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun test(vararg values: A) {
|
||||
A.foo(*values)
|
||||
A.<!INAPPLICABLE_CANDIDATE!>foo<!>(values)
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
//KT-328 Local function in function literals cause exceptions
|
||||
|
||||
fun bar1() = {
|
||||
bar1()
|
||||
}
|
||||
|
||||
fun bar2() = {
|
||||
fun foo2() = bar2()
|
||||
}
|
||||
|
||||
//properties
|
||||
//in a class
|
||||
class A() {
|
||||
val x = { x }
|
||||
}
|
||||
|
||||
//in a package
|
||||
val x = { x }
|
||||
|
||||
//KT-787 AssertionError on code 'val x = x'
|
||||
val z = z
|
||||
|
||||
//KT-329 Assertion failure on local function
|
||||
fun block(f : () -> Unit) = f()
|
||||
|
||||
fun bar3() = block{ <!UNRESOLVED_REFERENCE!>foo3<!>() // <-- missing closing curly bracket
|
||||
fun foo3() = block{ bar3() }<!SYNTAX!><!>
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
inline fun <reified T> parse(json: String): T? = TODO()
|
||||
|
||||
class MyType
|
||||
|
||||
fun parseMyData(json: String): MyType =
|
||||
try {
|
||||
parse(json) // error with new inf only: Cannot use 'Nothing?' as reified type parameter
|
||||
?: throw IllegalArgumentException("Can't parse")
|
||||
} catch (e: Exception) {
|
||||
throw IllegalArgumentException("Can't parse")
|
||||
}
|
||||
|
||||
fun main() {
|
||||
parseMyData("")
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// !CHECK_TYPE
|
||||
|
||||
import java.lang.Comparable as Comparable
|
||||
|
||||
fun f(c: Comparable<*>) {
|
||||
<!INAPPLICABLE_CANDIDATE!>checkSubtype<!><kotlin.Comparable<*>>(c)
|
||||
checkSubtype<java.lang.Comparable<*>>(c)
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// KT-336 Can't infer type parameter for ArrayList in a generic function (Exception in type inference)
|
||||
// KT-335 Type inference fails on Collections.sort
|
||||
|
||||
import java.util.*
|
||||
|
||||
fun <T : Comparable<T>> MutableList<T>.sort() {
|
||||
Collections.sort(this) // Error here
|
||||
}
|
||||
|
||||
fun <T> List<T>.plus(other : List<T>) : List<T> {
|
||||
val result = ArrayList(this)
|
||||
return result
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
//KT-337 Can't break a line before a dot
|
||||
|
||||
class A() {
|
||||
fun foo() {}
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val a = A()
|
||||
|
||||
a
|
||||
|
||||
.foo() // Should be a valid expression
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
//KT-352 Function variable declaration type isn't checked inside a function body
|
||||
|
||||
package kt352
|
||||
|
||||
val f : (Any) -> Unit = { -> } //type mismatch
|
||||
|
||||
fun foo() {
|
||||
val f : (Any) -> Unit = { -> } //!!! no error
|
||||
}
|
||||
|
||||
class A() {
|
||||
val f : (Any) -> Unit = { -> } //type mismatch
|
||||
}
|
||||
|
||||
//more tests
|
||||
val g : () -> Unit = { 42 }
|
||||
val gFunction : () -> Unit = fun(): Int = 1
|
||||
|
||||
val h : () -> Unit = { doSmth() }
|
||||
|
||||
fun doSmth(): Int = 42
|
||||
fun doSmth(a: String) {}
|
||||
|
||||
val testIt : (Any) -> Unit = {
|
||||
if (it is String) {
|
||||
doSmth(it)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// KT-353 Generic type argument inference sometimes doesn't work
|
||||
|
||||
interface A {
|
||||
fun <T> gen() : T
|
||||
}
|
||||
|
||||
fun foo(a: A) {
|
||||
val g : () -> Unit = {
|
||||
a.gen() //it works: Unit is derived
|
||||
}
|
||||
|
||||
val u: Unit = a.gen() // Unit should be inferred
|
||||
|
||||
if (true) {
|
||||
a.gen() // Shouldn't work: no info for inference
|
||||
}
|
||||
|
||||
val b : () -> Unit = {
|
||||
if (true) {
|
||||
a.gen() // unit can be inferred
|
||||
}
|
||||
else {
|
||||
Unit
|
||||
}
|
||||
}
|
||||
|
||||
val f : () -> Int = {
|
||||
a.gen() //type mismatch, but Int can be derived
|
||||
}
|
||||
|
||||
a.gen() // Shouldn't work: no info for inference
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// KT-3535 Functional value-parametr in nested class is inaccessible
|
||||
|
||||
class Foo {
|
||||
class Bar(val p: (Any) -> Any) {
|
||||
fun f() {
|
||||
p(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// KT-3647 Unexpected compilation error: "Expression is inaccessible from a nested class"
|
||||
|
||||
class Test(val value: Int) {
|
||||
companion object {
|
||||
fun create(init: () -> Int): Test {
|
||||
return Test(init())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// KT-3731 Resolve & inner class
|
||||
|
||||
class A {
|
||||
fun foo() {}
|
||||
fun bar(f: A.() -> Unit = {}) = <!INAPPLICABLE_CANDIDATE!>f<!>()
|
||||
}
|
||||
|
||||
class B {
|
||||
class D {
|
||||
init {
|
||||
A().bar {
|
||||
this.<!UNRESOLVED_REFERENCE!>foo<!>()
|
||||
<!UNRESOLVED_REFERENCE!>foo<!>()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
interface A {
|
||||
var foo: String
|
||||
}
|
||||
|
||||
class B(override val foo: String) : A
|
||||
@@ -0,0 +1,33 @@
|
||||
// KT-385 type inference does not work properly`
|
||||
// KT-109 Good code is red: type arguments are not inferred
|
||||
// KT-441 Exception in type inference when multiple overloads accepting an integer literal are accessible
|
||||
|
||||
import java.util.*
|
||||
|
||||
infix fun <T> Iterator<T>.foreach(operation: (element: T) -> Unit) : Unit { while(hasNext()) operation(next()) }
|
||||
|
||||
infix fun <T> Iterator<T>.foreach(operation: (index: Int, element: T) -> Unit) : Unit {
|
||||
var k = 0
|
||||
while(hasNext())
|
||||
operation(k++, next())
|
||||
}
|
||||
|
||||
fun <T> Iterable<T>.foreach(operation: (element: T) -> Unit) : Unit = iterator() foreach operation
|
||||
|
||||
fun <T> Iterable<T>.foreach(operation: (index: Int, element: T) -> Unit) : Unit = iterator() foreach operation
|
||||
|
||||
fun box() : String {
|
||||
return generic_invoker( { "OK"} )
|
||||
}
|
||||
|
||||
fun <T> generic_invoker(gen : () -> T) : T {
|
||||
return gen()
|
||||
}
|
||||
|
||||
fun println(message : Int) { System.out.println(message) }
|
||||
fun println(message : Long) { System.out.println(message) }
|
||||
|
||||
fun main() {
|
||||
|
||||
println(run { 1 })
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// KT-394 Make companion object members visible inside the owning class
|
||||
|
||||
class X() {
|
||||
// class Y {}
|
||||
|
||||
companion object{
|
||||
class Y() {}
|
||||
}
|
||||
|
||||
val y : Y = Y()
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// KT-398 Internal error when property initializes with function
|
||||
|
||||
class X<T>() {
|
||||
val check = { a : Any -> a is T }
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
if(X<String>().check(10)) return "fail"
|
||||
if(!X<String>().check("lala")) return "fail"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// KT-399 Type argument inference not implemented for CALL_EXPRESSION
|
||||
|
||||
fun <T> getSameTypeChecker(obj: T) : Function1<Any,Boolean> {
|
||||
return { a : Any -> a is T }
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
if(getSameTypeChecker<String>("lala")(10)) return "fail"
|
||||
if(!getSameTypeChecker<String>("mama")("lala")) return "fail"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package kt402
|
||||
|
||||
fun getTypeChecker() : (Any)->Boolean {
|
||||
{ a : Any -> a is T } // reports unsupported
|
||||
}
|
||||
fun f() : (Any) -> Boolean {
|
||||
return { a : Any -> a is String }
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// KT-41 Make functions with errors in returning statement return ERROR type and not Nothing
|
||||
|
||||
package kt41
|
||||
|
||||
fun aaa() =
|
||||
6 <!UNRESOLVED_REFERENCE!>foo<!> 1
|
||||
|
||||
fun bbb() {
|
||||
aaa()
|
||||
1 // Stupid error: unreachable code
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user