Have "in type" for java fields to be able to check that type in assignment positions (against rhs' type)
^KT-46727 Fixed
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
// FILE: Foo.java
|
||||
public class Foo<T> {
|
||||
public T value;
|
||||
}
|
||||
|
||||
// FILE: Foo2.java
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class Foo2<T> {
|
||||
public @Nullable T value;
|
||||
}
|
||||
|
||||
// FILE: Foo3.java
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Foo3<T> {
|
||||
public @NotNull T value;
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
|
||||
// --- from Java --- //
|
||||
|
||||
fun takeStarFoo(x: Foo<*>) {
|
||||
x.value = <!ASSIGNMENT_TYPE_MISMATCH!>"test"<!>
|
||||
}
|
||||
|
||||
fun main1() {
|
||||
val foo = Foo<Int>()
|
||||
foo.value = 1
|
||||
takeStarFoo(foo)
|
||||
println(foo.value) // CCE: String cannot be cast to Number
|
||||
}
|
||||
|
||||
// --- from Kotlin --- //
|
||||
|
||||
public class Bar<T> {
|
||||
var value: T = null as T
|
||||
}
|
||||
|
||||
fun takeStarBar(x: Bar<*>) {
|
||||
<!SETTER_PROJECTED_OUT!>x.value<!> = "test"
|
||||
}
|
||||
|
||||
fun main2() {
|
||||
val bar = Bar<Int>()
|
||||
bar.value = 1
|
||||
takeStarBar(bar)
|
||||
println(bar.value) // CCE: String cannot be cast to Number
|
||||
}
|
||||
|
||||
// --- from Java (nullable) --- //
|
||||
|
||||
fun takeStarFoo2(x: Foo2<*>) {
|
||||
x.value = <!ASSIGNMENT_TYPE_MISMATCH!>"test"<!>
|
||||
}
|
||||
|
||||
fun main3() {
|
||||
val foo = Foo2<Int>()
|
||||
foo.value = 1
|
||||
takeStarFoo2(foo)
|
||||
println(foo.value) // CCE: String cannot be cast to Number
|
||||
}
|
||||
|
||||
// --- from Kotlin (nullable) --- //
|
||||
public class Bar2<T> {
|
||||
var value: T? = null
|
||||
}
|
||||
|
||||
fun takeStarBar2(x: Bar2<*>) {
|
||||
<!SETTER_PROJECTED_OUT!>x.value<!> = "test"
|
||||
}
|
||||
|
||||
fun main4() {
|
||||
val bar = Bar2<Int>()
|
||||
bar.value = 1
|
||||
takeStarBar2(bar)
|
||||
println(bar.value) // CCE: String cannot be cast to Number
|
||||
}
|
||||
|
||||
// --- from Java (not-null) --- //
|
||||
|
||||
fun takeStarFoo3(x: Foo3<*>) {
|
||||
x.value = <!ASSIGNMENT_TYPE_MISMATCH!>"test"<!>
|
||||
}
|
||||
|
||||
fun main5() {
|
||||
val foo = Foo3<Int>()
|
||||
foo.value = 1
|
||||
takeStarFoo3(foo)
|
||||
println(foo.value) // CCE: String cannot be cast to Number
|
||||
}
|
||||
|
||||
// --- from Kotlin (field) --- //
|
||||
class Bar3<T> {
|
||||
@JvmField
|
||||
var value: T? = null
|
||||
}
|
||||
|
||||
fun takeStarBar3(x: Bar3<*>) {
|
||||
<!SETTER_PROJECTED_OUT!>x.value<!> = "test"
|
||||
}
|
||||
|
||||
fun main6() {
|
||||
val bar = Bar3<Int>()
|
||||
bar.value = 1
|
||||
takeStarBar3(bar)
|
||||
println(bar.value) // CCE: String cannot be cast to Number
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
// FILE: Foo.java
|
||||
public class Foo<T> {
|
||||
public T value;
|
||||
}
|
||||
|
||||
// FILE: Foo2.java
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class Foo2<T> {
|
||||
public @Nullable T value;
|
||||
}
|
||||
|
||||
// FILE: Foo3.java
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Foo3<T> {
|
||||
public @NotNull T value;
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
|
||||
// --- from Java --- //
|
||||
|
||||
fun takeStarFoo(x: Foo<*>) {
|
||||
x.value = <!TYPE_MISMATCH("Nothing!; String")!>"test"<!>
|
||||
}
|
||||
|
||||
fun main1() {
|
||||
val foo = Foo<Int>()
|
||||
foo.value = 1
|
||||
takeStarFoo(foo)
|
||||
println(foo.value) // CCE: String cannot be cast to Number
|
||||
}
|
||||
|
||||
// --- from Kotlin --- //
|
||||
|
||||
public class Bar<T> {
|
||||
var value: T = null <!UNCHECKED_CAST!>as T<!>
|
||||
}
|
||||
|
||||
fun takeStarBar(x: Bar<*>) {
|
||||
<!SETTER_PROJECTED_OUT!>x.value<!> = "test"
|
||||
}
|
||||
|
||||
fun main2() {
|
||||
val bar = Bar<Int>()
|
||||
bar.value = 1
|
||||
takeStarBar(bar)
|
||||
println(bar.value) // CCE: String cannot be cast to Number
|
||||
}
|
||||
|
||||
// --- from Java (nullable) --- //
|
||||
|
||||
fun takeStarFoo2(x: Foo2<*>) {
|
||||
x.value = <!TYPE_MISMATCH("Nothing?; String")!>"test"<!>
|
||||
}
|
||||
|
||||
fun main3() {
|
||||
val foo = Foo2<Int>()
|
||||
foo.value = 1
|
||||
takeStarFoo2(foo)
|
||||
println(foo.value) // CCE: String cannot be cast to Number
|
||||
}
|
||||
|
||||
// --- from Kotlin (nullable) --- //
|
||||
public class Bar2<T> {
|
||||
var value: T? = null
|
||||
}
|
||||
|
||||
fun takeStarBar2(x: Bar2<*>) {
|
||||
x.value = <!TYPE_MISMATCH_DUE_TO_TYPE_PROJECTIONS("Nothing?; String; Bar2<CapturedType(*)>; public final var value: T? defined in Bar2")!>"test"<!>
|
||||
}
|
||||
|
||||
fun main4() {
|
||||
val bar = Bar2<Int>()
|
||||
bar.value = 1
|
||||
takeStarBar2(bar)
|
||||
println(bar.value) // CCE: String cannot be cast to Number
|
||||
}
|
||||
|
||||
// --- from Java (not-null) --- //
|
||||
|
||||
fun takeStarFoo3(x: Foo3<*>) {
|
||||
x.value = <!TYPE_MISMATCH("Nothing; String")!>"test"<!>
|
||||
}
|
||||
|
||||
fun main5() {
|
||||
val foo = Foo3<Int>()
|
||||
foo.value = 1
|
||||
takeStarFoo3(foo)
|
||||
println(foo.value) // CCE: String cannot be cast to Number
|
||||
}
|
||||
|
||||
// --- from Kotlin (field) --- //
|
||||
class Bar3<T> {
|
||||
@JvmField
|
||||
var value: T? = null
|
||||
}
|
||||
|
||||
fun takeStarBar3(x: Bar3<*>) {
|
||||
x.value = <!TYPE_MISMATCH_DUE_TO_TYPE_PROJECTIONS("Nothing?; String; Bar3<CapturedType(*)>; public final var value: T? defined in Bar3")!>"test"<!>
|
||||
}
|
||||
|
||||
fun main6() {
|
||||
val bar = Bar3<Int>()
|
||||
bar.value = 1
|
||||
takeStarBar3(bar)
|
||||
println(bar.value) // CCE: String cannot be cast to Number
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package
|
||||
|
||||
public fun main1(): kotlin.Unit
|
||||
public fun main2(): kotlin.Unit
|
||||
public fun main3(): kotlin.Unit
|
||||
public fun main4(): kotlin.Unit
|
||||
public fun main5(): kotlin.Unit
|
||||
public fun takeStarBar(/*0*/ x: Bar<*>): kotlin.Unit
|
||||
public fun takeStarBar2(/*0*/ x: Bar2<*>): kotlin.Unit
|
||||
public fun takeStarFoo(/*0*/ x: Foo<*>): kotlin.Unit
|
||||
public fun takeStarFoo2(/*0*/ x: Foo2<*>): kotlin.Unit
|
||||
public fun takeStarFoo3(/*0*/ x: Foo3<*>): kotlin.Unit
|
||||
|
||||
public final class Bar</*0*/ T> {
|
||||
public constructor Bar</*0*/ T>()
|
||||
public final var value: T
|
||||
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
|
||||
}
|
||||
|
||||
public final class Bar2</*0*/ T> {
|
||||
public constructor Bar2</*0*/ T>()
|
||||
public final var value: T?
|
||||
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
|
||||
}
|
||||
|
||||
public open class Foo</*0*/ T : kotlin.Any!> {
|
||||
public constructor Foo</*0*/ T : kotlin.Any!>()
|
||||
public final var value: T!
|
||||
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
|
||||
}
|
||||
|
||||
public open class Foo2</*0*/ T : kotlin.Any!> {
|
||||
public constructor Foo2</*0*/ T : kotlin.Any!>()
|
||||
@org.jetbrains.annotations.Nullable public final var value: T?
|
||||
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
|
||||
}
|
||||
|
||||
public open class Foo3</*0*/ T : kotlin.Any!> {
|
||||
public constructor Foo3</*0*/ T : kotlin.Any!>()
|
||||
@org.jetbrains.annotations.Nullable public final var value: T?
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user