[FIR] Fix redundant explicit type checker

This commit is contained in:
vladislavf7@gmail.com
2020-07-17 10:55:33 +03:00
committed by Mikhail Glukhikh
parent eecb43d4c9
commit a988234bbf
3 changed files with 134 additions and 46 deletions
@@ -1,3 +1,33 @@
import kotlin.reflect.KClass
@Target(AnnotationTarget.TYPE)
annotation class A
fun annotated() {
val x: @A Int /* NOT redundant */ = 1
}
object SomeObj
fun fer() {
val x: Any /* NOT redundant */ = SomeObj
}
fun f2(y: String?): String {
val f: KClass<*> = (y ?: return "")::class
return ""
}
object Obj {}
interface IA
interface IB : IA
fun IA.extFun(x: IB) {}
fun testWithExpectedType() {
val extFun_AB_A: IA.(IB) -> Unit = IA::extFun
}
interface Point {
val x: Int
val y: Int
@@ -6,35 +36,37 @@ interface Point {
class PointImpl(override val x: Int, override val y: Int) : Point
fun foo() {
val s: <!REDUNDANT_EXPLICIT_TYPE!>String<!> = "Hello ${10+1}"
val str: String? = ""
val o: <!REDUNDANT_EXPLICIT_TYPE!>Obj<!> = Obj
val p: Point = PointImpl(1, 2)
val a: <!REDUNDANT_EXPLICIT_TYPE!>Boolean<!> = true
val i: Int = 2 * 2
val l: <!REDUNDANT_EXPLICIT_TYPE!>Long<!> = 1234567890123L
val s: String? = null
val sh: Short = 42
val integer: <!REDUNDANT_EXPLICIT_TYPE!>Int<!> = 42
val piFloat: <!REDUNDANT_EXPLICIT_TYPE!>Float<!> = 3.14f
val piDouble: <!REDUNDANT_EXPLICIT_TYPE!>Double<!> = 3.14
val charZ: <!REDUNDANT_EXPLICIT_TYPE!>Char<!> = 'z'
var alpha: <!REDUNDANT_EXPLICIT_TYPE!>Int<!> = 0
}
fun test(boolean: Boolean) {
val expectedLong: Long = if (boolean) {
42
} else {
return
}
}
class My {
val x: Int = 1
}
object Obj {}
fun bar() {
val o: <!REDUNDANT_EXPLICIT_TYPE!>Obj<!> = Obj
}
fun doo() {
val i: <!REDUNDANT_EXPLICIT_TYPE!>Int<!> = 42
val pi: <!REDUNDANT_EXPLICIT_TYPE!>Float<!> = 3.14f
val pi2: <!REDUNDANT_EXPLICIT_TYPE!>Double<!> = 3.14
val ch: <!REDUNDANT_EXPLICIT_TYPE!>Char<!> = 'z'
}
fun soo() {
val s: <!REDUNDANT_EXPLICIT_TYPE!>String<!> = "Hello ${10+1}"
}
val ZERO: Int = 0
fun main() {
@@ -1,4 +1,41 @@
FILE: RedundantExplicitTypeChecker.kt
@R|kotlin/annotation/Target|(vararg(Q|kotlin/annotation/AnnotationTarget|.R|kotlin/annotation/AnnotationTarget.TYPE|)) public final annotation class A : R|kotlin/Annotation| {
public constructor(): R|A| {
super<R|kotlin/Any|>()
}
}
public final fun annotated(): R|kotlin/Unit| {
lval x: @R|A|() R|kotlin/Int| = Int(1)
}
public final object SomeObj : R|kotlin/Any| {
private constructor(): R|SomeObj| {
super<R|kotlin/Any|>()
}
}
public final fun fer(): R|kotlin/Unit| {
lval x: R|kotlin/Any| = Q|SomeObj|
}
public final fun f2(y: R|kotlin/String?|): R|kotlin/String| {
lval f: R|kotlin/reflect/KClass<*>| = <getClass>(R|<local>/y| ?: ^f2 String())
^f2 String()
}
public final object Obj : R|kotlin/Any| {
private constructor(): R|Obj| {
super<R|kotlin/Any|>()
}
}
public abstract interface IA : R|kotlin/Any| {
}
public abstract interface IB : R|IA| {
}
public final fun R|IA|.extFun(x: R|IB|): R|kotlin/Unit| {
}
public final fun testWithExpectedType(): R|kotlin/Unit| {
lval extFun_AB_A: R|IA.(IB) -> kotlin/Unit| = Q|IA|::R|/extFun|
}
public abstract interface Point : R|kotlin/Any| {
public abstract val x: R|kotlin/Int|
public get(): R|kotlin/Int|
@@ -20,12 +57,31 @@ FILE: RedundantExplicitTypeChecker.kt
}
public final fun foo(): R|kotlin/Unit| {
lval s: R|kotlin/String| = <strcat>(String(Hello ), Int(10).R|kotlin/Int.plus|(Int(1)).R|kotlin/Any.toString|())
lval str: R|kotlin/String?| = String()
lval o: R|Obj| = Q|Obj|
lval p: R|Point| = R|/PointImpl.PointImpl|(Int(1), Int(2))
lval a: R|kotlin/Boolean| = Boolean(true)
lval i: R|kotlin/Int| = Int(2).R|kotlin/Int.times|(Int(2))
lval l: R|kotlin/Long| = Long(1234567890123)
lval s: R|kotlin/String?| = Null(null)
lval sh: R|kotlin/Short| = Short(42)
lval integer: R|kotlin/Int| = Int(42)
lval piFloat: R|kotlin/Float| = Float(3.14)
lval piDouble: R|kotlin/Double| = Double(3.14)
lval charZ: R|kotlin/Char| = Char(z)
lvar alpha: R|kotlin/Int| = Int(0)
}
public final fun test(boolean: R|kotlin/Boolean|): R|kotlin/Unit| {
lval expectedLong: R|kotlin/Long| = when () {
R|<local>/boolean| -> {
Int(42)
}
else -> {
^test Unit
}
}
}
public final class My : R|kotlin/Any| {
public constructor(): R|My| {
@@ -36,24 +92,6 @@ FILE: RedundantExplicitTypeChecker.kt
public get(): R|kotlin/Int|
}
public final object Obj : R|kotlin/Any| {
private constructor(): R|Obj| {
super<R|kotlin/Any|>()
}
}
public final fun bar(): R|kotlin/Unit| {
lval o: R|Obj| = Q|Obj|
}
public final fun doo(): R|kotlin/Unit| {
lval i: R|kotlin/Int| = Int(42)
lval pi: R|kotlin/Float| = Float(3.14)
lval pi2: R|kotlin/Double| = Double(3.14)
lval ch: R|kotlin/Char| = Char(z)
}
public final fun soo(): R|kotlin/Unit| {
lval s: R|kotlin/String| = <strcat>(String(Hello ), Int(10).R|kotlin/Int.plus|(Int(1)).R|kotlin/Any.toString|())
}
public final val ZERO: R|kotlin/Int| = Int(0)
public get(): R|kotlin/Int|
public final fun main(): R|kotlin/Unit| {