Introduce FirInitializerTypeMismatchChecker
This commit is contained in:
+31
@@ -0,0 +1,31 @@
|
||||
// FULL_JDK
|
||||
|
||||
import java.util.*
|
||||
|
||||
open class A
|
||||
open class B : A()
|
||||
class C : B()
|
||||
|
||||
fun foo() {
|
||||
// InitializerTypeMismatchChecker doesn't report here due this is work for another checker
|
||||
val (a: Int, b: Int) = bar()
|
||||
}
|
||||
|
||||
fun bar(): Pair<Int?, Int?> = null to null
|
||||
|
||||
class Classes {
|
||||
val p: Int = 1 // ok
|
||||
<!INITIALIZER_TYPE_MISMATCH{LT}!>val <!INITIALIZER_TYPE_MISMATCH{PSI}!>incorrect<!>: C = B()<!>
|
||||
val correct: A = C()
|
||||
}
|
||||
|
||||
class Expressions {
|
||||
val n: Number = 1 // ok
|
||||
<!INITIALIZER_TYPE_MISMATCH{LT}!>val <!INITIALIZER_TYPE_MISMATCH{PSI}!>s<!>: Number = "" // not ok<!>
|
||||
<!INITIALIZER_TYPE_MISMATCH{LT}!>val <!INITIALIZER_TYPE_MISMATCH{PSI}!>s2<!>: Number = "" + "expression" // not ok<!>
|
||||
}
|
||||
|
||||
class Generics {
|
||||
val n: SortedSet<Int> = TreeSet() // ok
|
||||
val b: SortedSet<Int> = TreeSet<Int>() // ok
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
FILE: InitializerTypeMismatch.kt
|
||||
public open class A : R|kotlin/Any| {
|
||||
public constructor(): R|A| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
}
|
||||
public open class B : R|A| {
|
||||
public constructor(): R|B| {
|
||||
super<R|A|>()
|
||||
}
|
||||
|
||||
}
|
||||
public final class C : R|B| {
|
||||
public constructor(): R|C| {
|
||||
super<R|B|>()
|
||||
}
|
||||
|
||||
}
|
||||
public final fun foo(): R|kotlin/Unit| {
|
||||
lval <destruct>: R|kotlin/Pair<kotlin/Int?, kotlin/Int?>| = R|/bar|()
|
||||
lval a: R|kotlin/Int| = R|<local>/<destruct>|.R|SubstitutionOverride<kotlin/Pair.component1: R|kotlin/Int?|>|()
|
||||
lval b: R|kotlin/Int| = R|<local>/<destruct>|.R|SubstitutionOverride<kotlin/Pair.component2: R|kotlin/Int?|>|()
|
||||
}
|
||||
public final fun bar(): R|kotlin/Pair<kotlin/Int?, kotlin/Int?>| {
|
||||
^bar Null(null).R|kotlin/to|<R|kotlin/Nothing?|, R|kotlin/Nothing?|>(Null(null))
|
||||
}
|
||||
public final class Classes : R|kotlin/Any| {
|
||||
public constructor(): R|Classes| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
public final val p: R|kotlin/Int| = Int(1)
|
||||
public get(): R|kotlin/Int|
|
||||
|
||||
public final val incorrect: R|C| = R|/B.B|()
|
||||
public get(): R|C|
|
||||
|
||||
public final val correct: R|A| = R|/C.C|()
|
||||
public get(): R|A|
|
||||
|
||||
}
|
||||
public final class Expressions : R|kotlin/Any| {
|
||||
public constructor(): R|Expressions| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
public final val n: R|kotlin/Number| = Int(1)
|
||||
public get(): R|kotlin/Number|
|
||||
|
||||
public final val s: R|kotlin/Number| = String()
|
||||
public get(): R|kotlin/Number|
|
||||
|
||||
public final val s2: R|kotlin/Number| = String().R|kotlin/String.plus|(String(expression))
|
||||
public get(): R|kotlin/Number|
|
||||
|
||||
}
|
||||
public final class Generics : R|kotlin/Any| {
|
||||
public constructor(): R|Generics| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
public final val n: R|java/util/SortedSet<kotlin/Int>| = R|java/util/TreeSet.TreeSet|<R|ft<kotlin/Int, kotlin/Int?>|>()
|
||||
public get(): R|java/util/SortedSet<kotlin/Int>|
|
||||
|
||||
public final val b: R|java/util/SortedSet<kotlin/Int>| = R|java/util/TreeSet.TreeSet|<R|ft<kotlin/Int, kotlin/Int?>|>()
|
||||
public get(): R|java/util/SortedSet<kotlin/Int>|
|
||||
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
FILE: TestCase1.kt
|
||||
public final class Case : R|kotlin/Any| {
|
||||
public constructor(): R|testsCase1/Case| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
public final fun case(v: R|testsCase1/V|): R|kotlin/Unit| {
|
||||
lval va: R|() -> kotlin/String| = Q|testsCase1/V|::R|testsCase1/a|
|
||||
lval vb: R|() -> kotlin/String| = Q|testsCase1/V|::R|testsCase1/V.Companion.b|
|
||||
lval va1: R|() -> kotlin/String| = R|<local>/v|::R|testsCase1/a|
|
||||
lval vb1: R|() -> kotlin/String| = Q|testsCase1/V|::R|testsCase1/V.Companion.b|
|
||||
}
|
||||
|
||||
public final val R|testsCase1/V.Companion|.b: R|kotlin/String|
|
||||
public get(): R|kotlin/String| {
|
||||
^ String(1)
|
||||
}
|
||||
|
||||
}
|
||||
public final val R|testsCase1/V|.a: R|kotlin/String|
|
||||
public get(): R|kotlin/String| {
|
||||
^ String(1)
|
||||
}
|
||||
public final val R|testsCase1/V.Companion|.a: R|kotlin/String|
|
||||
public get(): R|kotlin/String| {
|
||||
^ String(1)
|
||||
}
|
||||
public final class V : R|kotlin/Any| {
|
||||
public constructor(): R|testsCase1/V| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
public final companion object Companion : R|kotlin/Any| {
|
||||
private constructor(): R|testsCase1/V.Companion| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
public final const val b: R|kotlin/String| = String(1)
|
||||
public get(): R|kotlin/String|
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
// FULL_JDK
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNUSED_PARAMETER -UNUSED_EXPRESSION
|
||||
// SKIP_TXT
|
||||
|
||||
|
||||
|
||||
// FILE: TestCase1.kt
|
||||
// TESTCASE NUMBER: 1
|
||||
package testsCase1
|
||||
|
||||
class Case() {
|
||||
fun case(v: V) {
|
||||
// InitializerTypeMismatchChecker bug
|
||||
val va: () -> String = <!INITIALIZER_TYPE_MISMATCH!>(V)::a<!>
|
||||
|
||||
val vb: () -> String = (V)::b
|
||||
|
||||
val va1: () -> String = v::a
|
||||
val vb1: () -> String = (V)::b
|
||||
|
||||
}
|
||||
|
||||
val V.Companion.b: String // (3)
|
||||
get() = "1"
|
||||
|
||||
}
|
||||
|
||||
val V.a: String
|
||||
get() = "1"
|
||||
|
||||
val V.Companion.a: String
|
||||
get() = "1"
|
||||
|
||||
|
||||
class V {
|
||||
companion object {
|
||||
const val b: String = "1"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user