added info about smart casts to diagnostic tests

This commit is contained in:
Svetlana Isakova
2013-12-06 20:12:41 +04:00
parent 00da5fe1fb
commit c30259dfbe
116 changed files with 383 additions and 348 deletions
@@ -28,9 +28,11 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
import org.jetbrains.jet.lang.diagnostics.DiagnosticFactory;
import org.jetbrains.jet.lang.diagnostics.Severity;
import org.jetbrains.jet.lang.psi.JetExpression;
import org.jetbrains.jet.lang.psi.JetReferenceExpression;
import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.types.JetType;
import java.util.*;
import java.util.regex.Matcher;
@@ -104,6 +106,13 @@ public class CheckerTestUtil {
debugAnnotations.add(new DebugInfoDiagnostic(expression, factory));
}
});
// this code is used in tests and in internal action 'copy current file as diagnostic test'
//noinspection TestOnlyProblems
for (JetExpression expression : bindingContext.getSliceContents(BindingContext.AUTOCAST).keySet()) {
if (PsiTreeUtil.isAncestor(root, expression, false)) {
debugAnnotations.add(new DebugInfoDiagnostic(expression, DebugInfoDiagnosticFactory.AUTOCAST));
}
}
return debugAnnotations;
}
@@ -389,16 +398,21 @@ public class CheckerTestUtil {
}
public static class DebugInfoDiagnosticFactory extends DiagnosticFactory {
public static final DebugInfoDiagnosticFactory AUTOCAST = new DebugInfoDiagnosticFactory("AUTOCAST");
public static final DebugInfoDiagnosticFactory ELEMENT_WITH_ERROR_TYPE = new DebugInfoDiagnosticFactory("ELEMENT_WITH_ERROR_TYPE");
public static final DebugInfoDiagnosticFactory UNRESOLVED_WITH_TARGET = new DebugInfoDiagnosticFactory("UNRESOLVED_WITH_TARGET");
public static final DebugInfoDiagnosticFactory MISSING_UNRESOLVED = new DebugInfoDiagnosticFactory("MISSING_UNRESOLVED");
private final String name;
private DebugInfoDiagnosticFactory(String name) {
super(Severity.ERROR);
private DebugInfoDiagnosticFactory(String name, Severity severity) {
super(severity);
this.name = name;
}
private DebugInfoDiagnosticFactory(String name) {
this(name, Severity.ERROR);
}
@NotNull
@Override
public String getName() {
@@ -407,7 +421,7 @@ public class CheckerTestUtil {
}
public static class DebugInfoDiagnostic extends AbstractDiagnosticForTests {
public DebugInfoDiagnostic(@NotNull JetReferenceExpression reference, @NotNull DebugInfoDiagnosticFactory factory) {
public DebugInfoDiagnostic(@NotNull JetExpression reference, @NotNull DebugInfoDiagnosticFactory factory) {
super(reference, factory);
}
}
@@ -1,6 +1,6 @@
// FILE: a.kt
package example.ns
val y : Any? = 2
val y : Any? = 2
// FILE: b.kt
package example
@@ -20,53 +20,53 @@ val x : Any? = 1
fun Any?.vars(<!UNUSED_PARAMETER!>a<!>: Any?) : Int {
var <!ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE!>b<!>: Int = 0
if (ns.y is Int) {
b = <!UNUSED_VALUE!>ns.y<!>
b = <!UNUSED_VALUE, DEBUG_INFO_AUTOCAST!>ns.y<!>
}
if (ns.y is Int) {
b = <!UNUSED_VALUE!>example.ns.y<!>
b = <!UNUSED_VALUE, DEBUG_INFO_AUTOCAST!>example.ns.y<!>
}
if (example.ns.y is Int) {
b = <!UNUSED_VALUE!>ns.y<!>
b = <!UNUSED_VALUE, DEBUG_INFO_AUTOCAST!>ns.y<!>
}
if (example.ns.y is Int) {
b = <!UNUSED_VALUE!>example.ns.y<!>
b = <!UNUSED_VALUE, DEBUG_INFO_AUTOCAST!>example.ns.y<!>
}
// if (namespace.bottles.ns.y is Int) {
// b = ns.y
// }
if (Obj.y is Int) {
b = <!UNUSED_VALUE!>Obj.y<!>
b = <!UNUSED_VALUE, DEBUG_INFO_AUTOCAST!>Obj.y<!>
}
if (example.Obj.y is Int) {
b = <!UNUSED_VALUE!>Obj.y<!>
b = <!UNUSED_VALUE, DEBUG_INFO_AUTOCAST!>Obj.y<!>
}
if (AClass.y is Int) {
b = <!UNUSED_VALUE!>AClass.y<!>
b = <!UNUSED_VALUE, DEBUG_INFO_AUTOCAST!>AClass.y<!>
}
if (example.AClass.y is Int) {
b = <!UNUSED_VALUE!>AClass.y<!>
b = <!UNUSED_VALUE, DEBUG_INFO_AUTOCAST!>AClass.y<!>
}
if (x is Int) {
b = <!UNUSED_VALUE!>x<!>
b = <!UNUSED_VALUE, DEBUG_INFO_AUTOCAST!>x<!>
}
if (example.x is Int) {
b = <!UNUSED_VALUE!>x<!>
b = <!UNUSED_VALUE, DEBUG_INFO_AUTOCAST!>x<!>
}
if (example.x is Int) {
b = <!UNUSED_VALUE!>example.x<!>
b = <!UNUSED_VALUE, DEBUG_INFO_AUTOCAST!>example.x<!>
}
return 1
}
fun Any?.foo() : Int {
if (this is Int)
return this
return <!DEBUG_INFO_AUTOCAST!>this<!>
if (this@foo is Int)
return this
return <!DEBUG_INFO_AUTOCAST!>this<!>
if (this@foo is Int)
return this@foo
return <!DEBUG_INFO_AUTOCAST!>this@foo<!>
if (this is Int)
return this@foo
return <!DEBUG_INFO_AUTOCAST!>this@foo<!>
return 1
}
@@ -77,16 +77,16 @@ open class C {
fun foo() {
var <!ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE!>t<!> : T? = null
if (this is T) {
t = <!UNUSED_VALUE!>this<!>
t = <!UNUSED_VALUE, DEBUG_INFO_AUTOCAST!>this<!>
}
if (this is T) {
t = <!UNUSED_VALUE!>this@C<!>
t = <!UNUSED_VALUE, DEBUG_INFO_AUTOCAST!>this@C<!>
}
if (this@C is T) {
t = <!UNUSED_VALUE!>this<!>
t = <!UNUSED_VALUE, DEBUG_INFO_AUTOCAST!>this<!>
}
if (this@C is T) {
t = <!UNUSED_VALUE!>this@C<!>
t = <!UNUSED_VALUE, DEBUG_INFO_AUTOCAST!>this@C<!>
}
}
}
}
@@ -38,7 +38,7 @@ class C {
break;
}
}
a.compareTo("2")
<!DEBUG_INFO_AUTOCAST!>a<!>.compareTo("2")
}
fun containsBreakWithLabel(a: String?) {
@@ -52,7 +52,7 @@ class C {
@loop while(a == null) {
<!NOT_A_LOOP_LABEL!>break<!UNRESOLVED_REFERENCE!>@label<!><!>
}
a.compareTo("2")
<!DEBUG_INFO_AUTOCAST!>a<!>.compareTo("2")
}
fun containsBreakToOuterLoop(a: String?, b: String?) {
@@ -60,7 +60,7 @@ class C {
while(a == null) {
break@loop
}
a.compareTo("2")
<!DEBUG_INFO_AUTOCAST!>a<!>.compareTo("2")
}
}
@@ -135,7 +135,7 @@ class A() : BodyTag("a") {
get() = attributes["href"]
set(value) {
if (value != null) {
attributes.put("href", value)
attributes.put("href", <!DEBUG_INFO_AUTOCAST!>value<!>)
// attributes["href"] = value //doesn't work: KT-1355
}
}
@@ -4,6 +4,6 @@ fun gg() {
val a: String? = ""
if (a != null) {
ff(a)
ff(<!DEBUG_INFO_AUTOCAST!>a<!>)
}
}
@@ -5,4 +5,4 @@ package java
val c : lang.Class<*>? = null
val <T> Array<T>?.length : Int get() = if (this != null) this.size else throw NullPointerException()
val <T> Array<T>?.length : Int get() = if (this != null) <!DEBUG_INFO_AUTOCAST!>this<!>.size else throw NullPointerException()
@@ -1,7 +1,7 @@
fun test() {
val a : Int? = 0
if (a != null) {
a.plus(1)
<!DEBUG_INFO_AUTOCAST!>a<!>.plus(1)
}
else {
a?.plus(1)
@@ -14,122 +14,131 @@ fun test() {
ins?.read()
if (ins != null) {
ins.read()
<!DEBUG_INFO_AUTOCAST!>ins<!>.read()
out?.println()
if (out != null) {
ins.read();
out.println();
<!DEBUG_INFO_AUTOCAST!>ins<!>.read();
<!DEBUG_INFO_AUTOCAST!>out<!>.println();
}
}
if (out != null && ins != null) {
ins.read();
out.println();
<!DEBUG_INFO_AUTOCAST!>ins<!>.read();
<!DEBUG_INFO_AUTOCAST!>out<!>.println();
}
if (out == null) {
out?.println()
} else {
out.println()
<!DEBUG_INFO_AUTOCAST!>out<!>.println()
}
if (out != null && ins != null || out != null) {
ins?.read();
out.println();
ins<!UNSAFE_CALL!>.<!>read();
<!DEBUG_INFO_AUTOCAST!>out<!>.println();
}
if (out == null || out.println(0) == Unit.VALUE) {
if (out == null || <!DEBUG_INFO_AUTOCAST!>out<!>.println(0) == Unit.VALUE) {
out?.println(1)
out<!UNSAFE_CALL!>.<!>println(1)
}
else {
out.println(2)
<!DEBUG_INFO_AUTOCAST!>out<!>.println(2)
}
if (out != null && out.println() == Unit.VALUE) {
out.println();
if (out != null && <!DEBUG_INFO_AUTOCAST!>out<!>.println() == Unit.VALUE) {
<!DEBUG_INFO_AUTOCAST!>out<!>.println();
}
else {
out?.println();
}
if (out == null || out.println() == Unit.VALUE) {
if (out == null || <!DEBUG_INFO_AUTOCAST!>out<!>.println() == Unit.VALUE) {
out?.println();
}
else {
out.println();
<!DEBUG_INFO_AUTOCAST!>out<!>.println();
}
if (1 == 2 || out != null && out.println(1) == Unit.VALUE) {
if (1 == 2 || out != null && <!DEBUG_INFO_AUTOCAST!>out<!>.println(1) == Unit.VALUE) {
out?.println(2);
out<!UNSAFE_CALL!>.<!>println(2);
}
else {
out?.println(3)
out<!UNSAFE_CALL!>.<!>println(3)
}
out?.println()
ins?.read()
if (ins != null) {
ins.read()
<!DEBUG_INFO_AUTOCAST!>ins<!>.read()
out?.println()
if (out != null) {
ins.read();
out.println();
<!DEBUG_INFO_AUTOCAST!>ins<!>.read();
<!DEBUG_INFO_AUTOCAST!>out<!>.println();
}
}
if (out != null && ins != null) {
ins.read();
out.println();
<!DEBUG_INFO_AUTOCAST!>ins<!>.read();
<!DEBUG_INFO_AUTOCAST!>out<!>.println();
}
if (out == null) {
out?.println()
} else {
out.println()
<!DEBUG_INFO_AUTOCAST!>out<!>.println()
}
if (out != null && ins != null || out != null) {
ins?.read();
out.println();
<!DEBUG_INFO_AUTOCAST!>out<!>.println();
}
if (out == null || out.println(0) == Unit.VALUE) {
if (out == null || <!DEBUG_INFO_AUTOCAST!>out<!>.println(0) == Unit.VALUE) {
out?.println(1)
out<!UNSAFE_CALL!>.<!>println(1)
}
else {
out.println(2)
<!DEBUG_INFO_AUTOCAST!>out<!>.println(2)
}
if (out != null && out.println() == Unit.VALUE) {
out.println();
if (out != null && <!DEBUG_INFO_AUTOCAST!>out<!>.println() == Unit.VALUE) {
<!DEBUG_INFO_AUTOCAST!>out<!>.println();
}
else {
out?.println();
out<!UNSAFE_CALL!>.<!>println();
}
if (out == null || out.println() == Unit.VALUE) {
if (out == null || <!DEBUG_INFO_AUTOCAST!>out<!>.println() == Unit.VALUE) {
out?.println();
out<!UNSAFE_CALL!>.<!>println();
}
else {
out.println();
<!DEBUG_INFO_AUTOCAST!>out<!>.println();
}
if (1 == 2 || out != null && out.println(1) == Unit.VALUE) {
if (1 == 2 || out != null && <!DEBUG_INFO_AUTOCAST!>out<!>.println(1) == Unit.VALUE) {
out?.println(2);
out<!UNSAFE_CALL!>.<!>println(2);
}
else {
out?.println(3)
out<!UNSAFE_CALL!>.<!>println(3)
}
if (1 > 2) {
if (out == null) return;
out.println();
<!DEBUG_INFO_AUTOCAST!>out<!>.println();
}
out?.println();
while (out != null) {
out.println();
<!DEBUG_INFO_AUTOCAST!>out<!>.println();
}
out?.println();
@@ -137,16 +146,18 @@ fun test() {
while (out2 == null) {
out2?.println();
out2<!UNSAFE_CALL!>.<!>println();
}
out2.println()
<!DEBUG_INFO_AUTOCAST!>out2<!>.println()
}
fun f(out : String?) {
out?.get(0)
out<!UNSAFE_CALL!>.<!>get(0)
if (out != null) else return;
out.get(0)
<!DEBUG_INFO_AUTOCAST!>out<!>.get(0)
}
fun f1(out : String?) {
@@ -155,7 +166,7 @@ fun f1(out : String?) {
1 + 2
return;
}
out.get(0)
<!DEBUG_INFO_AUTOCAST!>out<!>.get(0)
}
fun f2(out : String?) {
@@ -164,7 +175,7 @@ fun f2(out : String?) {
1 + 2
return;
}
out.get(0)
<!DEBUG_INFO_AUTOCAST!>out<!>.get(0)
}
fun f3(out : String?) {
@@ -176,25 +187,25 @@ fun f3(out : String?) {
else {
1 + 2
}
out.get(0)
<!DEBUG_INFO_AUTOCAST!>out<!>.get(0)
}
fun f4(s : String?) {
s?.get(0)
while (1 < 2 && s != null) {
s.get(0)
<!DEBUG_INFO_AUTOCAST!>s<!>.get(0)
}
s?.get(0)
while (s == null || 1 < 2) {
s?.get(0)
}
s.get(0)
<!DEBUG_INFO_AUTOCAST!>s<!>.get(0)
}
fun f5(s : String?) {
s?.get(0)
while (1 < 2 && s != null) {
s.get(0)
<!DEBUG_INFO_AUTOCAST!>s<!>.get(0)
}
s?.get(0)
while (s == null || 1 < 2) {
@@ -214,24 +225,24 @@ fun f6(s : String?) {
do {
s?.get(0)
} while (s == null)
s.get(0)
<!DEBUG_INFO_AUTOCAST!>s<!>.get(0)
}
fun f7(s : String?, t : String?) {
s?.get(0)
if (!(s == null)) {
s.get(0)
<!DEBUG_INFO_AUTOCAST!>s<!>.get(0)
}
s?.get(0)
if (!(s != null)) {
s?.get(0)
}
else {
s.get(0)
<!DEBUG_INFO_AUTOCAST!>s<!>.get(0)
}
s?.get(0)
if (!!(s != null)) {
s.get(0)
<!DEBUG_INFO_AUTOCAST!>s<!>.get(0)
}
else {
s?.get(0)
@@ -239,8 +250,8 @@ fun f7(s : String?, t : String?) {
s?.get(0)
t?.get(0)
if (!(s == null || t == null)) {
s.get(0)
t.get(0)
<!DEBUG_INFO_AUTOCAST!>s<!>.get(0)
<!DEBUG_INFO_AUTOCAST!>t<!>.get(0)
}
else {
s?.get(0)
@@ -249,7 +260,7 @@ fun f7(s : String?, t : String?) {
s?.get(0)
t?.get(0)
if (!(s == null)) {
s.get(0)
<!DEBUG_INFO_AUTOCAST!>s<!>.get(0)
t?.get(0)
}
else {
@@ -261,22 +272,22 @@ fun f7(s : String?, t : String?) {
fun f8(b : String?, a : String) {
b?.get(0)
if (b == a) {
b.get(0);
<!DEBUG_INFO_AUTOCAST!>b<!>.get(0);
}
b?.get(0)
if (a == b) {
b.get(0)
<!DEBUG_INFO_AUTOCAST!>b<!>.get(0)
}
if (a != b) {
b?.get(0)
}
else {
b.get(0)
<!DEBUG_INFO_AUTOCAST!>b<!>.get(0)
}
}
fun f9(a : Int?) : Int {
if (a != null)
return a
return <!DEBUG_INFO_AUTOCAST!>a<!>
return 1
}
@@ -5,6 +5,6 @@ trait MutableMap<K, V>: Map<K, V> {
fun p(p: Map<String, Int>) {
if (p is MutableMap<String, Int>) {
p[""] = 1
<!DEBUG_INFO_AUTOCAST!>p<!>[""] = 1
}
}
@@ -1,3 +1,4 @@
// !DIAGNOSTICS: -DEBUG_INFO_AUTOCAST
trait Either<out A, out B>
trait Left<out A>: Either<A, Nothing> {
val value: A
@@ -1,3 +1,4 @@
// !DIAGNOSTICS: -DEBUG_INFO_AUTOCAST
trait Either<out A, out B>
trait Left<out A>: Either<A, Nothing> {
val value: A
@@ -1,3 +1,4 @@
// !DIAGNOSTICS: -DEBUG_INFO_AUTOCAST
trait Either<out A, out B>
trait Left<out A>: Either<A, Nothing> {
val value: A
@@ -1,6 +1,6 @@
fun illegalWhenBlock(a: Any): Int {
when(a) {
is Int -> return a
is String -> return a.length
is Int -> return <!DEBUG_INFO_AUTOCAST!>a<!>
is String -> return <!DEBUG_INFO_AUTOCAST!>a<!>.length
}
<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
@@ -11,6 +11,6 @@ fun test(c: Coll?) {
for (x in <!ITERATOR_MISSING!>c<!>) {}
if (c != null) {
for(x in c) {}
for(x in <!DEBUG_INFO_AUTOCAST!>c<!>) {}
}
}
@@ -2,6 +2,6 @@ class C(val f : () -> Unit)
fun test(e : Any) {
if (e is C) {
(e.f)()
(<!DEBUG_INFO_AUTOCAST!>e<!>.f)()
}
}
@@ -1,13 +1,13 @@
fun f1(s: String?) {
if (s!! == "");
s : String
<!DEBUG_INFO_AUTOCAST!>s<!> : String
}
fun f2(s: Number?) {
if (s is Int);
<!TYPE_MISMATCH!>s<!> : Int
if (s as Int == 42);
s : Int
<!DEBUG_INFO_AUTOCAST!>s<!> : Int
}
fun f3(s: Number?) {
@@ -3,7 +3,7 @@ class BinOp(val operator : String) : Expr
fun test(e : Expr) {
if (e is BinOp) {
when (e.operator) {
when (<!DEBUG_INFO_AUTOCAST!>e<!>.operator) {
else -> 0
}
}
@@ -4,7 +4,7 @@ fun test(x: Any, y: Int?) {
if (x !is String) return
if (y == null) return
class Local: Base(x, y) {
class Local: Base(<!DEBUG_INFO_AUTOCAST!>x<!>, <!DEBUG_INFO_AUTOCAST!>y<!>) {
}
}
@@ -1,8 +1,8 @@
fun test(x: Any) {
if (x !is String) return
class Local(s: String = x) {
fun foo(s: String = x): String = s
class Local(s: String = <!DEBUG_INFO_AUTOCAST!>x<!>) {
fun foo(s: String = <!DEBUG_INFO_AUTOCAST!>x<!>): String = s
}
}
@@ -9,8 +9,8 @@ fun test(del: Any?) {
if (del !is Del) return
class Local {
val delegatedVal by df(del)
val delegatedVal1: Int by df(del)
val delegatedVal by df(<!DEBUG_INFO_AUTOCAST!>del<!>)
val delegatedVal1: Int by df(<!DEBUG_INFO_AUTOCAST!>del<!>)
}
}
@@ -5,7 +5,7 @@ trait D {
fun test(d: Any?) {
if (d !is D) return
class Local : D by d {
class Local : D by <!DEBUG_INFO_AUTOCAST!>d<!> {
}
}
@@ -7,12 +7,12 @@ fun test(d: Any?) {
class Local {
fun f() {
d.foo()
<!DEBUG_INFO_AUTOCAST!>d<!>.foo()
}
fun f1() = d.foo()
fun f1() = <!DEBUG_INFO_AUTOCAST!>d<!>.foo()
fun f2(): String = d.foo()
fun f2(): String = <!DEBUG_INFO_AUTOCAST!>d<!>.foo()
}
}
@@ -6,8 +6,8 @@ fun test(x: Any) {
if (y !is String) return
class Local {
{
x.length
y.length
<!DEBUG_INFO_AUTOCAST!>x<!>.length
<!DEBUG_INFO_AUTOCAST!>y<!>.length
}
}
}
@@ -2,9 +2,9 @@
fun f(a: Any?) {
if (a is B) {
class C : X(a) {
class C : X(<!DEBUG_INFO_AUTOCAST!>a<!>) {
{
a.foo()
<!DEBUG_INFO_AUTOCAST!>a<!>.foo()
}
}
}
@@ -2,11 +2,11 @@ fun test(x: Any?) {
if (x !is String) return
class C {
val v = x.length
val v = <!DEBUG_INFO_AUTOCAST!>x<!>.length
val vGet: Int
get() = x.length
get() = <!DEBUG_INFO_AUTOCAST!>x<!>.length
val s: String = x
val s: String = <!DEBUG_INFO_AUTOCAST!>x<!>
}
}
@@ -1,7 +1,7 @@
fun foo(x: Any?) {
if (x is String) {
object : Base(x) {
fun bar() = x.length
object : Base(<!DEBUG_INFO_AUTOCAST!>x<!>) {
fun bar() = <!DEBUG_INFO_AUTOCAST!>x<!>.length
}
}
}
@@ -9,7 +9,7 @@ class B : A {
}
fun foo(b: B?) : Int {
if (b == null) return 0
val o = object : A by b { //no info about b not null check
val o = object : A by <!DEBUG_INFO_AUTOCAST!>b<!> { //no info about b not null check
}
return o.foo()
}
@@ -4,7 +4,7 @@ fun test(x: Any) {
class LocalOuter {
inner class Local {
{
x.length
<!DEBUG_INFO_AUTOCAST!>x<!>.length
}
}
}
@@ -2,7 +2,7 @@ open class X(val s: String)
fun f(a: String?) {
if (a != null) {
object : X(a) { // Type mismatch: inferred type is jet.String? but jet.String was expected
object : X(<!DEBUG_INFO_AUTOCAST!>a<!>) { // Type mismatch: inferred type is jet.String? but jet.String was expected
}
}
}
@@ -1,3 +1,4 @@
// !DIAGNOSTICS: -DEBUG_INFO_AUTOCAST
fun bar(x: Int): Int = x + 1
fun foo() {
@@ -4,10 +4,10 @@ fun foo() {
val x: Int? = null
val a = Array<Int>(3, {0})
if (x != null) bar(a[x]) else bar(a[<!TYPE_MISMATCH!>x<!>])
bar(a[if (x == null) 0 else x])
if (x != null) bar(a[<!DEBUG_INFO_AUTOCAST!>x<!>]) else bar(a[<!TYPE_MISMATCH!>x<!>])
bar(a[if (x == null) 0 else <!DEBUG_INFO_AUTOCAST!>x<!>])
bar(a[<!TYPE_MISMATCH!>x<!>])
"123"[<!TYPE_MISMATCH!>x<!>];
if (x != null) "123"[x];
if (x != null) "123"[<!DEBUG_INFO_AUTOCAST!>x<!>];
}
@@ -1,5 +1,5 @@
fun foo(arr: Array<out Number>): Int {
val result = (arr as Array<Int>)[0]
arr : Array<Int>
<!DEBUG_INFO_AUTOCAST!>arr<!> : Array<Int>
return result
}
@@ -4,23 +4,23 @@ trait G {
}
fun foo1(a: Int?, b: G) {
b[a!!, a<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>] = a
a : Int
b[a!!, a<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>] = <!DEBUG_INFO_AUTOCAST!>a<!>
<!DEBUG_INFO_AUTOCAST!>a<!> : Int
}
fun foo2(a: Int?, b: G) {
b[0, a!!] = a
a : Int
b[0, a!!] = <!DEBUG_INFO_AUTOCAST!>a<!>
<!DEBUG_INFO_AUTOCAST!>a<!> : Int
}
fun foo3(a: Int?, b: G) {
val r = b[a!!, a]
a : Int
val r = b[a!!, <!DEBUG_INFO_AUTOCAST!>a<!>]
<!DEBUG_INFO_AUTOCAST!>a<!> : Int
r : Int
}
fun foo4(a: Int?, b: G) {
val r = b[0, a!!]
a : Int
<!DEBUG_INFO_AUTOCAST!>a<!> : Int
r : Int
}
@@ -1,9 +1,9 @@
fun foo1(a: Int?, b: Array<Array<Int>>) {
b[a!!][a<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>] = a
a : Int
b[a!!][a<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>] = <!DEBUG_INFO_AUTOCAST!>a<!>
<!DEBUG_INFO_AUTOCAST!>a<!> : Int
}
fun foo2(a: Int?, b: Array<Array<Int>>) {
b[0][a!!] = a
a : Int
b[0][a!!] = <!DEBUG_INFO_AUTOCAST!>a<!>
<!DEBUG_INFO_AUTOCAST!>a<!> : Int
}
@@ -5,13 +5,13 @@ trait B : A {
fun bar1(a: A) {
var b: B = a as B
a.foo()
<!DEBUG_INFO_AUTOCAST!>a<!>.foo()
b.foo()
}
fun id(b: B) = b
fun bar2(a: A) {
var b: B = id(a as B)
a.foo()
<!DEBUG_INFO_AUTOCAST!>a<!>.foo()
b.foo()
}
@@ -10,12 +10,12 @@ fun baz(b: B) = b
fun bar1(a: A) {
val b = a as B
a.foo()
<!DEBUG_INFO_AUTOCAST!>a<!>.foo()
b.foo()
}
fun bar2(a: A) {
val b = baz(a as B)
a.foo()
<!DEBUG_INFO_AUTOCAST!>a<!>.foo()
b.foo()
}
@@ -1,15 +1,15 @@
fun bar1(x: Number, y: Int) {
var yy = y
yy += x as Int
x : Int
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
}
fun bar2(x: Number) {
<!UNRESOLVED_REFERENCE!>y<!> <!UNRESOLVED_REFERENCE!>+=<!> x as Int
x : Int
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
}
fun bar3(x: Number, y: Array<Int>) {
y[0] += x as Int
x : Int
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
}
@@ -1,10 +1,10 @@
fun arrayAccessRHS(a: Int?, b: Array<Int>) {
b[0] = a!!
a : Int
<!DEBUG_INFO_AUTOCAST!>a<!> : Int
}
fun arrayAccessLHS(a: Int?, b: Array<Int>) {
b[a!!] = a
a : Int
b[a!!] = <!DEBUG_INFO_AUTOCAST!>a<!>
<!DEBUG_INFO_AUTOCAST!>a<!> : Int
}
@@ -1,3 +1,4 @@
// !DIAGNOSTICS: -DEBUG_INFO_AUTOCAST
fun bar(x: Int): Int = x + 1
fun foo() {
@@ -6,7 +6,7 @@ fun foo1(x: Number, cond: Boolean): Boolean {
fun foo2(x: Number, cond: Boolean): Boolean {
val result = ((x as Int) == 42) && cond
x : Int
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
return result
}
@@ -18,6 +18,6 @@ fun foo3(x: Number, cond: Boolean): Boolean {
fun foo4(x: Number, cond: Boolean): Boolean {
val result = ((x as Int) == 42) || cond
x : Int
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
return result
}
@@ -4,13 +4,13 @@ trait B : A
fun B.compareTo(b: B) = if (this == b) 0 else 1
fun foo(a: A): Boolean {
val result = (a as B) < a
a : B
val result = (a as B) < <!DEBUG_INFO_AUTOCAST!>a<!>
<!DEBUG_INFO_AUTOCAST!>a<!> : B
return result
}
fun bar(a: A, b: B): Boolean {
val result = b < (a as B)
a : B
<!DEBUG_INFO_AUTOCAST!>a<!> : B
return result
}
@@ -1,5 +1,5 @@
fun foo(x: Number): Boolean {
val result = (x as Int) in 1..5
x : Int
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
return result
}
@@ -1,8 +1,8 @@
fun foo(x: Int?): Int = x!!
fun elvis(x: Number?): Int {
val result = (x as Int?) ?: foo(x)
x : Int?
val result = (x as Int?) ?: foo(<!DEBUG_INFO_AUTOCAST!>x<!>)
<!DEBUG_INFO_AUTOCAST!>x<!> : Int?
return result
}
@@ -3,12 +3,12 @@ trait B : A
fun foo1(a: A, b: B): Boolean {
val result = (a as B) == b
a : B
<!DEBUG_INFO_AUTOCAST!>a<!> : B
return result
}
fun foo2(a: A, b: B): Boolean {
val result = b == (a as B)
a : B
<!DEBUG_INFO_AUTOCAST!>a<!> : B
return result
}
@@ -1,11 +1,11 @@
fun foo(a: Number): Int {
val result = (a as Int) compareTo a
a : Int
val result = (a as Int) compareTo <!DEBUG_INFO_AUTOCAST!>a<!>
<!DEBUG_INFO_AUTOCAST!>a<!> : Int
return result
}
fun bar(a: Number): Int {
val result = 42 compareTo (a as Int)
a : Int
<!DEBUG_INFO_AUTOCAST!>a<!> : Int
return result
}
@@ -4,13 +4,13 @@ trait B : A
fun B.plus(b: B) = if (this == b) b else this
fun foo(a: A): B {
val result = (a as B) + a
a : B
val result = (a as B) + <!DEBUG_INFO_AUTOCAST!>a<!>
<!DEBUG_INFO_AUTOCAST!>a<!> : B
return result
}
fun bar(a: A, b: B): B {
val result = b + (a as B)
a : B
<!DEBUG_INFO_AUTOCAST!>a<!> : B
return result
}
@@ -1,5 +1,5 @@
fun foo(x: Int?): Boolean {
val result = ((x!! == 0) && ((x : Int) == 0))
x : Int
val result = ((x!! == 0) && ((<!DEBUG_INFO_AUTOCAST!>x<!> : Int) == 0))
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
return result
}
@@ -5,7 +5,7 @@ fun whileLoop(x: Int?) {
}
<!TYPE_MISMATCH!>x<!> : Int
}
x : Int
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
}
fun doWhileLoop(x: Int?) {
@@ -15,7 +15,7 @@ fun doWhileLoop(x: Int?) {
} while (x == null)
<!TYPE_MISMATCH!>x<!> : Int
}
x : Int
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
}
fun whileLoopContinueInnerOuter(x: Int?) {
@@ -26,7 +26,7 @@ fun whileLoopContinueInnerOuter(x: Int?) {
}
<!TYPE_MISMATCH!>x<!> : Int
}
x : Int
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
}
x : Int
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
}
@@ -1,3 +1,4 @@
// !DIAGNOSTICS: -DEBUG_INFO_AUTOCAST
fun bar(x: Int) = x + 1
fun foo() {
@@ -6,7 +6,7 @@ fun foo() {
do {
bar(<!TYPE_MISMATCH!>x<!>)
} while (x == null)
bar(x)
bar(<!DEBUG_INFO_AUTOCAST!>x<!>)
val y: Int? = null
do {
@@ -4,7 +4,7 @@ fun simpleDoWhile(x: Int?, y0: Int) {
x : Int?
y++
} while (x!! == y)
x : Int
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
}
fun doWhileWithBreak(x: Int?, y0: Int) {
@@ -4,6 +4,6 @@ fun foo() {
val x: Int? = null
bar(x ?: 0)
if (x != null) bar(<!USELESS_ELVIS!>x<!> ?: x)
if (x != null) bar(<!USELESS_ELVIS!>x<!> ?: <!DEBUG_INFO_AUTOCAST!>x<!>)
bar(<!TYPE_MISMATCH!>x<!>)
}
@@ -9,16 +9,16 @@ fun foo() {
for (p in a) {
bar(<!TYPE_MISMATCH!>x<!>)
if (x == null) continue
bar(x)
bar(<!DEBUG_INFO_AUTOCAST!>x<!>)
for (q in a) {
bar(x)
if (<!SENSELESS_COMPARISON!>x == null<!>) bar(x)
bar(<!DEBUG_INFO_AUTOCAST!>x<!>)
if (<!SENSELESS_COMPARISON!>x == null<!>) bar(<!DEBUG_INFO_AUTOCAST!>x<!>)
}
}
for (p in a) {
bar(<!TYPE_MISMATCH!>x<!>)
if (x == null) break
bar(x)
bar(<!DEBUG_INFO_AUTOCAST!>x<!>)
}
}
@@ -1,6 +1,6 @@
fun foo(arr: Array<Int>?) {
for (x in arr!!) {
arr : Array<Int>
<!DEBUG_INFO_AUTOCAST!>arr<!> : Array<Int>
}
arr : Array<Int>
<!DEBUG_INFO_AUTOCAST!>arr<!> : Array<Int>
}
@@ -4,6 +4,6 @@ fun foo() {
val x: Int? = null
fun baz() = bar(<!TYPE_MISMATCH!>x<!>)
fun quux() = if (x != null) bar(x) else baz()
fun quuux() = bar(if (x == null) 0 else x)
fun quux() = if (x != null) bar(<!DEBUG_INFO_AUTOCAST!>x<!>) else baz()
fun quuux() = bar(if (x == null) 0 else <!DEBUG_INFO_AUTOCAST!>x<!>)
}
@@ -1,24 +1,24 @@
fun ifThen(x: Int?) {
if (x!! == 0) {
x : Int
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
}
x : Int
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
}
fun ifElse(x: Int?) {
if (x!! == 0) else {
x : Int
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
}
x : Int
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
}
fun ifThenElse(x: Int?) {
if (x!! == 0) {
x : Int
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
} else {
x : Int
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
}
x : Int
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
}
fun ifIs(x: Int?, cond: Boolean) {
@@ -3,27 +3,27 @@ fun bar(x: Int): Int = x + 1
fun foo() {
val x: Int? = null
bar(if (x == null) 0 else x)
bar(if (x == null) 0 else <!DEBUG_INFO_AUTOCAST!>x<!>)
if (x == null) {
bar(<!TYPE_MISMATCH!>x<!>)
return
} else {
bar(x)
bar(<!DEBUG_INFO_AUTOCAST!>x<!>)
}
bar(x)
bar(<!DEBUG_INFO_AUTOCAST!>x<!>)
val y: Int? = null
if (y is Int) {
bar(y)
bar(<!DEBUG_INFO_AUTOCAST!>y<!>)
} else {
bar(<!TYPE_MISMATCH!>y<!>)
return
}
bar(y)
bar(<!DEBUG_INFO_AUTOCAST!>y<!>)
val z: Int? = null
if (z != null) bar(z)
if (z != null) bar(<!DEBUG_INFO_AUTOCAST!>z<!>)
bar(<!TYPE_MISMATCH!>z<!>)
bar(z!!)
if (<!SENSELESS_COMPARISON!>z != null<!>) bar(z<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>)
@@ -12,5 +12,5 @@ fun foo() {
if (<!SENSELESS_COMPARISON!>x == null<!>) return
2<!OVERLOAD_RESOLUTION_AMBIGUITY!>+<!><!SYNTAX!><!>
}
bar(x)
bar(<!DEBUG_INFO_AUTOCAST!>x<!>)
}
@@ -1,6 +1,6 @@
fun foo(x: Number) {
if ((x as Int) is Int) {
x : Int
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
}
x : Int
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
}
@@ -2,6 +2,6 @@ fun Int.component1() = "a"
fun foo(a: Number) {
val (x) = a as Int
a : Int
<!DEBUG_INFO_AUTOCAST!>a<!> : Int
x : String
}
@@ -4,7 +4,7 @@ fun foo() {
val x: Int? = null
val <!UNUSED_VARIABLE!>a<!> = object {
fun baz() = bar(if (x == null) 0 else x)
fun quux(): Int = if (x == null) <!TYPE_MISMATCH!>x<!> else x
fun baz() = bar(if (x == null) 0 else <!DEBUG_INFO_AUTOCAST!>x<!>)
fun quux(): Int = if (x == null) <!TYPE_MISMATCH!>x<!> else <!DEBUG_INFO_AUTOCAST!>x<!>
}
}
@@ -9,5 +9,5 @@ fun foo() {
A().bar(<!TYPE_MISMATCH!>x<!>)
if (x == null) return
A().bar(x)
A().bar(<!DEBUG_INFO_AUTOCAST!>x<!>)
}
@@ -1,3 +1,4 @@
// !DIAGNOSTICS: -DEBUG_INFO_AUTOCAST
fun bar(x: Int): Int = x + 1
fun foo(): Int {
@@ -1,6 +1,6 @@
fun foo(x: Number, y: String?): String {
val result = "abcde $x ${x as Int} ${y!!} $x $y"
x : Int
y : String
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
<!DEBUG_INFO_AUTOCAST!>y<!> : String
return result
}
@@ -11,11 +11,11 @@ class Derived : Base() {
super.bar(<!TYPE_MISMATCH!>x<!>)
this.baz(<!TYPE_MISMATCH!>x<!>)
if (x == null) return
super.bar(x)
this.baz(x)
super.bar(<!DEBUG_INFO_AUTOCAST!>x<!>)
this.baz(<!DEBUG_INFO_AUTOCAST!>x<!>)
val y: Int? = null
if (y != null) super.bar(this.baz(y))
if (y != null) super.bar(this.baz(<!DEBUG_INFO_AUTOCAST!>y<!>))
else this.baz(super.bar(<!TYPE_MISMATCH!>y<!>))
}
}
@@ -4,6 +4,6 @@ fun foo() {
val x: Int? = null
if (x == null) throw bar(<!TYPE_MISMATCH!>x<!>)
throw bar(x)
<!UNREACHABLE_CODE!>throw bar(x)<!>
throw bar(<!DEBUG_INFO_AUTOCAST!>x<!>)
<!UNREACHABLE_CODE!>throw bar(<!DEBUG_INFO_AUTOCAST!>x<!>)<!>
}
@@ -6,10 +6,10 @@ fun foo() {
bar(<!TYPE_MISMATCH!>x<!>)
if (x == null) return
try {
bar(x)
bar(<!DEBUG_INFO_AUTOCAST!>x<!>)
}
catch (e: Exception) {
bar(x)
bar(<!DEBUG_INFO_AUTOCAST!>x<!>)
}
bar(x)
bar(<!DEBUG_INFO_AUTOCAST!>x<!>)
}
@@ -3,7 +3,7 @@ fun tryFinally(x: Int?) {
} finally {
x!!
}
x : Int
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
}
fun tryCatchFinally(x: Int?) {
@@ -15,5 +15,5 @@ fun tryCatchFinally(x: Int?) {
<!TYPE_MISMATCH!>x<!> : Int
x!!
}
x : Int
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
}
@@ -5,10 +5,10 @@ fun foo() {
val x: Int? = null
bar(<!UNSAFE_CALL!>-<!>x)
if (x != null) bar(-x)
if (x != null) bar(-<!DEBUG_INFO_AUTOCAST!>x<!>)
bar(<!UNSAFE_CALL!>-<!>x)
val b: Boolean? = null
baz(<!UNSAFE_CALL!>!<!>b)
if (b != null) baz(!b)
if (b != null) baz(!<!DEBUG_INFO_AUTOCAST!>b<!>)
}
@@ -5,7 +5,7 @@ fun foo() {
if (x != null) {
when (x) {
0 -> bar(x)
0 -> bar(<!DEBUG_INFO_AUTOCAST!>x<!>)
else -> {}
}
}
@@ -14,5 +14,5 @@ fun foo() {
0 -> { if (<!SENSELESS_COMPARISON!>x == null<!>) return }
else -> { if (x == null) return }
}
bar(x)
bar(<!DEBUG_INFO_AUTOCAST!>x<!>)
}
@@ -1,6 +1,6 @@
fun foo(x: Number, y: Int) {
when (x) {
x as Int -> x : Int
x as Int -> <!DEBUG_INFO_AUTOCAST!>x<!> : Int
y -> {}
else -> {}
}
@@ -9,16 +9,16 @@ fun foo(x: Number, y: Int) {
fun bar(x: Number) {
when (x) {
x as Int -> x : Int
x as Int -> <!DEBUG_INFO_AUTOCAST!>x<!> : Int
else -> {}
}
x : Int
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
}
fun whenWithoutSubject(x: Number) {
when {
(x as Int) == 42 -> x : Int
(x as Int) == 42 -> <!DEBUG_INFO_AUTOCAST!>x<!> : Int
else -> {}
}
x : Int
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
}
@@ -1,13 +1,13 @@
fun foo(x: Int, list: List<Int>?) {
when (x) {
in list!! -> list : List<Int>
in list!! -> <!DEBUG_INFO_AUTOCAST!>list<!> : List<Int>
else -> {}
}
}
fun whenWithoutSubject(x: Int, list: List<Int>?) {
when {
x in list!! -> list : List<Int>
x in list!! -> <!DEBUG_INFO_AUTOCAST!>list<!> : List<Int>
else -> {}
}
}
@@ -1,6 +1,6 @@
fun foo(x: Number) {
when (x as Int) {
else -> x : Int
else -> <!DEBUG_INFO_AUTOCAST!>x<!> : Int
}
x : Int
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
}
@@ -5,11 +5,11 @@ fun foo() {
while (x == null) {
bar(<!TYPE_MISMATCH!>x<!>)
}
bar(x)
bar(<!DEBUG_INFO_AUTOCAST!>x<!>)
val y: Int? = null
while (y != null) {
bar(y)
bar(<!DEBUG_INFO_AUTOCAST!>y<!>)
}
bar(<!TYPE_MISMATCH!>y<!>)
@@ -1,19 +1,19 @@
fun simpleWhile(x: Int?, y0: Int) {
var y = y0
while (x!! == y) {
x : Int
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
y++
}
x : Int
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
}
fun whileWithBreak(x: Int?, y0: Int) {
var y = y0
while (x!! == y) {
x : Int
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
break
}
x : Int
<!DEBUG_INFO_AUTOCAST!>x<!> : Int
}
fun whileWithNoCondition(x: Int?) {
@@ -5,10 +5,10 @@ class A {
fun a(aa : A?, b : Any) {
if (aa != null) {
val (<!UNUSED_VARIABLE!>a1<!>, <!UNUSED_VARIABLE!>b1<!>) = aa;
val (<!UNUSED_VARIABLE!>a1<!>, <!UNUSED_VARIABLE!>b1<!>) = <!DEBUG_INFO_AUTOCAST!>aa<!>;
}
if (b is A) {
val (<!UNUSED_VARIABLE!>a1<!>, <!UNUSED_VARIABLE!>b1<!>) = b;
val (<!UNUSED_VARIABLE!>a1<!>, <!UNUSED_VARIABLE!>b1<!>) = <!DEBUG_INFO_AUTOCAST!>b<!>;
}
}
@@ -2,10 +2,10 @@ package m
fun test(i: Int?) {
if (i != null) {
foo(@l1 i)
foo((i))
foo(@l2 (i))
foo((@l3 i))
foo(@l1 <!DEBUG_INFO_AUTOCAST!>i<!>)
foo((<!DEBUG_INFO_AUTOCAST!>i<!>))
foo(@l2 (<!DEBUG_INFO_AUTOCAST!>i<!>))
foo((@l3 <!DEBUG_INFO_AUTOCAST!>i<!>))
}
val a: Int = @l4 <!TYPE_MISMATCH!>""<!>
@@ -4,10 +4,10 @@
import java.io.*
inline val InputStream.buffered : BufferedInputStream
get() = if(this is BufferedInputStream) this else BufferedInputStream(this)
get() = if(this is BufferedInputStream) <!DEBUG_INFO_AUTOCAST!>this<!> else BufferedInputStream(this)
inline val Reader.buffered : BufferedReader
get() = if(this is BufferedReader) this else BufferedReader(this)
get() = if(this is BufferedReader) <!DEBUG_INFO_AUTOCAST!>this<!> else BufferedReader(this)
//more tests
@@ -1,3 +1,4 @@
// !DIAGNOSTICS: -DEBUG_INFO_AUTOCAST
package a
import java.util.Date
@@ -3,8 +3,8 @@ package d
fun bar(a: Any?) {
if (a != null) {
a.foo() //overload resolution ambiguity
a.sure() //overload resolution ambiguity
<!DEBUG_INFO_AUTOCAST!>a<!>.foo() //overload resolution ambiguity
<!DEBUG_INFO_AUTOCAST!>a<!>.sure() //overload resolution ambiguity
}
}
@@ -11,8 +11,8 @@ fun f9(init : A?) {
a?.foo()
a?.<!UNRESOLVED_REFERENCE!>bar<!>()
if (a is B) {
a.bar()
a.foo()
<!DEBUG_INFO_AUTOCAST!>a<!>.bar()
<!DEBUG_INFO_AUTOCAST!>a<!>.foo()
}
a?.foo()
a?.<!UNRESOLVED_REFERENCE!>bar<!>()
@@ -20,14 +20,14 @@ fun f9(init : A?) {
a?.<!UNRESOLVED_REFERENCE!>bar<!>()
a?.foo()
}
if (!(a is B) || a.bar() == Unit.VALUE) {
if (!(a is B) || <!DEBUG_INFO_AUTOCAST!>a<!>.bar() == Unit.VALUE) {
a?.<!UNRESOLVED_REFERENCE!>bar<!>()
}
if (!(a is B)) {
return;
}
a.bar()
a.foo()
<!DEBUG_INFO_AUTOCAST!>a<!>.bar()
<!DEBUG_INFO_AUTOCAST!>a<!>.foo()
}
fun f10(init : A?) {
@@ -48,15 +48,15 @@ class C() : A() {
fun f101(a : A?) {
if (a is C) {
a.bar();
<!DEBUG_INFO_AUTOCAST!>a<!>.bar();
}
}
fun f11(a : A?) {
when (a) {
is B -> a.bar()
is A -> a.foo()
is Any -> a.foo()
is B -> <!DEBUG_INFO_AUTOCAST!>a<!>.bar()
is A -> <!DEBUG_INFO_AUTOCAST!>a<!>.foo()
is Any -> <!DEBUG_INFO_AUTOCAST!>a<!>.foo()
is Any? -> a.<!UNRESOLVED_REFERENCE!>bar<!>()
else -> a?.foo()
}
@@ -64,11 +64,11 @@ fun f11(a : A?) {
fun f12(a : A?) {
when (a) {
is B -> a.bar()
is A -> a.foo()
is Any -> a.foo();
is B -> <!DEBUG_INFO_AUTOCAST!>a<!>.bar()
is A -> <!DEBUG_INFO_AUTOCAST!>a<!>.foo()
is Any -> <!DEBUG_INFO_AUTOCAST!>a<!>.foo();
is Any? -> a.<!UNRESOLVED_REFERENCE!>bar<!>()
is C -> a.bar()
is C -> <!DEBUG_INFO_AUTOCAST!>a<!>.bar()
else -> a?.foo()
}
@@ -76,15 +76,15 @@ fun f12(a : A?) {
a?.<!UNRESOLVED_REFERENCE!>bar<!>()
}
if (a is B) {
a.foo()
a.bar()
<!DEBUG_INFO_AUTOCAST!>a<!>.foo()
<!DEBUG_INFO_AUTOCAST!>a<!>.bar()
}
}
fun f13(a : A?) {
if (a is B) {
a.foo()
a.bar()
<!DEBUG_INFO_AUTOCAST!>a<!>.foo()
<!DEBUG_INFO_AUTOCAST!>a<!>.bar()
}
else {
a?.foo()
@@ -97,14 +97,14 @@ fun f13(a : A?) {
<!UNRESOLVED_REFERENCE!>c<!>.<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>bar<!>()
}
else {
a.foo()
<!DEBUG_INFO_AUTOCAST!>a<!>.foo()
<!UNRESOLVED_REFERENCE!>c<!>.<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>bar<!>()
}
a?.foo()
if (a is B && a.foo() == Unit.VALUE) {
a.foo()
a.bar()
if (a is B && <!DEBUG_INFO_AUTOCAST!>a<!>.foo() == Unit.VALUE) {
<!DEBUG_INFO_AUTOCAST!>a<!>.foo()
<!DEBUG_INFO_AUTOCAST!>a<!>.bar()
}
else {
a?.foo()
@@ -120,70 +120,70 @@ fun f13(a : A?) {
}
if (!(a is B)) return
a.bar()
<!DEBUG_INFO_AUTOCAST!>a<!>.bar()
}
fun f14(a : A?) {
while (!(a is B)) {
}
a.bar()
<!DEBUG_INFO_AUTOCAST!>a<!>.bar()
}
fun f15(a : A?) {
do {
} while (!(a is B))
a.bar()
<!DEBUG_INFO_AUTOCAST!>a<!>.bar()
}
fun getStringLength(obj : Any) : Char? {
if (obj !is String)
return null
return obj.get(0) // no cast to String is needed
return <!DEBUG_INFO_AUTOCAST!>obj<!>.get(0) // no cast to String is needed
}
fun toInt(i: Int?): Int = if (i != null) i else 0
fun toInt(i: Int?): Int = if (i != null) <!DEBUG_INFO_AUTOCAST!>i<!> else 0
fun illegalWhenBody(a: Any): Int = <!NO_ELSE_IN_WHEN!>when<!>(a) {
is Int -> a
is Int -> <!DEBUG_INFO_AUTOCAST!>a<!>
is String -> <!TYPE_MISMATCH!>a<!>
}
fun illegalWhenBlock(a: Any): Int {
when(a) {
is Int -> return a
is Int -> return <!DEBUG_INFO_AUTOCAST!>a<!>
is String -> return <!TYPE_MISMATCH!>a<!>
}
<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
fun declarations(a: Any?) {
if (a is String) {
val <!UNUSED_VARIABLE!>p4<!>: String = a
val <!UNUSED_VARIABLE!>p4<!>: String = <!DEBUG_INFO_AUTOCAST!>a<!>
}
if (a is String?) {
if (a != null) {
val <!UNUSED_VARIABLE!>s<!>: String = a
val <!UNUSED_VARIABLE!>s<!>: String = <!DEBUG_INFO_AUTOCAST!>a<!>
}
}
if (a != null) {
if (a is String?) {
val <!UNUSED_VARIABLE!>s<!>: String = a
val <!UNUSED_VARIABLE!>s<!>: String = <!DEBUG_INFO_AUTOCAST!>a<!>
}
}
}
fun vars(a: Any?) {
var <!ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE!>b<!>: Int = 0
if (a is Int) {
b = <!UNUSED_VALUE!>a<!>
b = <!UNUSED_VALUE, DEBUG_INFO_AUTOCAST!>a<!>
}
}
fun returnFunctionLiteralBlock(a: Any?): Function0<Int> {
if (a is Int) return { a }
if (a is Int) return { <!DEBUG_INFO_AUTOCAST!>a<!> }
else return { 1 }
}
fun returnFunctionLiteral(a: Any?): Function0<Int> =
if (a is Int) { (): Int -> a }
if (a is Int) { (): Int -> <!DEBUG_INFO_AUTOCAST!>a<!> }
else { () -> 1 }
fun mergeAutocasts(a: Any?) {
if (a is String || a is Int) {
a.<!UNRESOLVED_REFERENCE!>compareTo<!>("")
a.toString()
<!DEBUG_INFO_AUTOCAST!>a<!>.toString()
}
if (a is Int || a is String) {
a.<!UNRESOLVED_REFERENCE!>compareTo<!>("")
@@ -192,9 +192,9 @@ fun mergeAutocasts(a: Any?) {
is String, is Any -> a.<!UNRESOLVED_REFERENCE!>compareTo<!>("")
}
if (a is String && a is Any) {
val <!UNUSED_VARIABLE!>i<!>: Int = a.compareTo("")
val <!UNUSED_VARIABLE!>i<!>: Int = <!DEBUG_INFO_AUTOCAST!>a<!>.compareTo("")
}
if (a is String && a.compareTo("") == 0) {}
if (a is String && <!DEBUG_INFO_AUTOCAST!>a<!>.compareTo("") == 0) {}
if (a is String || a.<!UNRESOLVED_REFERENCE!>compareTo<!>("") <!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>==<!> 0) {}
}
@@ -9,7 +9,7 @@ fun bar(any: Any): <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>java.lang.Iterable<Int><!>
val <!UNUSED_VARIABLE!>c<!> : <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>Iterator<String><!>? = null
if (any is <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>Iterator<*><!>) {
any : <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>Iterator<*><!>
<!DEBUG_INFO_AUTOCAST!>any<!> : <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>Iterator<*><!>
}
any as <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>Iterator<*><!>
return null
@@ -2,7 +2,7 @@ fun test() {
val out : Int? = null
val x : Nothing? = null
if (out != x)
out.plus(1)
<!DEBUG_INFO_AUTOCAST!>out<!>.plus(1)
if (out == x) return
out.plus(1)
<!DEBUG_INFO_AUTOCAST!>out<!>.plus(1)
}
@@ -1,3 +1,4 @@
// !DIAGNOSTICS: -DEBUG_INFO_AUTOCAST
class Foo {
fun foo(a: Foo): Foo = a
}
@@ -5,7 +5,7 @@ fun bar() {
val i: Int? = 42
if (i != null) {
<!OVERLOAD_RESOLUTION_AMBIGUITY!>doSmth1<!> {
val x = i + 1
val x = <!DEBUG_INFO_AUTOCAST!>i<!> + 1
}
}
}
@@ -4,7 +4,7 @@ fun foo() {
val i : Int? = 42
if (i != null) {
<!UNRESOLVED_REFERENCE!>doSmth<!> {
val <!UNUSED_VARIABLE!>x<!> = i + 1
val <!UNUSED_VARIABLE!>x<!> = <!DEBUG_INFO_AUTOCAST!>i<!> + 1
}
}
}
@@ -4,8 +4,8 @@ package kt1778
fun main(args : Array<String>) {
val x = args[0]: Any
if(x is <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>java.lang.CharSequence<!>) {
if ("a" == x) x.length() else x.length() // OK
if ("a" == x || "b" == x) x.length() else x.length() // < THEN ERROR
if ("a" == x && "a" == x) x.length() else x.length() // < ELSE ERROR
if ("a" == x) <!DEBUG_INFO_AUTOCAST!>x<!>.length() else <!DEBUG_INFO_AUTOCAST!>x<!>.length() // OK
if ("a" == x || "b" == x) <!DEBUG_INFO_AUTOCAST!>x<!>.length() else <!DEBUG_INFO_AUTOCAST!>x<!>.length() // < THEN ERROR
if ("a" == x && "a" == x) <!DEBUG_INFO_AUTOCAST!>x<!>.length() else <!DEBUG_INFO_AUTOCAST!>x<!>.length() // < ELSE ERROR
}
}
@@ -4,35 +4,35 @@ package kt2146
fun f1(s: Int?): Int {
return when (s) {
null -> 3
else -> s
else -> <!DEBUG_INFO_AUTOCAST!>s<!>
}
}
fun f2(s: Int?): Int {
return when (s) {
!is Int -> <!TYPE_MISMATCH!>s<!>
else -> s
else -> <!DEBUG_INFO_AUTOCAST!>s<!>
}
}
fun f3(s: Int?): Int {
return when (s) {
is Int -> s
is Int -> <!DEBUG_INFO_AUTOCAST!>s<!>
else -> <!TYPE_MISMATCH!>s<!>
}
}
fun f4(s: Int?): Int {
return when {
s == 4 -> s
s == 4 -> <!DEBUG_INFO_AUTOCAST!>s<!>
s == null -> <!TYPE_MISMATCH!>s<!>
else -> s
else -> <!DEBUG_INFO_AUTOCAST!>s<!>
}
}
fun f5(s: Int?): Int {
return when (s) {
s!! -> s
s!! -> <!DEBUG_INFO_AUTOCAST!>s<!>
s -> <!TYPE_MISMATCH!>s<!>
else -> 0
}
@@ -40,7 +40,7 @@ fun f5(s: Int?): Int {
fun f6(s: Int?): Int {
return when {
s is Int -> s
s is Int -> <!DEBUG_INFO_AUTOCAST!>s<!>
else -> <!TYPE_MISMATCH!>s<!>
}
}
@@ -48,6 +48,6 @@ fun f6(s: Int?): Int {
fun f7(s: Int?): Int {
return when {
s !is Int -> <!TYPE_MISMATCH!>s<!>
else -> s
else -> <!DEBUG_INFO_AUTOCAST!>s<!>
}
}
@@ -9,30 +9,30 @@ fun main(args : Array<String>) {
foo(<!TYPE_MISMATCH!>x<!>)
if (x != null) {
foo(x)
foo(<!DEBUG_INFO_AUTOCAST!>x<!>)
foo(x<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>)
foo(x)
foo(<!DEBUG_INFO_AUTOCAST!>x<!>)
}
foo(<!TYPE_MISMATCH!>x<!>)
if (x != null) {
foo(x)
foo(<!DEBUG_INFO_AUTOCAST!>x<!>)
foo(x<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>)
foo(x)
foo(<!DEBUG_INFO_AUTOCAST!>x<!>)
} else {
foo(<!TYPE_MISMATCH!>x<!>)
foo(x!!)
foo(x)
foo(<!DEBUG_INFO_AUTOCAST!>x<!>)
}
foo(x)
foo(<!DEBUG_INFO_AUTOCAST!>x<!>)
foo(x<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>)
foo(x)
foo(<!DEBUG_INFO_AUTOCAST!>x<!>)
val y: Int? = null
y!!
y<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
foo(y)
foo(<!DEBUG_INFO_AUTOCAST!>y<!>)
foo(y<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>)
}
@@ -3,7 +3,7 @@ package kt2176
fun f1(a: String?) {
a!!
a: String
<!DEBUG_INFO_AUTOCAST!>a<!>: String
}
fun f2(a: String) {
@@ -13,12 +13,12 @@ fun f2(a: String) {
fun f3(a: Any?) {
a as String
a: String
<!DEBUG_INFO_AUTOCAST!>a<!>: String
}
fun f4(a: Any) {
a as String
a: String
<!DEBUG_INFO_AUTOCAST!>a<!>: String
}
fun f5(a: String) {
@@ -3,6 +3,6 @@ package foo
private fun sendCommand<T>(errorCallback: (()->Unit)? = null) {
if (errorCallback != null) {
errorCallback()
<!DEBUG_INFO_AUTOCAST!>errorCallback<!>()
}
}
@@ -4,5 +4,5 @@ package kt2212
fun main(args: Array<String>) {
val x: Int? = 1
if (x == null) return
System.out.println(x.plus(x<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>))
System.out.println(<!DEBUG_INFO_AUTOCAST!>x<!>.plus(x<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>))
}
@@ -1,3 +1,4 @@
// !DIAGNOSTICS: -DEBUG_INFO_AUTOCAST
//KT-2216 Nullability of a value determined in function parameter computation doesn't pass to code following
package kt2216
@@ -8,14 +8,14 @@ fun main(args : Array<String>) {
val d : Long = 1
val period : Int? = null
if (period != null) Pair(d, period<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!> : Int) else Pair(d, 1)
if (period != null) Pair(d, period : Int) else Pair(d, 1)
if (period != null) Pair(d, <!DEBUG_INFO_AUTOCAST!>period<!> : Int) else Pair(d, 1)
}
fun foo() {
val x : Int? = 3
if (x != null) {
val <!UNUSED_VARIABLE!>u<!> = x<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!> : Int
val y = x : Int
val y = <!DEBUG_INFO_AUTOCAST!>x<!> : Int
val <!UNUSED_VARIABLE!>z<!> : Int = y
}
}
@@ -5,18 +5,18 @@ package kt244
fun f(s: String?) {
if (s != null) {
s.length //ok
var <!UNUSED_VARIABLE!>i<!> = s.length //error: Only safe calls are allowed on a nullable receiver
System.out.println(s.length) //error
<!DEBUG_INFO_AUTOCAST!>s<!>.length //ok
var <!UNUSED_VARIABLE!>i<!> = <!DEBUG_INFO_AUTOCAST!>s<!>.length //error: Only safe calls are allowed on a nullable receiver
System.out.println(<!DEBUG_INFO_AUTOCAST!>s<!>.length) //error
}
}
// more tests
class A(a: String?) {
val b = if (a != null) a.length else 1
val b = if (a != null) <!DEBUG_INFO_AUTOCAST!>a<!>.length else 1
{
if (a != null) {
val c = a.length
val c = <!DEBUG_INFO_AUTOCAST!>a<!>.length
}
}
@@ -24,7 +24,7 @@ class A(a: String?) {
{
if (a is String) {
i = a.length
i = <!DEBUG_INFO_AUTOCAST!>a<!>.length
}
else {
i = 3
@@ -7,11 +7,11 @@ fun test() {
val p = test.Public()
if (p.public is Int) <!AUTOCAST_IMPOSSIBLE!>p.public<!> + 1
if (p.<!INVISIBLE_MEMBER!>protected<!> is Int) <!AUTOCAST_IMPOSSIBLE!>p.<!INVISIBLE_MEMBER!>protected<!><!> + 1
if (p.internal is Int) p.internal + 1
if (p.internal is Int) <!DEBUG_INFO_AUTOCAST!>p.internal<!> + 1
val i = test.Internal()
if (i.public is Int) i.public + 1
if (i.<!INVISIBLE_MEMBER!>protected<!> is Int) i.<!INVISIBLE_MEMBER!>protected<!> + 1
if (i.internal is Int) i.internal + 1
if (i.public is Int) <!DEBUG_INFO_AUTOCAST!>i.public<!> + 1
if (i.<!INVISIBLE_MEMBER!>protected<!> is Int) <!DEBUG_INFO_AUTOCAST!>i.<!INVISIBLE_MEMBER!>protected<!><!> + 1
if (i.internal is Int) <!DEBUG_INFO_AUTOCAST!>i.internal<!> + 1
}
// FILE: other.kt
@@ -1,8 +1,8 @@
fun set(<!UNUSED_PARAMETER!>key<!> : String, <!UNUSED_PARAMETER!>value<!> : String) {
val a : String? = ""
when (a) {
"" -> a.get(0)
is String, is Any -> a.compareTo("")
"" -> <!DEBUG_INFO_AUTOCAST!>a<!>.get(0)
is String, is Any -> <!DEBUG_INFO_AUTOCAST!>a<!>.compareTo("")
else -> a.toString()
}
}
@@ -2,6 +2,6 @@
trait Tree {}
fun Any?.TreeValue() : Tree {
if (this is Tree) return this
if (this is Tree) return <!DEBUG_INFO_AUTOCAST!>this<!>
throw Exception()
}
@@ -1,6 +1,6 @@
// 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 <T : Any> T?.npe() : T = if (this == null) throw NullPointerException() else <!DEBUG_INFO_AUTOCAST!>this<!>
fun foo() {
val i : Int? = 1
@@ -7,5 +7,5 @@ fun <T> Iterable<T>.join(separator : String?) : String {
fun <T : Any> T?.npe() : T {
if (this == null)
throw NullPointerException()
return this;
return <!DEBUG_INFO_AUTOCAST!>this<!>;
}
@@ -22,6 +22,6 @@ fun doSmth(<!UNUSED_PARAMETER!>a<!>: String) {}
val testIt : (Any) -> Unit = {
if (it is String) {
doSmth(it)
doSmth(<!DEBUG_INFO_AUTOCAST!>it<!>)
}
}

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