[FIR] Add test about synthetic / non-synthetic smart casts
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
// FILE: SomeClass.java
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class SomeClass {
|
||||
@Nullable
|
||||
public CharSequence getBar();
|
||||
|
||||
public int getFoo();
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
class AnotherClass(val bar: CharSequence?, val foo: Int) {
|
||||
fun baz(): Any = true
|
||||
}
|
||||
|
||||
fun test1(x: AnotherClass?) {
|
||||
val bar = x?.bar ?: return
|
||||
x.bar
|
||||
}
|
||||
|
||||
fun test2(x: SomeClass?) {
|
||||
val bar = x?.bar ?: return
|
||||
x.bar
|
||||
}
|
||||
|
||||
fun test3(x: AnotherClass?) {
|
||||
val bar = x?.bar
|
||||
if (bar != null) {
|
||||
x.bar.length
|
||||
}
|
||||
}
|
||||
|
||||
fun test4(x: SomeClass?) {
|
||||
val bar = x?.bar
|
||||
if (bar != null) {
|
||||
x.bar.<!INAPPLICABLE_CANDIDATE!>length<!>
|
||||
}
|
||||
}
|
||||
|
||||
fun test5(x: AnotherClass?) {
|
||||
val bar = x?.bar as? String ?: return
|
||||
x.<!INAPPLICABLE_CANDIDATE!>foo<!>
|
||||
}
|
||||
|
||||
fun test6(x: SomeClass?) {
|
||||
val bar = x?.bar as? String ?: return
|
||||
x.<!INAPPLICABLE_CANDIDATE!>foo<!>
|
||||
}
|
||||
|
||||
fun test7(x: AnotherClass?) {
|
||||
val baz = x?.baz() as? Boolean ?: return
|
||||
x.foo
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
FILE: test.kt
|
||||
public final class AnotherClass : R|kotlin/Any| {
|
||||
public constructor(bar: R|kotlin/CharSequence?|, foo: R|kotlin/Int|): R|AnotherClass| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
public final val bar: R|kotlin/CharSequence?| = R|<local>/bar|
|
||||
public get(): R|kotlin/CharSequence?|
|
||||
|
||||
public final val foo: R|kotlin/Int| = R|<local>/foo|
|
||||
public get(): R|kotlin/Int|
|
||||
|
||||
public final fun baz(): R|kotlin/Any| {
|
||||
^baz Boolean(true)
|
||||
}
|
||||
|
||||
}
|
||||
public final fun test1(x: R|AnotherClass?|): R|kotlin/Unit| {
|
||||
lval bar: R|kotlin/CharSequence| = when (lval <elvis>: R|kotlin/CharSequence?| = R|<local>/x|?.R|/AnotherClass.bar|) {
|
||||
==($subj$, Null(null)) -> {
|
||||
^test1 Unit
|
||||
}
|
||||
else -> {
|
||||
R|<local>/<elvis>|
|
||||
}
|
||||
}
|
||||
|
||||
R|<local>/x|.R|/AnotherClass.bar|
|
||||
}
|
||||
public final fun test2(x: R|SomeClass?|): R|kotlin/Unit| {
|
||||
lval bar: R|kotlin/CharSequence| = when (lval <elvis>: R|kotlin/CharSequence?| = R|<local>/x|?.R|/SomeClass.bar|) {
|
||||
==($subj$, Null(null)) -> {
|
||||
^test2 Unit
|
||||
}
|
||||
else -> {
|
||||
R|<local>/<elvis>|
|
||||
}
|
||||
}
|
||||
|
||||
R|<local>/x|.R|/SomeClass.bar|
|
||||
}
|
||||
public final fun test3(x: R|AnotherClass?|): R|kotlin/Unit| {
|
||||
lval bar: R|kotlin/CharSequence?| = R|<local>/x|?.R|/AnotherClass.bar|
|
||||
when () {
|
||||
!=(R|<local>/bar|, Null(null)) -> {
|
||||
R|<local>/x|.R|/AnotherClass.bar|.R|kotlin/CharSequence.length|
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
public final fun test4(x: R|SomeClass?|): R|kotlin/Unit| {
|
||||
lval bar: R|kotlin/CharSequence?| = R|<local>/x|?.R|/SomeClass.bar|
|
||||
when () {
|
||||
!=(R|<local>/bar|, Null(null)) -> {
|
||||
R|<local>/x|.R|/SomeClass.bar|.<Inapplicable(WRONG_RECEIVER): [kotlin/CharSequence.length]>#
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
public final fun test5(x: R|AnotherClass?|): R|kotlin/Unit| {
|
||||
lval bar: R|kotlin/String| = when (lval <elvis>: R|kotlin/String?| = (R|<local>/x|?.R|/AnotherClass.bar| as? R|kotlin/String|)) {
|
||||
==($subj$, Null(null)) -> {
|
||||
^test5 Unit
|
||||
}
|
||||
else -> {
|
||||
R|<local>/<elvis>|
|
||||
}
|
||||
}
|
||||
|
||||
R|<local>/x|.<Inapplicable(WRONG_RECEIVER): [/AnotherClass.foo]>#
|
||||
}
|
||||
public final fun test6(x: R|SomeClass?|): R|kotlin/Unit| {
|
||||
lval bar: R|kotlin/String| = when (lval <elvis>: R|kotlin/String?| = (R|<local>/x|?.R|/SomeClass.bar| as? R|kotlin/String|)) {
|
||||
==($subj$, Null(null)) -> {
|
||||
^test6 Unit
|
||||
}
|
||||
else -> {
|
||||
R|<local>/<elvis>|
|
||||
}
|
||||
}
|
||||
|
||||
R|<local>/x|.<Inapplicable(WRONG_RECEIVER): [/SomeClass.foo]>#
|
||||
}
|
||||
public final fun test7(x: R|AnotherClass?|): R|kotlin/Unit| {
|
||||
lval baz: R|kotlin/Boolean| = when (lval <elvis>: R|kotlin/Boolean?| = (R|<local>/x|?.R|/AnotherClass.baz|() as? R|kotlin/Boolean|)) {
|
||||
==($subj$, Null(null)) -> {
|
||||
^test7 Unit
|
||||
}
|
||||
else -> {
|
||||
R|<local>/<elvis>|
|
||||
}
|
||||
}
|
||||
|
||||
R|<local>/x|.R|/AnotherClass.foo|
|
||||
}
|
||||
+5
@@ -689,6 +689,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest {
|
||||
runTest("compiler/fir/resolve/testData/resolve/expresssions/simple.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("syntheticSmartCast.kt")
|
||||
public void testSyntheticSmartCast() throws Exception {
|
||||
runTest("compiler/fir/resolve/testData/resolve/expresssions/syntheticSmartCast.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("this.kt")
|
||||
public void testThis() throws Exception {
|
||||
runTest("compiler/fir/resolve/testData/resolve/expresssions/this.kt");
|
||||
|
||||
Generated
+5
@@ -689,6 +689,11 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
|
||||
runTest("compiler/fir/resolve/testData/resolve/expresssions/simple.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("syntheticSmartCast.kt")
|
||||
public void testSyntheticSmartCast() throws Exception {
|
||||
runTest("compiler/fir/resolve/testData/resolve/expresssions/syntheticSmartCast.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("this.kt")
|
||||
public void testThis() throws Exception {
|
||||
runTest("compiler/fir/resolve/testData/resolve/expresssions/this.kt");
|
||||
|
||||
Reference in New Issue
Block a user