diagnostics for deprecated syntax of function type parameter list

This commit is contained in:
Dmitry Jemerov
2015-10-05 20:26:47 +02:00
parent c5d3673b6b
commit 7c20630272
156 changed files with 236 additions and 213 deletions
@@ -249,6 +249,8 @@ public interface Errors {
DiagnosticFactory0<JetTypeParameter>
VARIANCE_ON_TYPE_PARAMETER_OF_FUNCTION_OR_PROPERTY = DiagnosticFactory0.create(ERROR, VARIANCE_MODIFIER);
DiagnosticFactory0<JetTypeParameterList> DEPRECATED_TYPE_PARAMETER_SYNTAX = DiagnosticFactory0.create(WARNING);
DiagnosticFactory0<PsiElement> REIFIED_TYPE_PARAMETER_NO_INLINE = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<JetDeclaration> TYPE_PARAMETERS_NOT_ALLOWED
@@ -483,6 +483,9 @@ public class DefaultErrorMessages {
MAP.put(MISSING_CONSTRUCTOR_KEYWORD, "Use 'constructor' keyword after modifiers of primary constructor");
MAP.put(VARIANCE_ON_TYPE_PARAMETER_OF_FUNCTION_OR_PROPERTY, "Variance annotations are only allowed for type parameters of classes and interfaces");
MAP.put(DEPRECATED_TYPE_PARAMETER_SYNTAX, "Placing function type parameters after the function name is deprecated");
MAP.put(TYPE_VARIANCE_CONFLICT, "Type parameter {0} is declared as ''{1}'' but occurs in ''{2}'' position in type {3}",
new MultiRenderer<VarianceConflictDiagnosticData>() {
@NotNull
@@ -489,6 +489,13 @@ public class DeclarationsChecker {
}
protected void checkFunction(JetNamedFunction function, SimpleFunctionDescriptor functionDescriptor) {
JetTypeParameterList typeParameterList = function.getTypeParameterList();
PsiElement nameIdentifier = function.getNameIdentifier();
if (typeParameterList != null && nameIdentifier != null &&
typeParameterList.getTextRange().getStartOffset() > nameIdentifier.getTextRange().getStartOffset()) {
trace.report(DEPRECATED_TYPE_PARAMETER_SYNTAX.on(typeParameterList));
}
DeclarationDescriptor containingDescriptor = functionDescriptor.getContainingDeclaration();
boolean hasAbstractModifier = function.hasModifier(JetTokens.ABSTRACT_KEYWORD);
if (containingDescriptor instanceof ClassDescriptor) {
@@ -5,9 +5,9 @@ import kotlin.platform.platformStatic
class PlatformStaticClass {
companion object {
@platformStatic
fun inClassObject<T>() {}
fun <T> inClassObject() {}
}
fun inClass<T>() {}
fun <T> inClass() {}
}
+1 -1
View File
@@ -108,7 +108,7 @@ sink:
<SINK> PREV:[<ERROR>, <END>]
=====================
== genfun ==
fun genfun<T>() : Unit {}
fun <T> genfun() : Unit {}
---------------------
L0:
1 <START>
+1 -1
View File
@@ -18,6 +18,6 @@ fun f(a : Boolean) : Unit {
fun foo(a : Boolean, b : Int) : Unit {}
fun genfun<T>() : Unit {}
fun <T> genfun() : Unit {}
fun flfun(f : () -> Any) : Unit {}
+1 -1
View File
@@ -60,7 +60,7 @@ fun foo(a : Boolean, b : Int) : Unit {}
<v1>: Int NEW: magic[FAKE_INITIALIZER](b : Int) -> <v1>
=====================
== genfun ==
fun genfun<T>() : Unit {}
fun <T> genfun() : Unit {}
---------------------
=====================
== flfun ==
+1 -1
View File
@@ -26,7 +26,7 @@ fun box(): String {
return "OK"
}
fun check<T>(param: T, f: (T) -> Unit): String {
fun <T> check(param: T, f: (T) -> Unit): String {
try {
f(param)
}
+1 -1
View File
@@ -1,4 +1,4 @@
fun castToString<T>(t: T) {
fun <T> castToString(t: T) {
t as String
}
+1 -1
View File
@@ -1,5 +1,5 @@
fun box() : String {
fun foo<T>(t:() -> T) : T = t()
fun <T> foo(t:() -> T) : T = t()
return foo {"OK"}
}
+1 -1
View File
@@ -16,4 +16,4 @@ fun box(): String {
return "OK"
}
fun run1<T>(f: () -> T): T { return f() }
fun <T> run1(f: () -> T): T { return f() }
@@ -16,4 +16,4 @@ fun box(): String {
return "OK"
}
fun run1<T>(f: () -> T): T { return f() }
fun <T> run1(f: () -> T): T { return f() }
@@ -7,7 +7,7 @@ class Delegate {
fun propertyDelegated(a: Int) { inner = "fail" }
fun propertyDelegated(a: String) { inner = "fail" }
fun propertyDelegated(p: PropertyMetadata, a: Int) { inner = "fail" }
fun propertyDelegated<T>(p: PropertyMetadata, s: String = "") { inner = "fail" }
fun <T> propertyDelegated(p: PropertyMetadata, s: String = "") { inner = "fail" }
}
val prop by Delegate()
+1 -1
View File
@@ -1,4 +1,4 @@
fun foo<T>(t: T) {
fun <T> foo(t: T) {
t!!
}
@@ -6,9 +6,9 @@ fun Int.foo2() : (i : Int) -> Int {
return { x -> x + this }
}
fun fooT1<T>(t : T) = { t.toString() }
fun <T> fooT1(t : T) = { t.toString() }
fun fooT2<T>(t: T) = { x:T -> t.toString() + x.toString() }
fun <T> fooT2(t: T) = { x:T -> t.toString() + x.toString() }
object t
+1 -1
View File
@@ -1,6 +1,6 @@
// KT-2739 Error type inferred for hashSet(Pair, Pair, Pair)
fun foo<T>(vararg ts: T): T? = null
fun <T> foo(vararg ts: T): T? = null
class Pair<A>(a: A)
+1 -1
View File
@@ -1,4 +1,4 @@
fun foo<T>(t: T) {
fun <T> foo(t: T) {
}
fun box(): String {
@@ -1,5 +1,5 @@
fun box(): String {
fun foo<T>(t: T) = t
fun <T> foo(t: T) = t
return foo("OK")
}
+1 -1
View File
@@ -102,7 +102,7 @@ var Int.Companion.TopField : Int
fun Int.Companion.TopFun() : String = "TopFun"
fun myAssertEquals<T>(a: T, b: T) {
fun <T> myAssertEquals(a: T, b: T) {
if (a != b) throw Exception("$a != $b")
}
+1 -1
View File
@@ -4,7 +4,7 @@ class Identifier<T>(t : T?, myHasDollar : Boolean) {
public fun getName() : T? { return myT }
companion object {
open public fun init<T>(name : T?) : Identifier<T> {
open public fun <T> init(name : T?) : Identifier<T> {
val __ = Identifier<T>(name, false)
return __
}
+1 -1
View File
@@ -15,7 +15,7 @@ public open class Identifier<T>(myName : T?, myHasDollar : Boolean) {
}
companion object {
open public fun init<T>(name : T?) : Identifier<T> {
open public fun <T> init(name : T?) : Identifier<T> {
val __ = Identifier<T>(name, false)
return __
}
@@ -1,6 +1,6 @@
var entered = 0
fun foo<T>(t: T): T {
fun <T> foo(t: T): T {
entered++
return t
}
+1 -1
View File
@@ -1,4 +1,4 @@
fun assertEquals<T>(a: T, b: T) {
fun <T> assertEquals(a: T, b: T) {
if (a != b) throw AssertionError("$a != $b")
}
+1 -1
View File
@@ -1,6 +1,6 @@
class Foo {
fun bar(): String {
fun foo<T>(t:() -> T) : T = t()
fun <T> foo(t:() -> T) : T = t()
foo { }
return "OK"
}
+1 -1
View File
@@ -28,4 +28,4 @@ public fun Input.copyTo(output: Output, size: Int): Long {
}
public inline fun with2<T>(receiver : T, crossinline body : T.() -> Unit) : Unit = {receiver.body()}()
public inline fun <T> with2(receiver : T, crossinline body : T.() -> Unit) : Unit = {receiver.body()}()
@@ -1,5 +1,5 @@
fun test1<T>() = null as T
fun test2<T>(): T {
fun <T> test1() = null as T
fun <T> test2(): T {
val a : Any? = null
return a as T
}
+1 -1
View File
@@ -5,7 +5,7 @@ class UpdateableThing {
private val lock = ReentrantReadWriteLock()
private var updateCount = 0
fun performUpdates<T>(block: () -> T): T {
fun <T> performUpdates(block: () -> T): T {
lock.write {
++updateCount
val result = block()
@@ -1,6 +1,6 @@
inline fun calc<T, R>(value : T, fn: (T)->R) : R = fn(value)
inline fun identity<T>(value : T) : T = calc(value) {
inline fun <T> identity(value : T) : T = calc(value) {
if (1 == 1) return it
it
}
@@ -1,3 +1,3 @@
fun foo<T>(a: List<T>) {
fun <T> foo(a: List<T>) {
val t: T = a.get(0)
}
+2 -2
View File
@@ -37,6 +37,6 @@ fun test() {
1.buzz<<!UPPER_BOUND_VIOLATED!>Double<!>>()
}
fun foo<T : Any>() {}
fun bar<T : Int?>() {}
fun <T : Any> foo() {}
fun <T : Int?> bar() {}
fun <T : <!FINAL_UPPER_BOUND!>Int<!>> Int.buzz() : Unit {}
+1 -1
View File
@@ -69,7 +69,7 @@ abstract class Tag(val name : String) : Element {
val children = ArrayList<Element>()
val attributes = HashMap<String, String>()
protected fun initTag<T : Element>(tag : T, init : T.() -> Unit) : T {
protected fun <T : Element> initTag(tag : T, init : T.() -> Unit) : T {
tag.init()
children.add(tag)
return tag
@@ -14,11 +14,11 @@ fun foo2() : (i : () -> Unit) -> Unit {
return {}
}
fun fooT1<T>(t : T) : () -> T {
fun <T> fooT1(t : T) : () -> T {
return {t}
}
fun fooT2<T>() : (t : T) -> T {
fun <T> fooT2() : (t : T) -> T {
return {it}
}
@@ -1,7 +1,7 @@
// !CHECK_TYPE
// A generic funciton is always less specific than a non-generic one
fun foo<T>(<!UNUSED_PARAMETER!>t<!> : T) : Unit {}
fun <T> foo(<!UNUSED_PARAMETER!>t<!> : T) : Unit {}
fun foo(<!UNUSED_PARAMETER!>i<!> : Int) : Int = 1
fun test() {
+2 -2
View File
@@ -32,7 +32,7 @@ val y1 = foobar.a.b
/////////////////////////////////////////////////////////////////////////
fun done<O>(result : O) : Iteratee<Any?, O> = StrangeIterateeImpl<Any?, O>(result)
fun <O> done(result : O) : Iteratee<Any?, O> = StrangeIterateeImpl<Any?, O>(result)
abstract class Iteratee<in I, out O> {
abstract fun process(item : I) : Iteratee<I, O>
@@ -58,7 +58,7 @@ abstract class Sum() : Iteratee<Int, Int>() {
}
abstract class Collection<E> : Iterable<E> {
fun iterate<O>(iteratee : Iteratee<E, O>) : O {
fun <O> iterate(iteratee : Iteratee<E, O>) : O {
var current = iteratee
for (x in this) {
val it = current.process(x)
@@ -1,6 +1,6 @@
fun getT<T>() {}
fun getTT<A, B>() {}
fun getTTT<A, B, C>(<!UNUSED_PARAMETER!>x<!> : Any) {}
fun <T> getT() {}
fun <A, B> getTT() {}
fun <A, B, C> getTTT(<!UNUSED_PARAMETER!>x<!> : Any) {}
fun foo(<!UNUSED_PARAMETER!>a<!> : Any?) {}
public fun main() {
+1 -1
View File
@@ -3,7 +3,7 @@ class C<T>() {
}
fun foo(<!UNUSED_PARAMETER!>c<!>: C<Int>) {}
fun bar<T>() : C<T> {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
fun <T> bar() : C<T> {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
fun main(args : Array<String>) {
val <!UNUSED_VARIABLE!>a<!> : C<Int> = C();
@@ -1,3 +1,3 @@
fun ff<T>(l: MutableCollection<T>) = l is MutableList<T>
fun <T> ff(l: MutableCollection<T>) = l is MutableList<T>
@@ -1,3 +1,3 @@
class G<T>
fun f<Q>(q: Q) = q is G<*>
fun <Q> f(q: Q) = q is G<*>
@@ -1,8 +1,8 @@
import kotlin.reflect.KClass
fun f1<T>(): KClass<Array<T>> = <!CLASS_LITERAL_LHS_NOT_A_CLASS!>Array<T>::class<!>
fun f2<T>(): KClass<Array<Array<T>>> = <!CLASS_LITERAL_LHS_NOT_A_CLASS!>Array<Array<T>>::class<!>
inline fun f3<reified T>() = Array<T>::class
inline fun f4<reified T>() = Array<Array<T>>::class
fun <T> f1(): KClass<Array<T>> = <!CLASS_LITERAL_LHS_NOT_A_CLASS!>Array<T>::class<!>
fun <T> f2(): KClass<Array<Array<T>>> = <!CLASS_LITERAL_LHS_NOT_A_CLASS!>Array<Array<T>>::class<!>
inline fun <reified T> f3() = Array<T>::class
inline fun <reified T> f4() = Array<Array<T>>::class
fun f5(): KClass<Array<Any>> = <!CLASS_LITERAL_LHS_NOT_A_CLASS!>Array<*>::class<!>
fun f6(): KClass<Array<Int?>> = Array<Int?>::class
@@ -8,7 +8,7 @@ val a2 = <!CLASS_LITERAL_LHS_NOT_A_CLASS!>A?<!REDUNDANT_NULLABLE!>?<!>::class<!>
val l1 = <!CLASS_LITERAL_LHS_NOT_A_CLASS!>List<String>?::class<!>
val l2 = <!CLASS_LITERAL_LHS_NOT_A_CLASS!>List?::class<!>
fun foo<T : Any>() {
fun <T : Any> foo() {
val t1 = <!CLASS_LITERAL_LHS_NOT_A_CLASS!>T::class<!>
val t2 = <!CLASS_LITERAL_LHS_NOT_A_CLASS!>T?::class<!>
}
@@ -9,7 +9,7 @@ class D {
val cTopLevel: Int by <!DELEGATE_SPECIAL_FUNCTION_MISSING!>IncorrectThis<A>()<!>
class IncorrectThis<T> {
fun get<R>(t: Any?, p: PropertyMetadata): Int {
fun <R> get(t: Any?, p: PropertyMetadata): Int {
return 1
}
}
@@ -13,9 +13,9 @@ class A(outer: Outer) {
var f: String by <!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>foo<!>(<!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>getMyProperty<!>()) <!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>-<!> 1
}
fun foo<A, B>(<!UNUSED_PARAMETER!>a<!>: Any?) = MyProperty<A, B>()
fun <A, B> foo(<!UNUSED_PARAMETER!>a<!>: Any?) = MyProperty<A, B>()
fun getMyProperty<A, B>() = MyProperty<A, B>()
fun <A, B> getMyProperty() = MyProperty<A, B>()
fun getMyConcreteProperty() = MyProperty<Any?, String>()
@@ -35,7 +35,7 @@ operator fun <R, T> MyProperty<R, T>.plus() = MyProperty<R, T>()
operator fun <R, T> MyProperty<R, T>.minus(<!UNUSED_PARAMETER!>i<!>: Int) = MyProperty<R, T>()
object O {
fun getMyProperty<A, B>() = MyProperty<A, B>()
fun <A, B> getMyProperty() = MyProperty<A, B>()
}
interface MyPropertyContainer {
@@ -5,7 +5,7 @@ class A {
var b5: String by <!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>getMyProperty1<!>()
}
fun getMyProperty1<A, B>() = MyProperty1<A, B>()
fun <A, B> getMyProperty1() = MyProperty1<A, B>()
class MyProperty1<T, R> {
@@ -25,7 +25,7 @@ class B {
var b5: String by <!DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE!>getMyProperty2()<!>
}
fun getMyProperty2<A, B>() = MyProperty2<A, B>()
fun <A, B> getMyProperty2() = MyProperty2<A, B>()
class MyProperty2<T, R> {
@@ -8,7 +8,7 @@ class A1 {
var c1: String by getMyProperty1()
var d1: String by MyProperty1()
fun getMyProperty1<A, B>() = MyProperty1<A, B>()
fun <A, B> getMyProperty1() = MyProperty1<A, B>()
class MyProperty1<R, T> {
@@ -32,7 +32,7 @@ class A2 {
var c2: String by getMyProperty2()
var d2: String by MyProperty2()
fun getMyProperty2<A>() = MyProperty2<A>()
fun <A> getMyProperty2() = MyProperty2<A>()
class MyProperty2<T> {
@@ -56,7 +56,7 @@ class A3 {
var c3: String by getMyProperty3()
var d3: String by MyProperty3()
fun getMyProperty3<A>() = MyProperty3<A>()
fun <A> getMyProperty3() = MyProperty3<A>()
class MyProperty3<T> {
@@ -8,7 +8,7 @@ class A1 {
val c1: String by getMyProperty1()
val d1: String by MyProperty1()
fun getMyProperty1<A, B>() = MyProperty1<A, B>()
fun <A, B> getMyProperty1() = MyProperty1<A, B>()
class MyProperty1<R, T> {
@@ -28,7 +28,7 @@ class A2 {
val c2: String by getMyProperty2()
val d2: String by MyProperty2()
fun getMyProperty2<A>() = MyProperty2<A>()
fun <A> getMyProperty2() = MyProperty2<A>()
class MyProperty2<T> {
@@ -48,7 +48,7 @@ class A3 {
val c3: String by getMyProperty3()
val d3: String by MyProperty3()
fun getMyProperty3<A>() = MyProperty3<A>()
fun <A> getMyProperty3() = MyProperty3<A>()
class MyProperty3<T> {
@@ -7,5 +7,5 @@ class Delegate {
return 1
}
fun propertyDelegated<T>(p: PropertyMetadata) {}
fun <T> propertyDelegated(p: PropertyMetadata) {}
}
@@ -33,7 +33,7 @@ fun funcParamReceiver(param: <!DEPRECATED_SYMBOL_WITH_MESSAGE!>Obsolete<!>.()->U
fun funcParamParam(param: (<!DEPRECATED_SYMBOL_WITH_MESSAGE!>Obsolete<!>)->Unit) { param(<!DEPRECATED_SYMBOL_WITH_MESSAGE!>Obsolete<!>()) }
fun funcParamRetVal(param: ()-><!DEPRECATED_SYMBOL_WITH_MESSAGE!>Obsolete<!>) { param() }
fun constraint<T: <!DEPRECATED_SYMBOL_WITH_MESSAGE!>Obsolete<!>>() {}
fun <T: <!DEPRECATED_SYMBOL_WITH_MESSAGE!>Obsolete<!>> constraint() {}
fun <!DEPRECATED_SYMBOL_WITH_MESSAGE!>Obsolete<!>.receiver() {}
@@ -1,6 +1,6 @@
// !CHECK_TYPE
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
fun listOf<T>(): List<T> = null!!
fun <T> listOf(): List<T> = null!!
fun test(a: (Int) -> Int) {
test(fun (x) = 4)
@@ -5,8 +5,8 @@ interface A
interface B
interface C: A, B
fun foo<T>(<!UNUSED_PARAMETER!>a<!>: A, f: () -> T): T = f()
fun foo<T>(<!UNUSED_PARAMETER!>b<!>: B, f: () -> T): T = f()
fun <T> foo(<!UNUSED_PARAMETER!>a<!>: A, f: () -> T): T = f()
fun <T> foo(<!UNUSED_PARAMETER!>b<!>: B, f: () -> T): T = f()
fun test(c: C) {
<!CANNOT_COMPLETE_RESOLVE!>foo<!>(c) f@ {
@@ -8,4 +8,4 @@ fun main(args : Array<String>) {
fun <T : Any, R> T.let(f: (T) -> R): R = f(this)
operator fun <T> Iterable<T>.plus(<!UNUSED_PARAMETER!>element<!>: T): List<T> = null!!
fun listOf<T>(vararg <!UNUSED_PARAMETER!>values<!>: T): List<T> = null!!
fun <T> listOf(vararg <!UNUSED_PARAMETER!>values<!>: T): List<T> = null!!
@@ -15,4 +15,4 @@ fun test3() {
}
}
fun run<T>(f: () -> T): T { return f() }
fun <T> run(f: () -> T): T { return f() }
@@ -8,4 +8,4 @@ fun test2(a: Int) {
checkSubtype<Int>(x)
}
fun run<T>(f: () -> T): T { return f() }
fun <T> run(f: () -> T): T { return f() }
@@ -5,4 +5,4 @@ fun test2() {
checkSubtype<Int>(x)
}
fun run<T>(f: () -> T): T { return f() }
fun <T> run(f: () -> T): T { return f() }
@@ -11,4 +11,4 @@ fun test1() {
checkSubtype<Int>(x)
}
fun run<T>(f: () -> T): T { return f() }
fun <T> run(f: () -> T): T { return f() }
@@ -6,4 +6,4 @@ fun test() {
}
}
fun run1<T>(f: () -> T): T { return f() }
fun <T> run1(f: () -> T): T { return f() }
@@ -11,4 +11,4 @@ fun test() {
checkSubtype<Int>(x)
}
fun run<T>(f: () -> T): T { return f() }
fun <T> run(f: () -> T): T { return f() }
@@ -10,4 +10,4 @@ fun test() {
checkSubtype<Int>(x)
}
fun run<T>(f: () -> T): T { return f() }
fun <T> run(f: () -> T): T { return f() }
@@ -5,4 +5,4 @@ fun test(a: Int) {
}
}
fun run<T>(f: () -> T): T { return f() }
fun <T> run(f: () -> T): T { return f() }
@@ -8,4 +8,4 @@ fun test(a: Int) {
checkSubtype<Unit>(x)
}
fun run<T>(f: () -> T): T { return f() }
fun <T> run(f: () -> T): T { return f() }
@@ -1,5 +1,5 @@
val flag = true
fun run<T>(f: () -> T): T { return f() }
fun <T> run(f: () -> T): T { return f() }
// type of a was checked by txt
val a = run { // () -> Unit
@@ -1,5 +1,5 @@
fun listOf<T>(): List<T> = null!!
fun listOf<T>(vararg <!UNUSED_PARAMETER!>values<!>: T): List<T> = null!!
fun <T> listOf(): List<T> = null!!
fun <T> listOf(vararg <!UNUSED_PARAMETER!>values<!>: T): List<T> = null!!
val flag = true
@@ -8,4 +8,4 @@ fun test(a: Int) {
run<Int>{ 1 }
}
fun run<T>(f: () -> T): T { return f() }
fun <T> run(f: () -> T): T { return f() }
@@ -13,4 +13,4 @@ fun test(a: C, b: B) {
checkSubtype<A>(x)
}
fun run<T>(f: () -> T): T { return f() }
fun <T> run(f: () -> T): T { return f() }
@@ -1,6 +1,6 @@
fun <T, R> Iterable<T>.map(<!UNUSED_PARAMETER!>transform<!>: (T) -> R): List<R> = null!!
fun listOf<T>(): List<T> = null!!
fun listOf<T>(vararg <!UNUSED_PARAMETER!>values<!>: T): List<T> = null!!
fun <T> listOf(): List<T> = null!!
fun <T> listOf(vararg <!UNUSED_PARAMETER!>values<!>: T): List<T> = null!!
fun commonSystemFailed(a: List<Int>) {
a.map {
@@ -3,7 +3,7 @@ package d
interface A<T>
fun infer<T>(<!UNUSED_PARAMETER!>a<!>: A<T>) : T {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
fun <T> infer(<!UNUSED_PARAMETER!>a<!>: A<T>) : T {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
fun test(nothing: Nothing?) {
val <!UNUSED_VARIABLE!>i<!> = <!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>infer<!>(<!TYPE_MISMATCH!>nothing<!>)
@@ -20,7 +20,7 @@ fun test(expectedSum : Int, vararg data : Int) {
assertEquals(actualSum, expectedSum, "\ndata = ${Arrays.toString(data)}\n" +
"sum(data) = ${actualSum}, but must be $expectedSum ")
}
fun assertEquals<T: Any>(actual : T?, expected : T?, message : Any? = null) {
fun <T: Any> assertEquals(actual : T?, expected : T?, message : Any? = null) {
if (actual != expected) {
if (message == null)
throw AssertionError()
@@ -1,7 +1,7 @@
//!DIAGNOSTICS: -UNUSED_PARAMETER
fun foo<T>(i: Int, t: T) {}
fun foo<T>(s: String, t: T) {}
fun <T> foo(i: Int, t: T) {}
fun <T> foo(s: String, t: T) {}
fun bar(i: Int) {}
fun bar(s: String) {}
@@ -1,4 +1,4 @@
fun fooT22<T: Any>() : T? {
fun <T: Any> fooT22() : T? {
return null
}
@@ -1,8 +1,8 @@
package f
fun g<T>(<!UNUSED_PARAMETER!>i<!>: Int, <!UNUSED_PARAMETER!>a<!>: Any): List<T> {throw Exception()}
fun g<T>(<!UNUSED_PARAMETER!>a<!>: Any, <!UNUSED_PARAMETER!>i<!>: Int): Collection<T> {throw Exception()}
fun <T> g(<!UNUSED_PARAMETER!>i<!>: Int, <!UNUSED_PARAMETER!>a<!>: Any): List<T> {throw Exception()}
fun <T> g(<!UNUSED_PARAMETER!>a<!>: Any, <!UNUSED_PARAMETER!>i<!>: Int): Collection<T> {throw Exception()}
fun test<T>() {
fun <T> test() {
val <!UNUSED_VARIABLE!>c<!>: List<T> = <!CANNOT_COMPLETE_RESOLVE!>g<!>(1, 1)
}
@@ -1,6 +1,6 @@
package f
fun h<R>(<!UNUSED_PARAMETER!>i<!>: Int, <!UNUSED_PARAMETER!>a<!>: Any, <!UNUSED_PARAMETER!>r<!>: R, <!UNUSED_PARAMETER!>f<!>: (Boolean) -> Int) = 1
fun h<R>(<!UNUSED_PARAMETER!>a<!>: Any, <!UNUSED_PARAMETER!>i<!>: Int, <!UNUSED_PARAMETER!>r<!>: R, <!UNUSED_PARAMETER!>f<!>: (Boolean) -> Int) = 1
fun <R> h(<!UNUSED_PARAMETER!>i<!>: Int, <!UNUSED_PARAMETER!>a<!>: Any, <!UNUSED_PARAMETER!>r<!>: R, <!UNUSED_PARAMETER!>f<!>: (Boolean) -> Int) = 1
fun <R> h(<!UNUSED_PARAMETER!>a<!>: Any, <!UNUSED_PARAMETER!>i<!>: Int, <!UNUSED_PARAMETER!>r<!>: R, <!UNUSED_PARAMETER!>f<!>: (Boolean) -> Int) = 1
fun test() = <!CANNOT_COMPLETE_RESOLVE!>h<!>(1, 1, 1, { <!CANNOT_INFER_PARAMETER_TYPE!>b<!> -> 42 })
@@ -1,10 +1,10 @@
package f
fun f<T>(<!UNUSED_PARAMETER!>i<!>: Int, <!UNUSED_PARAMETER!>c<!>: Collection<T>): List<T> {throw Exception()}
fun f<T>(<!UNUSED_PARAMETER!>a<!>: Any, <!UNUSED_PARAMETER!>l<!>: List<T>): Collection<T> {throw Exception()}
fun <T> f(<!UNUSED_PARAMETER!>i<!>: Int, <!UNUSED_PARAMETER!>c<!>: Collection<T>): List<T> {throw Exception()}
fun <T> f(<!UNUSED_PARAMETER!>a<!>: Any, <!UNUSED_PARAMETER!>l<!>: List<T>): Collection<T> {throw Exception()}
fun test<T>(<!UNUSED_PARAMETER!>l<!>: List<T>) {
fun <T> test(<!UNUSED_PARAMETER!>l<!>: List<T>) {
<!CANNOT_COMPLETE_RESOLVE!>f<!>(1, <!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>emptyList<!>())
}
fun emptyList<T>(): List<T> {throw Exception()}
fun <T> emptyList(): List<T> {throw Exception()}
@@ -1,7 +1,7 @@
package f
fun f<T>(<!UNUSED_PARAMETER!>i<!>: Int, <!UNUSED_PARAMETER!>t<!>: T, <!UNUSED_PARAMETER!>c<!>: MutableCollection<T>) {}
fun f<T>(<!UNUSED_PARAMETER!>a<!>: Any, <!UNUSED_PARAMETER!>t<!>: T, <!UNUSED_PARAMETER!>l<!>: MutableList<T>) {}
fun <T> f(<!UNUSED_PARAMETER!>i<!>: Int, <!UNUSED_PARAMETER!>t<!>: T, <!UNUSED_PARAMETER!>c<!>: MutableCollection<T>) {}
fun <T> f(<!UNUSED_PARAMETER!>a<!>: Any, <!UNUSED_PARAMETER!>t<!>: T, <!UNUSED_PARAMETER!>l<!>: MutableList<T>) {}
fun test(l: List<Int>) {
<!NONE_APPLICABLE!>f<!>(1, "", l)
@@ -1,8 +1,8 @@
// !DIAGNOSTICS: -CONFLICTING_JVM_DECLARATIONS
package f
fun h<R>(<!UNUSED_PARAMETER!>f<!>: (Boolean) -> R) = 1
fun h<R>(<!UNUSED_PARAMETER!>f<!>: (String) -> R) = 2
fun <R> h(<!UNUSED_PARAMETER!>f<!>: (Boolean) -> R) = 1
fun <R> h(<!UNUSED_PARAMETER!>f<!>: (String) -> R) = 2
fun test() = <!CANNOT_COMPLETE_RESOLVE!>h<!>{ <!CANNOT_INFER_PARAMETER_TYPE!>i<!> -> getAnswer() }
@@ -4,7 +4,7 @@ class GenericClass<out T>
public fun <K, V> GenericClass<Map<K, V>>.foo() {}
public fun bar<T>(t: T, ext: GenericClass<T>.() -> Unit) {}
public fun <T> bar(t: T, ext: GenericClass<T>.() -> Unit) {}
fun test() {
bar(mapOf(2 to 3)) { foo() }
@@ -1,7 +1,7 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
class GenericClass<out T>(val value: T) {
public fun foo<P>(extension: T.() -> P) {}
public fun <P> foo(extension: T.() -> P) {}
}
public fun <E> GenericClass<List<E>>.bar() {
@@ -12,7 +12,7 @@ fun test() {
val <!UNUSED_VARIABLE!>u<!> = 11.<!TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS!>elemAndListWithReceiver<!>(4, list("7"))
}
fun list<T>(value: T) : ArrayList<T> {
fun <T> list(value: T) : ArrayList<T> {
val list = ArrayList<T>()
list.add(value)
return list
@@ -12,7 +12,7 @@ fun <R> elem(t: List<R>): R = t.get(0)
fun <R> elemAndList(<!UNUSED_PARAMETER!>r<!>: R, t: List<R>): R = t.get(0)
fun both<T>(t1: T, <!UNUSED_PARAMETER!>t2<!>: T) : T = t1
fun <T> both(t1: T, <!UNUSED_PARAMETER!>t2<!>: T) : T = t1
fun test1() {
val a = elem(list(2))
@@ -42,12 +42,12 @@ fun test1() {
checkSubtype<Any>(j)
}
fun list<T>(value: T) : ArrayList<T> {
fun <T> list(value: T) : ArrayList<T> {
val list = ArrayList<T>()
list.add(value)
return list
}
fun newList<S>() : ArrayList<S> {
fun <S> newList() : ArrayList<S> {
return ArrayList<S>()
}
@@ -4,7 +4,7 @@ package a
fun <T> emptyList(): List<T> = throw Exception()
fun foo<T>(f: T.() -> Unit, l: List<T>): T = throw Exception("$f$l")
fun <T> foo(f: T.() -> Unit, l: List<T>): T = throw Exception("$f$l")
fun test() {
val q = foo(fun Int.() {}, emptyList()) //type inference no information for parameter error
@@ -1,6 +1,6 @@
package n
fun foo<T>(<!UNUSED_PARAMETER!>t<!>: T, <!UNUSED_PARAMETER!>t1<!>: T) {}
fun <T> foo(<!UNUSED_PARAMETER!>t<!>: T, <!UNUSED_PARAMETER!>t1<!>: T) {}
fun test() {
//no type inference error
@@ -3,7 +3,7 @@ package n
//+JDK
import java.util.*
fun expected<T>(t: T, <!UNUSED_PARAMETER!>f<!>: () -> T) : T = t
fun <T> expected(t: T, <!UNUSED_PARAMETER!>f<!>: () -> T) : T = t
fun test(arrayList: ArrayList<Int>, list: List<Int>) {
val <!UNUSED_VARIABLE!>t<!> = expected(arrayList, { list.reverse() })
@@ -3,7 +3,7 @@ package n
//+JDK
import java.util.*
fun expected<T>(t: T, <!UNUSED_PARAMETER!>f<!>: () -> T) : T = t
fun <T> expected(t: T, <!UNUSED_PARAMETER!>f<!>: () -> T) : T = t
fun test(arrayList: ArrayList<Int>, list: List<Int>) {
val <!UNUSED_VARIABLE!>t<!> = expected(arrayList, l@ {return@l list.reverse() })
@@ -22,7 +22,7 @@ fun test() {
// ---------------------
// copy from kotlin util
fun arrayList<T>(vararg values: T) : ArrayList<T> = values.toCollection(ArrayList<T>(values.size()))
fun <T> arrayList(vararg values: T) : ArrayList<T> = values.toCollection(ArrayList<T>(values.size()))
fun <T, C: MutableCollection<in T>> Array<T>.toCollection(result: C) : C {
for (element in this) result.add(element)
@@ -1,4 +1,4 @@
fun foo<T>(t: T) = t
fun <T> foo(t: T) = t
fun test(map: MutableMap<Int, Int>, t: Int) {
map [t] = foo(t) // t was marked with black square
@@ -9,7 +9,7 @@ class B {
operator fun <T> invoke(<!UNUSED_PARAMETER!>f<!>: (T) -> T): MyFunc<T> = throw Exception()
}
fun id<R>(r: R) = r
fun <R> id(r: R) = r
fun foo(a: A) {
val <!UNUSED_VARIABLE!>r<!> : MyFunc<Int> = id (a.b { x -> x + 14 })
@@ -4,7 +4,7 @@ package aaa
fun <T> T.foo(t: T) = t
fun id<T>(t: T) = t
fun <T> id(t: T) = t
fun a() {
val i = id(2 foo 3)
@@ -3,7 +3,7 @@ package b
import java.util.ArrayList
public fun query<T>(<!UNUSED_PARAMETER!>t<!>: T, <!UNUSED_PARAMETER!>args<!>: Map<String, Any>): List<T> {
public fun <T> query(<!UNUSED_PARAMETER!>t<!>: T, <!UNUSED_PARAMETER!>args<!>: Map<String, Any>): List<T> {
return ArrayList<T>()
}
@@ -17,7 +17,7 @@ fun test(pair: Pair<String, Int>) {
//from standard library
fun mapOf<K, V>(vararg <!UNUSED_PARAMETER!>values<!>: Pair<K, V>): Map<K, V> { throw Exception() }
fun <K, V> mapOf(vararg <!UNUSED_PARAMETER!>values<!>: Pair<K, V>): Map<K, V> { throw Exception() }
fun <A,B> A.to(<!UNUSED_PARAMETER!>that<!>: B): Pair<A, B> { throw Exception() }
@@ -26,7 +26,7 @@ fun println(<!UNUSED_PARAMETER!>message<!> : Any?) { throw Exception() }
class Pair<out A, out B> () {}
//short example
fun foo<T>(t: T) = t
fun <T> foo(t: T) = t
fun test(t: String) {
@@ -9,6 +9,6 @@ fun test() {
val <!UNUSED_VARIABLE!>n1<!> : List<String> = newList()
}
fun newList<S>() : ArrayList<S> {
fun <S> newList() : ArrayList<S> {
return ArrayList<S>()
}
@@ -2,7 +2,7 @@ package a
import java.util.*
fun g<T> (<!UNUSED_PARAMETER!>f<!>: () -> List<T>) : T {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
fun <T> g (<!UNUSED_PARAMETER!>f<!>: () -> List<T>) : T {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
fun test() {
//here possibly can be a cycle on constraints
@@ -13,5 +13,5 @@ fun test() {
}
//from library
fun arrayList<T>(vararg <!UNUSED_PARAMETER!>values<!>: T) : ArrayList<T> {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
fun <T> arrayList(vararg <!UNUSED_PARAMETER!>values<!>: T) : ArrayList<T> {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
operator fun <T> Iterable<T>.plus(<!UNUSED_PARAMETER!>elements<!>: Iterable<T>): List<T> {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
@@ -5,7 +5,7 @@ import java.util.ArrayList
fun <T> foo(a : T, b : Collection<T>, c : Int) {
}
fun arrayListOf<T>(vararg values: T): ArrayList<T> = throw Exception("$values")
fun <T> arrayListOf(vararg values: T): ArrayList<T> = throw Exception("$values")
val bar = foo("", arrayListOf(),<!SYNTAX!><!> )
val bar2 = foo<String>("", arrayListOf(),<!SYNTAX!><!> )
@@ -25,7 +25,7 @@ fun test() {
//------------
fun arrayList<T>(vararg values: T) : ArrayList<T> = values.toCollection(ArrayList<T>(values.size()))
fun <T> arrayList(vararg values: T) : ArrayList<T> = values.toCollection(ArrayList<T>(values.size()))
fun <T, R> Collection<T>.map(transform : (T) -> R) : List<R> {
return mapTo(java.util.ArrayList<R>(this.size), transform)
@@ -3,7 +3,7 @@
//KT-2294 Type inference infers DONT_CARE instead of correct type
package a
public fun foo<E>(array: Array<E>): Array<E> = array
public fun <E> foo(array: Array<E>): Array<E> = array
public fun test()
{
@@ -27,7 +27,7 @@ fun testSomeFunction() {
fun assertEquals(<!UNUSED_PARAMETER!>expected<!>: Any?, <!UNUSED_PARAMETER!>actual<!>: Any?, <!UNUSED_PARAMETER!>message<!>: String = "") {
}
fun arrayList<T>(vararg values: T) : ArrayList<T> = values.toCollection(ArrayList<T>(values.size()))
fun <T> arrayList(vararg values: T) : ArrayList<T> = values.toCollection(ArrayList<T>(values.size()))
fun <T, C: MutableCollection<in T>> Array<T>.toCollection(result: C) : C {
for (element in this) result.add(element)
@@ -11,7 +11,7 @@ fun test() {
}
//from library
fun arrayList<T>(vararg <!UNUSED_PARAMETER!>values<!>: T) : ArrayList<T> {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
fun <T> arrayList(vararg <!UNUSED_PARAMETER!>values<!>: T) : ArrayList<T> {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
fun <T, R> Collection<T>.map(<!UNUSED_PARAMETER!>transform<!> : (T) -> R) : List<R> {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
@@ -8,4 +8,4 @@ fun main(args: Array<String>) {
}
}
fun test<R>(callback: (R) -> Unit):Unit = callback(null!!)
fun <R> test(callback: (R) -> Unit):Unit = callback(null!!)
@@ -7,4 +7,4 @@ class B<T>(val x: List<T>)
fun <T> f(x: T): B<T> = B(arrayList(x))
// from standard library
fun arrayList<T>(vararg <!UNUSED_PARAMETER!>values<!>: T) : ArrayList<T> {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
fun <T> arrayList(vararg <!UNUSED_PARAMETER!>values<!>: T) : ArrayList<T> {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
@@ -8,7 +8,7 @@ interface MyType {}
class MyClass<T> : MyType {}
public open class HttpResponse() {
public open fun parseAs<T>(dataClass : MyClass<T>) : T {
public open fun <T> parseAs(dataClass : MyClass<T>) : T {
throw Exception()
}
public open fun parseAs(dataType : MyType) : Any? {
@@ -16,7 +16,7 @@ public open class HttpResponse() {
}
}
fun test<R> (httpResponse: HttpResponse, rtype: MyClass<R>) {
fun <R> test (httpResponse: HttpResponse, rtype: MyClass<R>) {
val res = httpResponse.parseAs( rtype )
checkSubtype<R>(res) //type mismatch: required R, found T
}
@@ -10,7 +10,7 @@ interface D
class B : A, D
class C : A, D
fun hashSetOf<T>(vararg values: T): HashSet<T> = throw Exception("$values")
fun <T> hashSetOf(vararg values: T): HashSet<T> = throw Exception("$values")
fun foo(b: MyClass<B>, c: MyClass<C>) {
val set1 : Set<MyClass<out D>> = hashSetOf(b, c) //type inference expected type mismatch
@@ -2,7 +2,7 @@
package a
fun <T, R: Comparable<R>> Iterable<T>._sortBy(<!UNUSED_PARAMETER!>f<!>: (T) -> R): List<T> = throw Exception()
fun _arrayList<T>(vararg <!UNUSED_PARAMETER!>values<!>: T) : List<T> = throw Exception()
fun <T> _arrayList(vararg <!UNUSED_PARAMETER!>values<!>: T) : List<T> = throw Exception()
class _Pair<A>(val a: A)
@@ -2,8 +2,8 @@
//KT-2838 Type inference failed on passing null as a nullable argument
package a
fun foo<T>(a: T, b: Map<T, String>?) = b?.get(a)
fun bar<T>(a: T, b: Map<T, String>) = b.get(a)
fun <T> foo(a: T, b: Map<T, String>?) = b?.get(a)
fun <T> bar(a: T, b: Map<T, String>) = b.get(a)
fun test(a: Int) {
foo(a, null)

Some files were not shown because too many files have changed in this diff Show More