Add some test cases after review

This commit is contained in:
Denis Zharkov
2015-08-27 17:45:02 +03:00
parent 00a78fce0c
commit 5e09a0c2c9
10 changed files with 182 additions and 11 deletions
@@ -0,0 +1,13 @@
fun <E : String?, T : ((CharSequence).() -> Unit)?> foo(x: E, y: T) {
if (x != null) {
<!DEBUG_INFO_SMARTCAST!>x<!>.<!UNSAFE_CALL!>y<!>()
}
if (y != null) {
x<!UNSAFE_CALL!>.<!><!DEBUG_INFO_SMARTCAST!>y<!>()
}
if (x != null && y != null) {
<!DEBUG_INFO_SMARTCAST!>x<!>.<!DEBUG_INFO_SMARTCAST!>y<!>()
}
}
@@ -0,0 +1,3 @@
package
internal fun </*0*/ E : kotlin.String?, /*1*/ T : (kotlin.CharSequence.() -> kotlin.Unit)?> foo(/*0*/ x: E, /*1*/ y: T): kotlin.Unit
@@ -0,0 +1,13 @@
fun <T : Any?> foo(x: T) {
if (x is String<!USELESS_NULLABLE_CHECK!>?<!>) {
x<!UNSAFE_CALL!>.<!>length()
if (x != null) {
<!DEBUG_INFO_SMARTCAST!>x<!>.length()
}
}
if (x is String) {
<!DEBUG_INFO_SMARTCAST!>x<!>.length()
}
}
@@ -0,0 +1,3 @@
package
internal fun </*0*/ T> foo(/*0*/ x: T): kotlin.Unit
@@ -14,6 +14,7 @@ fun <T : CharSequence?> foo(x: T) {
y2 = <!TYPE_MISMATCH!>x<!>
<!TYPE_INFERENCE_UPPER_BOUND_VIOLATED!>bar1<!>(x)
bar1<CharSequence>(<!DEBUG_INFO_SMARTCAST!>x<!>)
bar2(<!DEBUG_INFO_SMARTCAST!>x<!>)
bar3(<!TYPE_MISMATCH!>x<!>)
}
@@ -39,6 +40,7 @@ fun <T : CharSequence?> foo(x: T) {
if (1 == 1) {
val y = x!!
<!TYPE_INFERENCE_UPPER_BOUND_VIOLATED!>bar1<!>(x)
bar1<CharSequence>(<!DEBUG_INFO_SMARTCAST!>x<!>)
bar2(<!DEBUG_INFO_SMARTCAST!>x<!>)
bar3(<!TYPE_MISMATCH!>x<!>)
@@ -1,31 +1,48 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER, -BASE_WITH_NULLABLE_UPPER_BOUND
// !CHECK_TYPE
// !DIAGNOSTICS: -UNUSED_PARAMETER, -BASE_WITH_NULLABLE_UPPER_BOUND, -UNUSED_VARIABLE
class A<F> {
fun <E : F> foo1(x: E) {}
fun <E : F?> foo2(x: E) {}
fun <E : F> foo1(x: E) = x
fun <E : F?> foo2(x: E) = x
fun <Z : F, W : Z?> bar(x: F, y: F?, z: Z, w: W) {
foo1<F>(x)
foo1(x)
val x1 = foo1(x)
x1.checkType { _<F>() }
foo2<F>(x)
foo2(x)
val x2 = foo2(x)
x2.checkType { _<F>() }
foo1<<!UPPER_BOUND_VIOLATED!>F?<!>>(y)
<!TYPE_INFERENCE_UPPER_BOUND_VIOLATED!>foo1<!>(y)
foo2<F?>(y)
foo2(y)
val x3 = foo2(y)
x3.checkType { _<F?>() }
foo1<F>(<!TYPE_MISMATCH!>y<!>)
foo2<F>(<!TYPE_MISMATCH!>y<!>)
foo1<Z>(z)
foo1(z)
val x4 = foo1(z)
x4.checkType { _<Z>() }
foo2<Z>(z)
foo2(z)
val x5 = foo2(z)
x4.checkType { _<Z>() }
foo1<<!UPPER_BOUND_VIOLATED!>W<!>>(w)
<!TYPE_INFERENCE_UPPER_BOUND_VIOLATED!>foo1<!>(w)
foo2<W>(w)
foo2(w)
val x6 = foo2(w)
x6.checkType { _<W>() }
foo1<<!UPPER_BOUND_VIOLATED!>W<!>>(w)
}
}
@@ -4,8 +4,8 @@ internal final class A</*0*/ F> {
public constructor A</*0*/ F>()
internal final fun </*0*/ Z : F, /*1*/ W : Z?> bar(/*0*/ x: F, /*1*/ y: F?, /*2*/ z: Z, /*3*/ w: W): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
internal final fun </*0*/ E : F> foo1(/*0*/ x: E): kotlin.Unit
internal final fun </*0*/ E : F?> foo2(/*0*/ x: E): kotlin.Unit
internal final fun </*0*/ E : F> foo1(/*0*/ x: E): E
internal final fun </*0*/ E : F?> foo2(/*0*/ x: E): E
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -0,0 +1,66 @@
// !CHECK_TYPE
// !DIAGNOSTICS: -UNUSED_PARAMETER, -BASE_WITH_NULLABLE_UPPER_BOUND, -UNUSED_VARIABLE
class A<F> {
class Inv<Q>
fun <E : Inv<F>> fooInv1(x: E) = x
fun <E : Inv<F?>> fooInv2(x: E) = x
class In<in Q>
fun <E : In<F>> fooIn1(x: E) = x
fun <E : In<F?>> fooIn2(x: E) = x
class Out<out Q>
fun <E : Out<F>> fooOut1(x: E) = x
fun <E : Out<F?>> fooOut2(x: E) = x
fun <Z : F, W : Z?> bar() {
// F
fooInv1<Inv<F>>(Inv<F>())
fooInv2<<!UPPER_BOUND_VIOLATED!>Inv<F><!>>(Inv<F>())
fooInv1(Inv<F>())
<!TYPE_INFERENCE_UPPER_BOUND_VIOLATED!>fooInv2<!>(Inv<F>())
fooIn1<In<F?>>(In<F?>())
fooIn2<In<F?>>(In<F?>())
fooIn1(In<F?>())
fooIn2(In<F?>())
fooOut1<Out<F>>(Out<F>())
fooOut2<Out<F>>(Out<F>())
fooOut1(Out<F>())
fooOut2(Out<F>())
// Z
fooInv1<<!UPPER_BOUND_VIOLATED!>Inv<Z><!>>(Inv<Z>())
fooInv2<<!UPPER_BOUND_VIOLATED!>Inv<Z><!>>(Inv<Z>())
<!TYPE_INFERENCE_UPPER_BOUND_VIOLATED!>fooInv1<!>(Inv<Z>())
<!TYPE_INFERENCE_UPPER_BOUND_VIOLATED!>fooInv2<!>(Inv<Z>())
fooIn1<<!UPPER_BOUND_VIOLATED!>In<Z?><!>>(In<Z?>())
fooIn2<<!UPPER_BOUND_VIOLATED!>In<Z?><!>>(In<Z?>())
<!TYPE_INFERENCE_UPPER_BOUND_VIOLATED!>fooIn1<!>(In<Z?>())
<!TYPE_INFERENCE_UPPER_BOUND_VIOLATED!>fooIn2<!>(In<Z?>())
fooOut1<Out<Z>>(Out<Z>())
fooOut2<Out<Z>>(Out<Z>())
fooOut1(Out<Z>())
fooOut2(Out<Z>())
// W
fooInv1<<!UPPER_BOUND_VIOLATED!>Inv<W><!>>(Inv<W>())
fooInv2<<!UPPER_BOUND_VIOLATED!>Inv<W><!>>(Inv<W>())
<!TYPE_INFERENCE_UPPER_BOUND_VIOLATED!>fooInv1<!>(Inv<W>())
<!TYPE_INFERENCE_UPPER_BOUND_VIOLATED!>fooInv2<!>(Inv<W>())
fooIn1<<!UPPER_BOUND_VIOLATED!>In<W?><!>>(In<W?>())
fooIn2<<!UPPER_BOUND_VIOLATED!>In<W?><!>>(In<W?>())
<!TYPE_INFERENCE_UPPER_BOUND_VIOLATED!>fooIn1<!>(In<W?>())
<!TYPE_INFERENCE_UPPER_BOUND_VIOLATED!>fooIn2<!>(In<W?>())
fooOut1<<!UPPER_BOUND_VIOLATED!>Out<W><!>>(Out<W>())
fooOut2<Out<W>>(Out<W>())
<!TYPE_INFERENCE_UPPER_BOUND_VIOLATED!>fooOut1<!>(Out<W>())
fooOut2(Out<W>())
}
}
@@ -0,0 +1,36 @@
package
internal final class A</*0*/ F> {
public constructor A</*0*/ F>()
internal final fun </*0*/ Z : F, /*1*/ W : Z?> bar(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
internal final fun </*0*/ E : A.In<F>> fooIn1(/*0*/ x: E): E
internal final fun </*0*/ E : A.In<F?>> fooIn2(/*0*/ x: E): E
internal final fun </*0*/ E : A.Inv<F>> fooInv1(/*0*/ x: E): E
internal final fun </*0*/ E : A.Inv<F?>> fooInv2(/*0*/ x: E): E
internal final fun </*0*/ E : A.Out<F>> fooOut1(/*0*/ x: E): E
internal final fun </*0*/ E : A.Out<F?>> fooOut2(/*0*/ x: E): E
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
internal final class In</*0*/ in Q> {
public constructor In</*0*/ in Q>()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
internal final class Inv</*0*/ Q> {
public constructor Inv</*0*/ Q>()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
internal final class Out</*0*/ out Q> {
public constructor Out</*0*/ out Q>()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
}
@@ -6149,12 +6149,24 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("functionalBound.kt")
public void testFunctionalBound() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/generics/nullability/functionalBound.kt");
doTest(fileName);
}
@TestMetadata("nullToGeneric.kt")
public void testNullToGeneric() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/generics/nullability/nullToGeneric.kt");
doTest(fileName);
}
@TestMetadata("smartCastRefinedClass.kt")
public void testSmartCastRefinedClass() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/generics/nullability/smartCastRefinedClass.kt");
doTest(fileName);
}
@TestMetadata("smartCasts.kt")
public void testSmartCasts() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/generics/nullability/smartCasts.kt");
@@ -6179,6 +6191,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("tpBoundsViolationVariance.kt")
public void testTpBoundsViolationVariance() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/generics/nullability/tpBoundsViolationVariance.kt");
doTest(fileName);
}
@TestMetadata("tpInBounds.kt")
public void testTpInBounds() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/generics/nullability/tpInBounds.kt");