deprecating types after colon

This commit is contained in:
Dmitry Jemerov
2015-04-21 18:32:31 +02:00
parent b7a4b3c17d
commit f374eec8f1
268 changed files with 1055 additions and 769 deletions
@@ -569,7 +569,7 @@ public interface Errors {
DiagnosticFactory1<JetElement, JetType> CANNOT_CHECK_FOR_ERASED = DiagnosticFactory1.create(ERROR);
DiagnosticFactory2<JetBinaryExpressionWithTypeRHS, JetType, JetType> UNCHECKED_CAST = DiagnosticFactory2.create(WARNING);
DiagnosticFactory0<JetBinaryExpressionWithTypeRHS> USELESS_CAST_STATIC_ASSERT_IS_FINE = DiagnosticFactory0.create(WARNING, AS_TYPE);
DiagnosticFactory0<JetBinaryExpressionWithTypeRHS> DEPRECATED_STATIC_ASSERT = DiagnosticFactory0.create(WARNING, AS_TYPE);
DiagnosticFactory0<JetBinaryExpressionWithTypeRHS> USELESS_CAST = DiagnosticFactory0.create(WARNING, AS_TYPE);
DiagnosticFactory0<JetSimpleNameExpression> CAST_NEVER_SUCCEEDS = DiagnosticFactory0.create(WARNING);
DiagnosticFactory0<JetTypeReference> DYNAMIC_NOT_ALLOWED = DiagnosticFactory0.create(ERROR);
@@ -673,7 +673,7 @@ public interface Errors {
INVISIBLE_MEMBER, INVISIBLE_MEMBER_FROM_INLINE, INVISIBLE_REFERENCE, INVISIBLE_SETTER);
ImmutableSet<? extends DiagnosticFactory<?>> UNUSED_ELEMENT_DIAGNOSTICS = ImmutableSet.of(
UNUSED_VARIABLE, UNUSED_PARAMETER, ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE, VARIABLE_WITH_REDUNDANT_INITIALIZER,
UNUSED_FUNCTION_LITERAL, USELESS_CAST, USELESS_CAST_STATIC_ASSERT_IS_FINE);
UNUSED_FUNCTION_LITERAL, USELESS_CAST);
ImmutableSet<? extends DiagnosticFactory<?>> TYPE_INFERENCE_ERRORS = ImmutableSet.of(
TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER, TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS, TYPE_INFERENCE_TYPE_CONSTRUCTOR_MISMATCH,
TYPE_INFERENCE_UPPER_BOUND_VIOLATED, TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH);
@@ -291,7 +291,7 @@ public class DefaultErrorMessages {
MAP.put(ABSTRACT_SUPER_CALL, "Abstract member cannot be accessed directly");
MAP.put(NOT_A_SUPERTYPE, "Not a supertype");
MAP.put(TYPE_ARGUMENTS_REDUNDANT_IN_SUPER_QUALIFIER, "Type arguments do not need to be specified in a 'super' qualifier");
MAP.put(USELESS_CAST_STATIC_ASSERT_IS_FINE, "No cast needed. You can use ':' if you need a cast to a super type");
MAP.put(DEPRECATED_STATIC_ASSERT, "Static type assertions are deprecated, consider using a cast instead");
MAP.put(USELESS_CAST, "No cast needed");
MAP.put(CAST_NEVER_SUCCEEDS, "This cast can never succeed");
MAP.put(DYNAMIC_NOT_ALLOWED, "Dynamic types are not allowed in this position");
@@ -212,6 +212,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
JetSimpleNameExpression operationSign = expression.getOperationReference();
IElementType operationType = operationSign.getReferencedNameElementType();
if (operationType == JetTokens.COLON) {
context.trace.report(DEPRECATED_STATIC_ASSERT.on(expression));
return;
}
if (operationType != JetTokens.AS_KEYWORD && operationType != JetTokens.AS_SAFE) {
@@ -250,7 +251,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
expression.getLeft(), context.dataFlowInfo, actualType, context);
for (JetType possibleType : possibleTypes) {
if (typeChecker.isSubtypeOf(possibleType, targetType)) {
context.trace.report(USELESS_CAST_STATIC_ASSERT_IS_FINE.on(expression));
context.trace.report(USELESS_CAST.on(expression));
return;
}
}
+12 -10
View File
@@ -1,16 +1,18 @@
// !CHECK_TYPE
fun test() : Unit {
var x : Int? = 0
var y : Int = 0
x : Int?
y : Int
x as Int : Int
y <!USELESS_CAST!>as Int<!> : Int
x <!USELESS_CAST!>as Int?<!> : Int?
y <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as Int?<!> : Int?
x <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as? Int<!> : Int?
y <!USELESS_CAST!>as? Int<!> : Int?
x <!USELESS_CAST!>as? Int?<!> : Int?
y <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as? Int?<!> : Int?
checkSubtype<Int?>(x)
checkSubtype<Int>(y)
checkSubtype<Int>(x as Int)
checkSubtype<Int>(y <!USELESS_CAST!>as Int<!>)
checkSubtype<Int?>(x <!USELESS_CAST!>as Int?<!>)
checkSubtype<Int?>(y <!USELESS_CAST!>as Int?<!>)
checkSubtype<Int?>(x <!USELESS_CAST!>as? Int<!>)
checkSubtype<Int?>(y <!USELESS_CAST!>as? Int<!>)
checkSubtype<Int?>(x <!USELESS_CAST!>as? Int?<!>)
checkSubtype<Int?>(y <!USELESS_CAST!>as? Int?<!>)
Unit
}
@@ -1,3 +1,5 @@
// !CHECK_TYPE
fun varargByte(vararg v: Byte) = v
fun varargShort(vararg v: Short) = v
@@ -13,29 +15,29 @@ fun varargDouble(vararg v: Double) = v
fun <T> testFun(<!UNUSED_PARAMETER!>p<!>: T) {}
fun test() {
1: Byte
1: Short
1: Int
1: Long
checkSubtype<Byte>(1)
checkSubtype<Short>(1)
checkSubtype<Int>(1)
checkSubtype<Long>(1)
0x001: Long
0b001: Int
checkSubtype<Long>(0x001)
checkSubtype<Int>(0b001)
0.1: Double
0.1.toFloat(): Float
checkSubtype<Double>(0.1)
checkSubtype<Float>(0.1.toFloat())
1e5: Double
1e-5.toFloat(): Float
checkSubtype<Double>(1e5)
checkSubtype<Float>(1e-5.toFloat())
<!CONSTANT_EXPECTED_TYPE_MISMATCH!>1<!>: Double
<!CONSTANT_EXPECTED_TYPE_MISMATCH!>1<!>: Float
checkSubtype<Double>(<!CONSTANT_EXPECTED_TYPE_MISMATCH!>1<!>)
checkSubtype<Float>(<!CONSTANT_EXPECTED_TYPE_MISMATCH!>1<!>)
1 <!CAST_NEVER_SUCCEEDS!>as<!> Byte
1 <!USELESS_CAST!>as Int<!>
0xff <!CAST_NEVER_SUCCEEDS!>as<!> Long
1.1 <!CAST_NEVER_SUCCEEDS!>as<!> Int
<!CONSTANT_EXPECTED_TYPE_MISMATCH!>1.1<!>: Int
checkSubtype<Int>(<!CONSTANT_EXPECTED_TYPE_MISMATCH!>1.1<!>)
varargByte(0x77, 1, 3, <!CONSTANT_EXPECTED_TYPE_MISMATCH!>200<!>, 0b111)
varargShort(0x777, 1, 2, 3, <!CONSTANT_EXPECTED_TYPE_MISMATCH!>200000<!>, 0b111)
@@ -1,3 +1,5 @@
// !CHECK_TYPE
import java.util.*;
class NotRange1() {
@@ -87,5 +89,5 @@ fun test(notRange1: NotRange1, notRange2: NotRange2, notRange3: NotRange3, notRa
for (i in range0);
for (i in range1);
for (i in (ArrayList<Int>() : List<Int>));
for (i in (checkSubtype<List<Int>>(ArrayList<Int>())));
}
@@ -1,3 +1,5 @@
// !CHECK_TYPE
package foo
fun Any.foo() : () -> Unit {
@@ -38,10 +40,10 @@ fun main(args : Array<String>) {
foo2()({<!EXPECTED_PARAMETERS_NUMBER_MISMATCH, CANNOT_INFER_PARAMETER_TYPE!>x<!> -> })
val a = fooT1(1)()
a : Int
checkSubtype<Int>(a)
val b = fooT2<Int>()(1)
b : Int
checkSubtype<Int>(b)
<!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>fooT2<!>()(1) // : Any?
<!FUNCTION_EXPECTED!>1<!>()
@@ -1,8 +1,10 @@
// !CHECK_TYPE
// A generic funciton is always less specific than a non-generic one
fun foo<T>(<!UNUSED_PARAMETER!>t<!> : T) : Unit {}
fun foo(<!UNUSED_PARAMETER!>i<!> : Int) : Int = 1
fun test() {
foo(1) : Int
foo("s") : Unit
checkSubtype<Int>(foo(1))
checkSubtype<Unit>(foo("s"))
}
@@ -53,11 +53,9 @@ fun cannotBe() {
fun canBe(i0: Int, j: Int) {
var <!ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE!>i<!> = i0
(i: Int) = <!UNUSED_VALUE!>36<!>
(label@ i) = <!UNUSED_VALUE!>34<!>
(<!VAL_REASSIGNMENT!>j<!>: Int) = <!UNUSED_VALUE!>36<!>
(label@ j) = <!UNUSED_VALUE!>34<!> //repeat for j
(label@ <!VAL_REASSIGNMENT!>j<!>) = <!UNUSED_VALUE!>34<!> //repeat for j
val a = A()
(l@ a.a) = 3894
@@ -74,20 +72,16 @@ class A() {
class Test() {
fun testIllegalValues() {
<!VARIABLE_EXPECTED!>1<!> += 23
(<!VARIABLE_EXPECTED!>1<!> : Int) += 43
(l@ <!VARIABLE_EXPECTED!>1<!>) += 23
<!VARIABLE_EXPECTED!>getInt()<!> += 343
(f@ <!VARIABLE_EXPECTED!>getInt()<!>) += 343
(<!VARIABLE_EXPECTED!>getInt()<!> : Int) += 343
<!VARIABLE_EXPECTED!>1<!>++
(r@ <!VARIABLE_EXPECTED!>1<!>)++
(<!VARIABLE_EXPECTED!>1<!> : Int)++
<!VARIABLE_EXPECTED!>getInt()<!>++
(m@ <!VARIABLE_EXPECTED!>getInt()<!>)++
(<!VARIABLE_EXPECTED!>getInt()<!> : Int)++
this<!UNRESOLVED_REFERENCE!>++<!>
@@ -103,13 +97,11 @@ class Test() {
a += 34
(l@ a) += 34
(a : Int) += 34
<!VAL_REASSIGNMENT!>b<!> += 34
a++
(l@ a)++
(a : Int)++
<!UNUSED_CHANGED_VALUE!>(a)++<!>
}
@@ -118,7 +110,6 @@ class Test() {
(l@ <!VAL_REASSIGNMENT!>b<!>) += 34
//repeat for b
(b : Int) += 34
(b) += 3
}
@@ -131,8 +122,6 @@ class Test() {
ab.getArray()[54]++
(f@ a)[3] = 4
(a : Array<Int>)[4]++
(ab.getArray() : Array<Int>)[54] += 43
this<!NO_SET_METHOD!><!UNRESOLVED_REFERENCE!>[<!>54<!UNRESOLVED_REFERENCE!>]<!><!> = 34
}
@@ -1,3 +1,5 @@
// !CHECK_TYPE
// FILE: f.kt
import java.*
@@ -24,7 +26,7 @@ fun test(<!UNUSED_PARAMETER!>l<!> : <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>java.util
Collections.emptyList<Int>()
Collections.<!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>emptyList<!>()
Collections.singleton<Int>(1) : Set<Int>?
checkSubtype<Set<Int>?>(Collections.singleton<Int>(1))
Collections.singleton<Int>(<!CONSTANT_EXPECTED_TYPE_MISMATCH!>1.0<!>)
<!UNRESOLVED_REFERENCE!>List<!><Int>
@@ -43,7 +45,7 @@ fun test(<!UNUSED_PARAMETER!>l<!> : <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>java.util
val c : <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>Com<Int><!>? = null
c : <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>java.lang.Comparable<Int><!>?
checkSubtype<<!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>java.lang.Comparable<Int><!>?>(c)
// Collections.sort<Integer>(ArrayList<Integer>())
xxx.<!UNRESOLVED_REFERENCE!>Class<!>()
@@ -1,3 +1,5 @@
// !CHECK_TYPE
fun test() {
return Unit : Unit
return checkSubtype<Unit>(Unit)
}
@@ -3,7 +3,7 @@ fun foo(<!UNRESOLVED_REFERENCE!>varargs<!> <!UNUSED_PARAMETER!>f<!> : Int) {}
var bar : Int = 1
set(<!UNRESOLVED_REFERENCE!>varargs<!> v) {}
val x : (Int) -> Int = {[<!UNRESOLVED_REFERENCE!>varargs<!>] <!TYPE_MISMATCH!>x<!> : Int <!SYNTAX!>-> x<!>}
val x : (Int) -> Int = {[<!UNRESOLVED_REFERENCE!>varargs<!>] <!TYPE_MISMATCH!>x<!> <!DEPRECATED_STATIC_ASSERT!>: Int<!> <!SYNTAX!>-> x<!>}
class Hello(<!UNRESOLVED_REFERENCE!>varargs<!> <!UNUSED_PARAMETER!>args<!>: Any) {
}
@@ -5,7 +5,7 @@ fun foo(test <!UNUSED_PARAMETER!>f<!> : Int) {}
var bar : Int = 1
set(test v) {}
val x : (Int) -> Int = {[test] <!TYPE_MISMATCH!>x<!> : Int <!SYNTAX!>-> x<!>} // todo fix parser annotation on lambda parameter
val x : (Int) -> Int = {[test] <!TYPE_MISMATCH!>x<!> <!DEPRECATED_STATIC_ASSERT!>: Int<!> <!SYNTAX!>-> x<!>} // todo fix parser annotation on lambda parameter
class Hello(test <!UNUSED_PARAMETER!>args<!>: Any) {
}
@@ -1,8 +1,10 @@
// !CHECK_TYPE
trait Tr<T>
trait G<T> : Tr<T>
fun test(tr: Tr<String>) {
val v = tr as G?
// If v is not nullable, there will be a warning on this line:
v!!: G<String>
checkSubtype<G<String>>(v!!)
}
@@ -1,8 +1,10 @@
// !CHECK_TYPE
trait Tr
trait G<T>
fun test(tr: Tr) {
val v = tr as <!NO_TYPE_ARGUMENTS_ON_RHS!>G?<!>
// If v is not nullable, there will be a warning on this line:
v!!: G<*>
checkSubtype<G<*>>(v!!)
}
@@ -1,3 +1,5 @@
// !CHECK_TYPE
trait Either<out A, out B>
trait Left<out A>: Either<A, Nothing>
trait Right<out B>: Either<Nothing, B>
@@ -7,10 +9,10 @@ class C2(val v2: Int)
fun _as_left(e: Either<C1, C2>): Any {
val v = e as Left
return v: Left<C1>
return checkSubtype<Left<C1>>(v)
}
fun _as_right(e: Either<C1, C2>): Any {
val v = e as Right
return v: Right<C2>
return checkSubtype<Right<C2>>(v)
}
@@ -1,3 +1,5 @@
// !CHECK_TYPE
trait Either<out A, out B>
trait Left<out A>: Either<A, Nothing>
trait Right<out B>: Either<Nothing, B>
@@ -7,10 +9,10 @@ class C2(val v2: Int)
fun _as_left(e: Either<C1, C2>): Any? {
val v = e as? Left
return v: Left<C1>?
return checkSubtype<Left<C1>?>(v)
}
fun _as_right(e: Either<C1, C2>): Any? {
val v = e as? Right
return v: Right<C2>?
return checkSubtype<Right<C2>?>(v)
}
@@ -1,7 +1,9 @@
// !CHECK_TYPE
trait B<T>
trait G<T>: B<T>
fun f(p: B<<!UNRESOLVED_REFERENCE!>Foo<!>>): Any {
val v = <!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>p<!> as G
return <!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>v<!>: G<*>
return checkSubtype<G<*>>(<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>v<!>)
}
@@ -1,6 +1,8 @@
// !CHECK_TYPE
class G<T>
fun foo(p: <!UNRESOLVED_REFERENCE!>P<!>) {
val v = <!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>p<!> <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as <!NO_TYPE_ARGUMENTS_ON_RHS!>G?<!><!>
v!!: G<*>
val v = <!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>p<!> <!USELESS_CAST!>as <!NO_TYPE_ARGUMENTS_ON_RHS!>G?<!><!>
checkSubtype<G<*>>(v!!)
}
@@ -1,7 +1,9 @@
// !CHECK_TYPE
trait Tr<T>
trait G<T> : Tr<T>
fun test(tr: Tr<String>?) {
val v = tr as G
v: G<String>
checkSubtype<G<String>>(v)
}
@@ -1,7 +1,9 @@
// !CHECK_TYPE
trait Tr
trait G<T>
fun test(tr: Tr?) {
val v = tr as <!NO_TYPE_ARGUMENTS_ON_RHS!>G<!>
v: G<*>
checkSubtype<G<*>>(v)
}
@@ -1,8 +1,10 @@
// !CHECK_TYPE
trait Tr<T>
trait G<T> : Tr<T>
fun test(tr: Tr<String>?) {
val v = tr as G?
// If v is not nullable, there will be a warning on this line:
v!!: G<String>
checkSubtype<G<String>>(v!!)
}
@@ -1,7 +1,9 @@
// !CHECK_TYPE
trait Tr
trait G<T>
fun test(tr: Tr?) {
val v = tr as <!NO_TYPE_ARGUMENTS_ON_RHS!>G?<!>
v!!: G<*>
checkSubtype<G<*>>(v!!)
}
@@ -1,7 +1,9 @@
// !CHECK_TYPE
trait Tr
trait G<T>
fun test(tr: Tr) {
val v = tr as <!NO_TYPE_ARGUMENTS_ON_RHS!>G<!>
v: G<*>
checkSubtype<G<*>>(v)
}
@@ -1,4 +1,6 @@
// !CHECK_TYPE
trait Tr
trait G<T>
fun test(tr: Tr) = tr: <!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>G<!>
fun test(tr: Tr) = checkSubtype<<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>G<!>>(tr)
@@ -1,3 +1,5 @@
// !CHECK_TYPE
fun <T> array1(vararg a : T) = a
fun main(args : Array<String>) {
@@ -52,23 +54,23 @@ fun main(args : Array<String>) {
joinG(a = *a, x = 1)
val x1 = joinT(1, "2")
x1 : String?
checkSubtype<String?>(x1)
val x2 = joinT(<!NON_VARARG_SPREAD!>*<!>1, "2")
x2 : String?
checkSubtype<String?>(x2)
val x6 = joinT(1, *a)
x6 : String?
checkSubtype<String?>(x6)
val x7 = joinT(1, *a, "3")
x7 : String?
checkSubtype<String?>(x7)
val x8 = joinT(1, "4", *a, "3")
x8 : String?
checkSubtype<String?>(x8)
val x9 = joinT(1, "4", *a)
x9 : String?
checkSubtype<String?>(x9)
val x10 = joinT(1, "4", *a, *a, "3")
x10 : String?
checkSubtype<String?>(x10)
val x11 = joinT(a = *a, x = 1)
x11 : String?
checkSubtype<String?>(x11)
val x12 = joinT(x = 1, a = *a)
x12 : String?
checkSubtype<String?>(x12)
}
fun join(x : Int, vararg a : String) : String {
@@ -5,7 +5,7 @@ trait B : A
trait C : B
fun test(b: B) {
b checkType { it : _<B> }
b checkType { <!TYPE_MISMATCH!>it<!> : _<A> }
b checkType { <!TYPE_MISMATCH!>it<!> : _<C> }
b checkType { _<B>() }
b checkType { <!TYPE_MISMATCH!>_<!><A>() }
b checkType { <!TYPE_MISMATCH!>_<!><C>() }
}
@@ -15,7 +15,6 @@ fun bar() {
val x = X
x.foo()
X.foo()
(X : C).foo()
(X <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as C<!>).foo()
((if (1<2) X else Y) : C).foo()
(X <!USELESS_CAST!>as C<!>).foo()
((if (1<2) X else Y) <!USELESS_CAST!>as C<!>).foo()
}
@@ -11,10 +11,10 @@ fun <T: Any> exclExcl(t: T?): T = t!!
fun test11() {
// not 'String!'
exclExcl(A.foo()) checkType { it : _<String> }
exclExcl(A.foo()) checkType { <!TYPE_MISMATCH!>it<!> : _<String?> }
exclExcl(A.foo()) checkType { _<String>() }
exclExcl(A.foo()) checkType { <!TYPE_MISMATCH!>_<!><String?>() }
// not 'String!'
A.foo()!! checkType { it : _<String> }
A.foo()!! checkType { <!TYPE_MISMATCH!>it<!> : _<String?> }
A.foo()!! checkType { _<String>() }
A.foo()!! checkType { <!TYPE_MISMATCH!>_<!><String?>() }
}
@@ -1,3 +1,5 @@
// !CHECK_TYPE
open data class A(private val x: Int)
class B : A(1) {
@@ -6,6 +8,6 @@ class B : A(1) {
fun foo() {
val b = B()
b.component1() : String
(b : A).<!INVISIBLE_MEMBER!>component1<!>() : Int
checkSubtype<String>(b.component1())
checkSubtype<Int>((checkSubtype<A>(b)).<!INVISIBLE_MEMBER!>component1<!>())
}
@@ -1,6 +1,8 @@
// !CHECK_TYPE
data class A(val x: Int, <!UNUSED_PARAMETER!>y<!>: String)
fun foo(a: A) {
a.component1() : Int
checkSubtype<Int>(a.component1())
a.<!UNRESOLVED_REFERENCE!>component2<!>()
}
@@ -1,6 +1,8 @@
// !CHECK_TYPE
data class A(var x: Int, <!UNUSED_PARAMETER!>y<!>: String)
fun foo(a: A) {
a.component1() : Int
checkSubtype<Int>(a.component1())
a.<!UNRESOLVED_REFERENCE!>component2<!>()
}
@@ -1,7 +1,9 @@
// !CHECK_TYPE
data class A(val x: Int, val y: String)
fun foo(a: A) {
val (b, c) = a
b : Int
c : String
checkSubtype<Int>(b)
checkSubtype<String>(c)
}
@@ -1,8 +1,10 @@
// !CHECK_TYPE
data class A(val x: Int, val y: String)
fun foo(arr: Array<A>) {
for ((b, c) in arr) {
b : Int
c : String
checkSubtype<Int>(b)
checkSubtype<String>(c)
}
}
@@ -1,6 +1,8 @@
// !CHECK_TYPE
data class A(val x: Int)
fun foo(a: A) {
a.component1() : Int
checkSubtype<Int>(a.component1())
a.<!UNRESOLVED_REFERENCE!>component2<!>()
}
@@ -1,6 +1,8 @@
// !CHECK_TYPE
data class A(<!UNUSED_PARAMETER!>x<!>: Int, val y: String)
fun foo(a: A) {
a.component1() : String
checkSubtype<String>(a.component1())
a.<!UNRESOLVED_REFERENCE!>component2<!>()
}
@@ -1,6 +1,8 @@
// !CHECK_TYPE
data class A(<!UNUSED_PARAMETER!>x<!>: Int, var y: String)
fun foo(a: A) {
a.component1() : String
checkSubtype<String>(a.component1())
a.<!UNRESOLVED_REFERENCE!>component2<!>()
}
@@ -1,6 +1,8 @@
// !CHECK_TYPE
data class A(val x: Int, val y: String)
fun foo(a: A) {
a.component1() : Int
a.component2() : String
checkSubtype<Int>(a.component1())
checkSubtype<String>(a.component2())
}
@@ -1,6 +1,8 @@
// !CHECK_TYPE
data class A(var x: Int, var y: String)
fun foo(a: A) {
a.component1() : Int
a.component2() : String
checkSubtype<Int>(a.component1())
checkSubtype<String>(a.component2())
}
@@ -1,18 +1,20 @@
// !CHECK_TYPE
fun f1(s: String?) {
if (s!! == "");
<!DEBUG_INFO_SMARTCAST!>s<!> : String
checkSubtype<String>(<!DEBUG_INFO_SMARTCAST!>s<!>)
}
fun f2(s: Number?) {
if (s is Int);
<!TYPE_MISMATCH!>s<!> : Int
checkSubtype<Int>(<!TYPE_MISMATCH!>s<!>)
if (s as Int == 42);
<!DEBUG_INFO_SMARTCAST!>s<!> : Int
checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>s<!>)
}
fun f3(s: Number?) {
if (s is Int && s <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as Int<!> == 42);
<!TYPE_MISMATCH!>s<!> : Int
if (s is Int && s <!USELESS_CAST!>as Int<!> == 42);
checkSubtype<Int>(<!TYPE_MISMATCH!>s<!>)
}
fun f4(s: Int?) {
@@ -2,7 +2,7 @@
fun foo(o: Any) {
if (o is String) {
val s = o <!USELESS_CAST_STATIC_ASSERT_IS_FINE!>as String<!>
val s = o <!USELESS_CAST!>as String<!>
s.length()
}
}
@@ -1,5 +1,7 @@
// !CHECK_TYPE
fun foo(arr: Array<out Number>): Int {
val result = (arr as Array<Int>)[0]
<!DEBUG_INFO_SMARTCAST!>arr<!> : Array<Int>
checkSubtype<Array<Int>>(<!DEBUG_INFO_SMARTCAST!>arr<!>)
return result
}
@@ -1,3 +1,5 @@
// !CHECK_TYPE
trait G {
fun get(x: Int, y: Int): Int = x + y
fun set(x: Int, y: Int, value: Int) {}
@@ -5,22 +7,22 @@ trait G {
fun foo1(a: Int?, b: G) {
b[a!!, a<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>] = <!DEBUG_INFO_SMARTCAST!>a<!>
<!DEBUG_INFO_SMARTCAST!>a<!> : Int
checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>a<!>)
}
fun foo2(a: Int?, b: G) {
b[0, a!!] = <!DEBUG_INFO_SMARTCAST!>a<!>
<!DEBUG_INFO_SMARTCAST!>a<!> : Int
checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>a<!>)
}
fun foo3(a: Int?, b: G) {
val r = b[a!!, <!DEBUG_INFO_SMARTCAST!>a<!>]
<!DEBUG_INFO_SMARTCAST!>a<!> : Int
r : Int
checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>a<!>)
checkSubtype<Int>(r)
}
fun foo4(a: Int?, b: G) {
val r = b[0, a!!]
<!DEBUG_INFO_SMARTCAST!>a<!> : Int
r : Int
checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>a<!>)
checkSubtype<Int>(r)
}
@@ -1,9 +1,11 @@
// !CHECK_TYPE
fun foo1(a: Int?, b: Array<Array<Int>>) {
b[a!!][a<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>] = <!DEBUG_INFO_SMARTCAST!>a<!>
<!DEBUG_INFO_SMARTCAST!>a<!> : Int
checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>a<!>)
}
fun foo2(a: Int?, b: Array<Array<Int>>) {
b[0][a!!] = <!DEBUG_INFO_SMARTCAST!>a<!>
<!DEBUG_INFO_SMARTCAST!>a<!> : Int
checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>a<!>)
}
@@ -1,15 +1,17 @@
// !CHECK_TYPE
fun bar1(x: Number, y: Int) {
var yy = y
yy += x as Int
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>x<!>)
}
fun bar2(x: Number) {
<!UNRESOLVED_REFERENCE!>y<!> <!UNRESOLVED_REFERENCE!>+=<!> x as Int
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>x<!>)
}
fun bar3(x: Number, y: Array<Int>) {
y[0] += x as Int
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>x<!>)
}
@@ -1,10 +1,12 @@
// !CHECK_TYPE
fun arrayAccessRHS(a: Int?, b: Array<Int>) {
b[0] = a!!
<!DEBUG_INFO_SMARTCAST!>a<!> : Int
checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>a<!>)
}
fun arrayAccessLHS(a: Int?, b: Array<Int>) {
b[a!!] = <!DEBUG_INFO_SMARTCAST!>a<!>
<!DEBUG_INFO_SMARTCAST!>a<!> : Int
checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>a<!>)
}
@@ -1,23 +1,25 @@
// !CHECK_TYPE
fun foo1(x: Number, cond: Boolean): Boolean {
val result = cond && ((x as Int) == 42)
<!TYPE_MISMATCH!>x<!> : Int
checkSubtype<Int>(<!TYPE_MISMATCH!>x<!>)
return result
}
fun foo2(x: Number, cond: Boolean): Boolean {
val result = ((x as Int) == 42) && cond
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>x<!>)
return result
}
fun foo3(x: Number, cond: Boolean): Boolean {
val result = cond || ((x as Int) == 42)
<!TYPE_MISMATCH!>x<!> : Int
checkSubtype<Int>(<!TYPE_MISMATCH!>x<!>)
return result
}
fun foo4(x: Number, cond: Boolean): Boolean {
val result = ((x as Int) == 42) || cond
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>x<!>)
return result
}
@@ -1,3 +1,5 @@
// !CHECK_TYPE
trait A
trait B : A
@@ -5,12 +7,12 @@ fun B.compareTo(b: B) = if (this == b) 0 else 1
fun foo(a: A): Boolean {
val result = (a as B) < <!DEBUG_INFO_SMARTCAST!>a<!>
<!DEBUG_INFO_SMARTCAST!>a<!> : B
checkSubtype<B>(<!DEBUG_INFO_SMARTCAST!>a<!>)
return result
}
fun bar(a: A, b: B): Boolean {
val result = b < (a as B)
<!DEBUG_INFO_SMARTCAST!>a<!> : B
checkSubtype<B>(<!DEBUG_INFO_SMARTCAST!>a<!>)
return result
}
@@ -1,5 +1,7 @@
// !CHECK_TYPE
fun foo(x: Number): Boolean {
val result = (x as Int) in 1..5
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>x<!>)
return result
}
@@ -1,14 +1,16 @@
// !CHECK_TYPE
fun foo(x: Int?): Int = x!!
fun elvis(x: Number?): Int {
val result = (x as Int?) ?: foo(<!DEBUG_INFO_SMARTCAST!>x<!>)
<!DEBUG_INFO_SMARTCAST!>x<!> : Int?
checkSubtype<Int?>(<!DEBUG_INFO_SMARTCAST!>x<!>)
return result
}
fun elvisWithRHSTypeInfo(x: Number?): Any? {
val result = x ?: x!!
<!TYPE_MISMATCH!>x<!> : Int?
checkSubtype<Int?>(<!TYPE_MISMATCH!>x<!>)
return result
}
@@ -1,14 +1,16 @@
// !CHECK_TYPE
trait A
trait B : A
fun foo1(a: A, b: B): Boolean {
val result = (a as B) == b
<!DEBUG_INFO_SMARTCAST!>a<!> : B
checkSubtype<B>(<!DEBUG_INFO_SMARTCAST!>a<!>)
return result
}
fun foo2(a: A, b: B): Boolean {
val result = b == (a as B)
<!DEBUG_INFO_SMARTCAST!>a<!> : B
checkSubtype<B>(<!DEBUG_INFO_SMARTCAST!>a<!>)
return result
}
@@ -1,11 +1,13 @@
// !CHECK_TYPE
fun foo(a: Number): Int {
val result = (a as Int) compareTo <!DEBUG_INFO_SMARTCAST!>a<!>
<!DEBUG_INFO_SMARTCAST!>a<!> : Int
checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>a<!>)
return result
}
fun bar(a: Number): Int {
val result = 42 compareTo (a as Int)
<!DEBUG_INFO_SMARTCAST!>a<!> : Int
checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>a<!>)
return result
}
@@ -1,3 +1,5 @@
// !CHECK_TYPE
trait A
trait B : A
@@ -5,12 +7,12 @@ fun B.plus(b: B) = if (this == b) b else this
fun foo(a: A): B {
val result = (a as B) + <!DEBUG_INFO_SMARTCAST!>a<!>
<!DEBUG_INFO_SMARTCAST!>a<!> : B
checkSubtype<B>(<!DEBUG_INFO_SMARTCAST!>a<!>)
return result
}
fun bar(a: A, b: B): B {
val result = b + (a as B)
<!DEBUG_INFO_SMARTCAST!>a<!> : B
checkSubtype<B>(<!DEBUG_INFO_SMARTCAST!>a<!>)
return result
}
@@ -1,5 +1,7 @@
// !CHECK_TYPE
fun foo(x: Int?): Boolean {
val result = ((x!! == 0) && ((<!DEBUG_INFO_SMARTCAST!>x<!> : Int) == 0))
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
val result = ((x!! == 0) && (checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>x<!>) == 0))
checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>x<!>)
return result
}
@@ -1,11 +1,13 @@
// !CHECK_TYPE
fun whileLoop(x: Int?) {
outer@ while (x != 0) {
while (x != 1) {
if (x == 2) continue@outer
}
<!TYPE_MISMATCH!>x<!> : Int
checkSubtype<Int>(<!TYPE_MISMATCH!>x<!>)
}
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>x<!>)
}
fun doWhileLoop(x: Int?) {
@@ -13,9 +15,9 @@ fun doWhileLoop(x: Int?) {
do {
if (x == 2) continue@outer
} while (x == null)
<!TYPE_MISMATCH!>x<!> : Int
checkSubtype<Int>(<!TYPE_MISMATCH!>x<!>)
}
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>x<!>)
}
fun whileLoopContinueInnerOuter(x: Int?) {
@@ -24,9 +26,9 @@ fun whileLoopContinueInnerOuter(x: Int?) {
while (x != 2) {
if (x == 3) continue@inner
}
<!TYPE_MISMATCH!>x<!> : Int
checkSubtype<Int>(<!TYPE_MISMATCH!>x<!>)
}
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>x<!>)
}
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>x<!>)
}
@@ -1,18 +1,20 @@
// !CHECK_TYPE
fun simpleDoWhile(x: Int?, y0: Int) {
var y = y0
do {
x : Int?
checkSubtype<Int?>(x)
y++
} while (x!! == y)
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>x<!>)
}
fun doWhileWithBreak(x: Int?, y0: Int) {
var y = y0
do {
x : Int?
checkSubtype<Int?>(x)
y++
if (y > 0) break
} while (x!! == y)
<!TYPE_MISMATCH!>x<!> : Int
checkSubtype<Int>(<!TYPE_MISMATCH!>x<!>)
}
@@ -1,6 +1,8 @@
// !CHECK_TYPE
fun foo(arr: Array<Int>?) {
for (x in arr!!) {
<!DEBUG_INFO_SMARTCAST!>arr<!> : Array<Int>
checkSubtype<Array<Int>>(<!DEBUG_INFO_SMARTCAST!>arr<!>)
}
<!DEBUG_INFO_SMARTCAST!>arr<!> : Array<Int>
checkSubtype<Array<Int>>(<!DEBUG_INFO_SMARTCAST!>arr<!>)
}
@@ -1,29 +1,31 @@
// !CHECK_TYPE
fun ifThen(x: Int?) {
if (x!! == 0) {
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>x<!>)
}
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>x<!>)
}
fun ifElse(x: Int?) {
if (x!! == 0) else {
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>x<!>)
}
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>x<!>)
}
fun ifThenElse(x: Int?) {
if (x!! == 0) {
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>x<!>)
} else {
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>x<!>)
}
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>x<!>)
}
fun ifIs(x: Int?, cond: Boolean) {
if ((x is Int) == cond) {
<!TYPE_MISMATCH!>x<!> : Int
checkSubtype<Int>(<!TYPE_MISMATCH!>x<!>)
}
<!TYPE_MISMATCH!>x<!> : Int
checkSubtype<Int>(<!TYPE_MISMATCH!>x<!>)
}
@@ -1,6 +1,8 @@
// !CHECK_TYPE
fun foo(x: Number) {
if ((x as Int) is Int) {
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>x<!>)
}
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>x<!>)
}
@@ -1,3 +1,5 @@
// !CHECK_TYPE
fun noUselessDataFlowInfoCreation(x: Number) {
if (x is Int) { if (x is Int) { if (x is Int) { if (x is Int) { if (x is Int) {
if (x is Int) { if (x is Int) { if (x is Int) { if (x is Int) { if (x is Int) {
@@ -14,7 +16,7 @@ fun dataFlowInfoAnd(a: Array<Number>) {
if (a[15] is Int) { if (a[16] is Int) { if (a[17] is Int) { if (a[18] is Int) { if (a[19] is Int) {
if (a[20] is Int) { if (a[21] is Int) { if (a[22] is Int) { if (a[23] is Int) { if (a[24] is Int) {
if (a[25] is Int) { if (a[26] is Int) { if (a[27] is Int) { if (a[28] is Int) { if (a[29] is Int) {
<!TYPE_MISMATCH!>a[0]<!> : Int
checkSubtype<Int>(<!TYPE_MISMATCH!>a[0]<!>)
} } } } } } } } } } } } } } } } } } } } } } } } } } } } } }
}
@@ -25,6 +27,6 @@ fun dataFlowInfoOr(a: Array<Number>) {
a[30] is Int || a[31] is Int || a[32] is Int || a[33] is Int || a[34] is Int || a[35] is Int || a[36] is Int || a[37] is Int || a[38] is Int || a[39] is Int ||
a[40] is Int || a[41] is Int || a[42] is Int || a[43] is Int || a[44] is Int || a[45] is Int || a[46] is Int || a[47] is Int || a[48] is Int || a[49] is Int ||
a[50] is Int || a[51] is Int || a[52] is Int || a[53] is Int || a[54] is Int || a[55] is Int || a[56] is Int || a[57] is Int || a[58] is Int || a[59] is Int) {
<!TYPE_MISMATCH!>a[0]<!> : Int
checkSubtype<Int>(<!TYPE_MISMATCH!>a[0]<!>)
}
}
@@ -1,7 +1,9 @@
// !CHECK_TYPE
fun Int.component1() = "a"
fun foo(a: Number) {
val (x) = a as Int
<!DEBUG_INFO_SMARTCAST!>a<!> : Int
x : String
checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>a<!>)
checkSubtype<String>(x)
}
@@ -1,6 +1,8 @@
// !CHECK_TYPE
fun foo(x: Number, y: String?): String {
val result = "abcde $x ${x as Int} ${y!!} $x $y"
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
<!DEBUG_INFO_SMARTCAST!>y<!> : String
checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>x<!>)
checkSubtype<String>(<!DEBUG_INFO_SMARTCAST!>y<!>)
return result
}
@@ -1,9 +1,11 @@
// !CHECK_TYPE
fun tryFinally(x: Int?) {
try {
} finally {
x!!
}
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>x<!>)
}
fun tryCatchFinally(x: Int?) {
@@ -12,8 +14,8 @@ fun tryCatchFinally(x: Int?) {
} catch (e: Exception) {
x!!
} finally {
<!TYPE_MISMATCH!>x<!> : Int
checkSubtype<Int>(<!TYPE_MISMATCH!>x<!>)
x!!
}
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>x<!>)
}
@@ -1,24 +1,26 @@
// !CHECK_TYPE
fun foo(x: Number, y: Int) {
when (x) {
x as Int -> <!DEBUG_INFO_SMARTCAST!>x<!> : Int
x as Int -> checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>x<!>)
y -> {}
else -> {}
}
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>x<!>)
}
fun bar(x: Number) {
when (x) {
x as Int -> <!DEBUG_INFO_SMARTCAST!>x<!> : Int
x as Int -> checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>x<!>)
else -> {}
}
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>x<!>)
}
fun whenWithoutSubject(x: Number) {
when {
(x as Int) == 42 -> <!DEBUG_INFO_SMARTCAST!>x<!> : Int
(x as Int) == 42 -> checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>x<!>)
else -> {}
}
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>x<!>)
}
@@ -1,24 +1,26 @@
// !CHECK_TYPE
fun foo(x: Number, y: Int) {
when (x) {
is Int -> <!DEBUG_INFO_SMARTCAST!>x<!> : Int
is Int -> checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>x<!>)
y -> {}
else -> {}
}
<!TYPE_MISMATCH!>x<!> : Int
checkSubtype<Int>(<!TYPE_MISMATCH!>x<!>)
}
fun bar(x: Number) {
when (x) {
is Int -> <!DEBUG_INFO_SMARTCAST!>x<!> : Int
is Int -> checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>x<!>)
else -> {}
}
<!TYPE_MISMATCH!>x<!> : Int
checkSubtype<Int>(<!TYPE_MISMATCH!>x<!>)
}
fun whenWithoutSubject(x: Number) {
when {
(x is Int) -> <!DEBUG_INFO_SMARTCAST!>x<!> : Int
(x is Int) -> checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>x<!>)
else -> {}
}
<!TYPE_MISMATCH!>x<!> : Int
checkSubtype<Int>(<!TYPE_MISMATCH!>x<!>)
}
@@ -1,13 +1,15 @@
// !CHECK_TYPE
fun foo(x: Int, list: List<Int>?) {
when (x) {
in list!! -> <!DEBUG_INFO_SMARTCAST!>list<!> : List<Int>
in list!! -> checkSubtype<List<Int>>(<!DEBUG_INFO_SMARTCAST!>list<!>)
else -> {}
}
}
fun whenWithoutSubject(x: Int, list: List<Int>?) {
when {
x in list!! -> <!DEBUG_INFO_SMARTCAST!>list<!> : List<Int>
x in list!! -> checkSubtype<List<Int>>(<!DEBUG_INFO_SMARTCAST!>list<!>)
else -> {}
}
}
@@ -1,6 +1,8 @@
// !CHECK_TYPE
fun foo(x: Number) {
when (x as Int) {
else -> <!DEBUG_INFO_SMARTCAST!>x<!> : Int
else -> checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>x<!>)
}
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>x<!>)
}
@@ -1,24 +1,26 @@
// !CHECK_TYPE
fun simpleWhile(x: Int?, y0: Int) {
var y = y0
while (x!! == y) {
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>x<!>)
y++
}
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>x<!>)
}
fun whileWithBreak(x: Int?, y0: Int) {
var y = y0
while (x!! == y) {
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>x<!>)
break
}
<!DEBUG_INFO_SMARTCAST!>x<!> : Int
checkSubtype<Int>(<!DEBUG_INFO_SMARTCAST!>x<!>)
}
fun whileWithNoCondition(x: Int?) {
while (<!SYNTAX!><!>) {
x!!
}
<!TYPE_MISMATCH!>x<!> : Int
checkSubtype<Int>(<!TYPE_MISMATCH!>x<!>)
}
@@ -1,3 +1,5 @@
// !CHECK_TYPE
//KT-2631 Check multiple assignment
package a
@@ -12,14 +14,14 @@ fun MyClass2.component1() = 1.2
fun test(mc1: MyClass, mc2: MyClass2) {
val (a, b) = mc1
a : Int
b : String
checkSubtype<Int>(a)
checkSubtype<String>(b)
val (c) = mc2
c : Double
checkSubtype<Double>(c)
//check no error types
<!TYPE_MISMATCH!>a<!> : Boolean
<!TYPE_MISMATCH!>b<!> : Boolean
<!TYPE_MISMATCH!>c<!> : Boolean
checkSubtype<Boolean>(<!TYPE_MISMATCH!>a<!>)
checkSubtype<Boolean>(<!TYPE_MISMATCH!>b<!>)
checkSubtype<Boolean>(<!TYPE_MISMATCH!>c<!>)
}
@@ -1,8 +1,10 @@
// !CHECK_TYPE
class A {
val a by MyProperty()
fun test() {
a: Int
checkSubtype<Int>(a)
}
}
@@ -1,3 +1,5 @@
// !CHECK_TYPE
package m
fun test(i: Int?) {
@@ -10,14 +12,14 @@ fun test(i: Int?) {
val a: Int = l4@ <!TYPE_MISMATCH!>""<!>
val b: Int = (<!TYPE_MISMATCH!>""<!>)
val c: Int = <!TYPE_MISMATCH!>""<!>: Int
val d: Int = <!TYPE_MISMATCH!><!TYPE_MISMATCH!>""<!>: Long<!>
val c: Int = checkSubtype<Int>(<!TYPE_MISMATCH!>""<!>)
val d: Int = <!TYPE_MISMATCH!>checkSubtype<Long>(<!TYPE_MISMATCH!>""<!>)<!>
foo(l4@ <!TYPE_MISMATCH!>""<!>)
foo((<!TYPE_MISMATCH!>""<!>))
foo(<!TYPE_MISMATCH!>""<!>: Int)
foo(<!TYPE_MISMATCH!><!TYPE_MISMATCH!>""<!>: Long<!>)
foo(checkSubtype<Int>(<!TYPE_MISMATCH!>""<!>))
foo(<!TYPE_MISMATCH!>checkSubtype<Long>(<!TYPE_MISMATCH!>""<!>)<!>)
use(a, b, c, d)
}
@@ -1,3 +1,4 @@
// !CHECK_TYPE
// FILE: A.java
public enum A {
ENTRY;
@@ -5,5 +6,5 @@ public enum A {
// FILE: test.kt
fun main() {
A.valueOf("ENTRY"): A
checkSubtype<A>(A.valueOf("ENTRY"))
}
@@ -1,3 +1,4 @@
// !CHECK_TYPE
// FILE: A.java
public enum A {
ENTRY,
@@ -6,5 +7,5 @@ public enum A {
// FILE: test.kt
fun main() {
A.values(): Array<A>
checkSubtype<Array<A>>(A.values())
}
@@ -1,3 +1,4 @@
// !CHECK_TYPE
// FILE: A.java
public enum A {
@@ -11,5 +12,5 @@ public enum A {
// FILE: test.kt
fun main() {
A.ENTRY.s(): String?
checkSubtype<String?>(A.ENTRY.s())
}
@@ -1,3 +1,5 @@
// !CHECK_TYPE
import java.util.Enumeration
fun <T> java.util.Enumeration<T>.iterator() = object : Iterator<T> {
@@ -8,6 +10,6 @@ fun <T> java.util.Enumeration<T>.iterator() = object : Iterator<T> {
fun a(e : java.util.Enumeration<Int>) {
for (i in e) {
i : Int
checkSubtype<Int>(i)
}
}
@@ -1,3 +1,4 @@
// !CHECK_TYPE
// !DIAGNOSTICS: -UNUSED_PARAMETER
annotation class ann(val name: String)
@@ -16,5 +17,5 @@ val withExpression = fun() = 5
val funfun = fun() = fun() = 5
val parentesized = (fun () {})
val parentesizedWithType = (fun () {}) : () -> Unit
val withType = (fun () {}) : () -> Unit
val parentesizedWithType = checkSubtype<() -> Unit>((fun () {}))
val withType = checkSubtype<() -> Unit>((fun () {}))
@@ -4,7 +4,7 @@
fun testReturnType(foo: String) {
val bar = fun () = foo
bar.checkType { it : _<() -> String> }
bar.checkType { _<() -> String>() }
val bas: () -> String = fun () = foo
@@ -14,7 +14,7 @@ fun testReturnType(foo: String) {
fun testParamType() {
val bar = fun (bal: String){}
bar.checkType { it : _<(String) -> Unit> }
bar.checkType { _<(String) -> Unit>() }
val bas: (String) -> Unit = fun (param: String) {}
val bag: (Int) -> Unit = <!TYPE_MISMATCH!>fun (<!EXPECTED_PARAMETER_TYPE_MISMATCH!>param: String<!>) {}<!>
@@ -23,7 +23,7 @@ fun testParamType() {
fun testReceiverType() {
val bar = fun String.() {}
bar.checkType { it : _<String.() -> Unit> }
bar.checkType { _<String.() -> Unit>() }
val bas: String.() -> Unit = fun String.() {}
@@ -1,3 +1,4 @@
// !CHECK_TYPE
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
fun listOf<T>(): List<T> = null!!
@@ -6,13 +7,13 @@ fun test(a: (Int) -> Int) {
test(fun (x) = x)
test(fun (x): Int { x: Int; return 4 })
test(fun (x): Int { checkSubtype<Int>(x); return 4 })
}
fun test2(a: () -> List<Int>) {
test2(fun () = <!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>listOf<!>())
}
val a: (Int) -> Unit = fun(x) { x: Int }
val a: (Int) -> Unit = fun(x) { checkSubtype<Int>(x) }
val b: (Int) -> Unit = <!TYPE_MISMATCH!>fun(<!EXPECTED_PARAMETER_TYPE_MISMATCH!>x: String<!>) {}<!>
@@ -1,3 +1,4 @@
// !CHECK_TYPE
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
val a = fun (<!CANNOT_INFER_PARAMETER_TYPE!>x<!>) = <!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>x<!>
@@ -13,7 +14,7 @@ val e: (Int, String) -> Int = <!TYPE_MISMATCH!>fun <!EXPECTED_PARAMETERS_NUMBER_
val f: (Int) -> Int = <!TYPE_MISMATCH!>fun (<!EXPECTED_PARAMETER_TYPE_MISMATCH!>x: String<!>) = 3<!>
fun test1(a: (Int) -> Unit) {
test1(fun (x) { x : Int})
test1(fun (x) { checkSubtype<Int>(x)})
}
fun test2(a: (Int) -> Unit) {
@@ -1,16 +1,18 @@
// !CHECK_TYPE
fun test(bal: Array<Int>) {
var bar = 4
val a = { bar += 4 }
a : () -> Unit
checkSubtype<() -> Unit>(a)
val b = { bar = 4 }
b : () -> Unit
checkSubtype<() -> Unit>(b)
val c = { bal[2] = 3 }
c : () -> Unit
checkSubtype<() -> Unit>(c)
val d = run { bar += 4 }
d : Unit
checkSubtype<Unit>(d)
}
fun <T> run(f: () -> T): T = f()
@@ -6,5 +6,5 @@ fun test() {
} else {
{ 2 }
}
a checkType { it : _<() -> Int> }
a checkType { _<() -> Int>() }
}
@@ -3,5 +3,5 @@ fun <T> id(t: T) = t
fun foo() {
val i = id { 22 } //type inference error: no information for parameter
i checkType { it : _<()->Int> }
i checkType { _<()->Int>() }
}
@@ -1,9 +1,11 @@
// !CHECK_TYPE
fun test2(a: Int) {
val x = run f@{
if (a > 0) <!RETURN_NOT_ALLOWED!>return<!>
return@f 1
}
x: Int
checkSubtype<Int>(x)
}
fun run<T>(f: () -> T): T { return f() }
@@ -1,6 +1,8 @@
// !CHECK_TYPE
fun test2() {
val x = run f@{return@f 1}
x: Int
checkSubtype<Int>(x)
}
fun run<T>(f: () -> T): T { return f() }
@@ -1,12 +1,14 @@
// !CHECK_TYPE
fun test() {
val x = run(f@{return@f 1})
x: Int
checkSubtype<Int>(x)
}
fun test1() {
val x = run(l@{return@l 1})
x: Int
checkSubtype<Int>(x)
}
fun run<T>(f: () -> T): T { return f() }
@@ -1,6 +1,8 @@
// !CHECK_TYPE
fun test() {
run1 f@{
(return@f 1)<!UNREACHABLE_CODE!>: Nothing<!>
<!UNREACHABLE_CODE!>checkSubtype<Nothing>(<!>return@f 1<!UNREACHABLE_CODE!>)<!>
}
}
@@ -1,3 +1,5 @@
// !CHECK_TYPE
fun test() {
val x = run f@{
fun local(a: Int): String {
@@ -6,7 +8,7 @@ fun test() {
}
return@f 1
}
x: Int
checkSubtype<Int>(x)
}
fun run<T>(f: () -> T): T { return f() }
@@ -1,3 +1,5 @@
// !CHECK_TYPE
fun test() {
val x = run f@{
run ff@ {
@@ -5,7 +7,7 @@ fun test() {
}
return@f 1
}
x: Int
checkSubtype<Int>(x)
}
fun run<T>(f: () -> T): T { return f() }
@@ -1,9 +1,11 @@
// !CHECK_TYPE
fun test(a: Int) {
val x = run f@{
if (a > 0) return@f
else return@f Unit
}
x: Unit
checkSubtype<Unit>(x)
}
fun run<T>(f: () -> T): T { return f() }
@@ -1,3 +1,5 @@
// !CHECK_TYPE
trait A
trait B: A
trait C: A
@@ -8,7 +10,7 @@ fun test(a: C, b: B) {
if (a != b) return@f a
b
}
x: A
checkSubtype<A>(x)
}
fun run<T>(f: () -> T): T { return f() }
@@ -1,3 +1,5 @@
// !CHECK_TYPE
class In<in T>() {
fun f(<!UNUSED_PARAMETER!>t<!> : T) : Unit {}
fun f(<!UNUSED_PARAMETER!>t<!> : Int) : Int = 1
@@ -43,7 +45,7 @@ fun testInOut() {
(null <!CAST_NEVER_SUCCEEDS!>as<!> Inv<*>).<!UNRESOLVED_REFERENCE!>inf<!>(1) // !!
Inv<Int>().outf()
<!TYPE_MISMATCH!>(null <!CAST_NEVER_SUCCEEDS!>as<!> Inv<in Int>).outf()<!> : Int // Type mismatch
checkSubtype<Int>(<!TYPE_MISMATCH!>(null <!CAST_NEVER_SUCCEEDS!>as<!> Inv<in Int>).outf()<!>) // Type mismatch
(null <!CAST_NEVER_SUCCEEDS!>as<!> Inv<out Int>).outf()
(null <!CAST_NEVER_SUCCEEDS!>as<!> Inv<*>).outf()
@@ -5,5 +5,5 @@ trait Tr<T> {
fun test(t: Tr<*>) {
t.v = t
t.v checkType { it : _<Tr<*>> }
t.v checkType { _<Tr<*>>() }
}
@@ -7,5 +7,5 @@ trait Tr<T> {
fun test(t: Tr<*>) {
t.<!SETTER_PROJECTED_OUT!>v<!> = null!!
t.v checkType { it : _<Any?> }
t.v checkType { _<Any?>() }
}
@@ -6,7 +6,7 @@ fun <T: Any> bar(a: Array<T>): Array<T?> = null!!
fun test1(a: Array<out Int>) {
val r: Array<out Int?> = bar(a)
val t = bar(a)
t checkType { it : _<Array<out Int?>> }
t checkType { _<Array<out Int?>>() }
}
fun <T: Any> foo(l: Array<T>): Array<Array<T?>> = null!!
@@ -14,5 +14,5 @@ fun <T: Any> foo(l: Array<T>): Array<Array<T?>> = null!!
fun test2(a: Array<out Int>) {
val r: Array<out Array<out Int?>> = foo(a)
val t = foo(a)
t checkType { it : _<Array<out Array<out Int?>>> }
t checkType { _<Array<out Array<out Int?>>>() }
}
@@ -15,15 +15,15 @@ public class A {
fun test1(clazz: Class<out Int>) {
val foo0: Class<out Int> = A.foo(clazz)
val foo1 = A.foo(clazz)
foo1 checkType { it: _< Class<out Int> > }
foo1 checkType { _< Class<out Int> >() }
// should be ok
foo1 checkType { <!TYPE_MISMATCH!>it<!>: _< Class<out Int?> > }
foo1 checkType { <!TYPE_MISMATCH!>_<!>< Class<out Int?> >() }
}
fun tes2t(clazz: Class<in Int>) {
val foo0: Class<out Class<in Int>> = A.bar(clazz)
val foo1 = A.bar(clazz)
foo1 checkType { it: _< Class<out Class<in Int>> > }
foo1 checkType { _< Class<out Class<in Int>> >() }
// should be ok
foo1 checkType { <!TYPE_MISMATCH!>it<!>: _< Class<out Class<in Int?>> > }
foo1 checkType { <!TYPE_MISMATCH!>_<!>< Class<out Class<in Int?>> >() }
}
@@ -4,10 +4,10 @@ fun <T : Any> Array<T?>.filterNotNull(): List<T> = throw Exception()
fun test1(a: Array<out Int?>) {
val list = a.filterNotNull()
list checkType { it : _<List<Int>> }
list checkType { _<List<Int>>() }
}
fun test2(vararg a: Int?) {
val list = a.filterNotNull()
list checkType { it : _<List<Int>> }
list checkType { _<List<Int>>() }
}
@@ -6,11 +6,11 @@ fun <T> foo(array: Array<T>): Array<T> = array
fun test1(a1: Array<out Int>) {
val b1: Array<out Int> = foo(a1)
val c1 = foo(a1)
c1 checkType { it : _<Array<out Int>> }
c1 checkType { _<Array<out Int>>() }
}
fun test2(a2: Array<in Int>) {
val b2: Array<in Int> = foo(a2)
val c2 = foo(a2)
c2 checkType { it : _<Array<in Int>> }
c2 checkType { _<Array<in Int>>() }
}
@@ -6,11 +6,11 @@ fun <T> foo(a: Array<T>): Array<Array<T>> = throw Exception()
fun test1(a1: Array<out Int>) {
val b1: Array<out Array<out Int>> = foo(a1)
val c1 = foo(a1)
c1 checkType { it : _<Array<out Array<out Int>>> }
c1 checkType { _<Array<out Array<out Int>>>() }
}
fun test2(a2: Array<in Int>) {
val b2: Array<out Array<in Int>> = foo(a2)
val c2 = foo(a2)
c2 checkType { it : _<Array<out Array<in Int>>> }
c2 checkType { _<Array<out Array<in Int>>>() }
}
@@ -4,11 +4,11 @@
fun <T> foo1(a1: Array<in T>, a2: Array<T>): T = null!!
fun test1(a1: Array<Int>, a2: Array<out Int>) {
foo1(a1, a2) checkType { it : _<Int> }
foo1(a1, a2) checkType { _<Int>() }
}
fun <T> foo2(a1: Array<T>, a2: Array<out T>): T = null!!
fun test2(a1: Array<in Int>, a2: Array<Int>) {
foo2(a1, a2) checkType { it : _<Any?>}
foo2(a1, a2) checkType { _<Any?>() }
}
@@ -5,5 +5,5 @@ fun <T> foo(l: MutableList<T>): MutableList<T> = l
fun test(l: MutableList<out Int>) {
val a: MutableList<out Int> = foo(l)
val b = foo(l)
b checkType { it: _< MutableList<out Int> > }
b checkType { _< MutableList<out Int> >() }
}

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