[FIR] Enhance equality smartcasting test case to include data classes
^KT-58169 Fixed
This commit is contained in:
+6
@@ -35082,6 +35082,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/enumEntryMembers_before.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("equalitySmartcast.kt")
|
||||
public void testEqualitySmartcast() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/equalitySmartcast.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("equals.kt")
|
||||
public void testEquals() throws Exception {
|
||||
|
||||
+6
@@ -35082,6 +35082,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/enumEntryMembers_before.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("equalitySmartcast.kt")
|
||||
public void testEqualitySmartcast() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/equalitySmartcast.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("equals.kt")
|
||||
public void testEquals() throws Exception {
|
||||
|
||||
+6
@@ -32726,6 +32726,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/enumEntryMembers_before.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("equalitySmartcast.kt")
|
||||
public void testEqualitySmartcast() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/equalitySmartcast.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("equals.kt")
|
||||
public void testEquals() throws Exception {
|
||||
|
||||
+6
@@ -32852,6 +32852,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/enumEntryMembers_before.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("equalitySmartcast.kt")
|
||||
public void testEqualitySmartcast() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/equalitySmartcast.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("equals.kt")
|
||||
public void testEquals() throws Exception {
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
// SKIP_TXT
|
||||
// ISSUE: KT-57513, KT-58169
|
||||
|
||||
fun string(foo: Any) {
|
||||
val string = ""
|
||||
if ("" == foo) foo.length
|
||||
if (string == foo) foo.length
|
||||
if (foo == "") foo.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
|
||||
fun int(foo: Any) {
|
||||
val int = 1
|
||||
if (1 == foo) foo.<!UNRESOLVED_REFERENCE!>plus<!>(1)
|
||||
if (int == foo) foo.<!UNRESOLVED_REFERENCE!>plus<!>(1)
|
||||
if (foo == 1) foo.<!UNRESOLVED_REFERENCE!>plus<!>(1)
|
||||
}
|
||||
|
||||
fun long(foo: Any) {
|
||||
val long = 1L
|
||||
if (1L == foo) foo.<!UNRESOLVED_REFERENCE!>plus<!>(1L)
|
||||
if (long == foo) foo.<!UNRESOLVED_REFERENCE!>plus<!>(1L)
|
||||
if (foo == 1L) foo.<!UNRESOLVED_REFERENCE!>plus<!>(1L)
|
||||
}
|
||||
|
||||
fun char(foo: Any) {
|
||||
val char = 'a'
|
||||
if ('a' == foo) foo.<!UNRESOLVED_REFERENCE!>compareTo<!>('a')
|
||||
if (char == foo) foo.<!UNRESOLVED_REFERENCE!>compareTo<!>('a')
|
||||
if (foo == 'a') foo.<!UNRESOLVED_REFERENCE!>compareTo<!>('a')
|
||||
}
|
||||
|
||||
class A { fun a() = Unit }
|
||||
class B { fun b() = Unit; override fun equals(other: Any?): Boolean = this === other }
|
||||
data class C(val x: Int) { fun c() = Unit }
|
||||
open class D { fun d() = Unit }
|
||||
enum class E { ONE; fun e() = Unit }
|
||||
|
||||
fun testA(foo: A, bar: Any) {
|
||||
if (foo == bar) bar.a()
|
||||
if (bar == foo) bar.<!UNRESOLVED_REFERENCE!>a<!>()
|
||||
}
|
||||
|
||||
fun testNullableA(foo: A?, bar: Any?) {
|
||||
if (foo != null && foo == bar) bar.a()
|
||||
}
|
||||
|
||||
fun testB(foo: B, bar: Any) {
|
||||
if (foo == bar) bar.<!UNRESOLVED_REFERENCE!>b<!>()
|
||||
if (bar == foo) bar.<!UNRESOLVED_REFERENCE!>b<!>()
|
||||
}
|
||||
|
||||
fun testNullableB(foo: B?, bar: B?) {
|
||||
if (foo != null && foo == bar) bar.b()
|
||||
}
|
||||
|
||||
fun testC(foo: C, bar: Any) {
|
||||
if (foo == bar) bar.<!UNRESOLVED_REFERENCE!>c<!>()
|
||||
if (bar == foo) bar.<!UNRESOLVED_REFERENCE!>c<!>()
|
||||
}
|
||||
|
||||
fun testNullableC(foo: C?, bar: C?) {
|
||||
if (foo != null && foo == bar) bar.c()
|
||||
}
|
||||
|
||||
fun testD(foo: D, bar: Any) {
|
||||
if (foo == bar) bar.<!UNRESOLVED_REFERENCE!>d<!>()
|
||||
if (bar == foo) bar.<!UNRESOLVED_REFERENCE!>d<!>()
|
||||
}
|
||||
|
||||
fun testNullableD(foo: D?, bar: D?) {
|
||||
if (foo != null && foo == bar) bar.d()
|
||||
}
|
||||
|
||||
fun testE(foo: E, bar: Any) {
|
||||
if (foo == bar) bar.<!UNRESOLVED_REFERENCE!>e<!>()
|
||||
if (bar == foo) bar.<!UNRESOLVED_REFERENCE!>e<!>()
|
||||
}
|
||||
|
||||
fun testNullableE(foo: E?, bar: E?) {
|
||||
if (foo != null && foo == bar) bar.e()
|
||||
}
|
||||
|
||||
fun testSmartcast(foo: Any, bar: Any) {
|
||||
if (foo is A && foo == bar) {
|
||||
bar.a()
|
||||
}
|
||||
if (foo is B && foo == bar) {
|
||||
bar.<!UNRESOLVED_REFERENCE!>b<!>()
|
||||
}
|
||||
if (foo is C && foo == bar) {
|
||||
bar.<!UNRESOLVED_REFERENCE!>c<!>()
|
||||
}
|
||||
if (foo is D && foo == bar) {
|
||||
bar.<!UNRESOLVED_REFERENCE!>d<!>()
|
||||
}
|
||||
if (foo is E && foo == bar) {
|
||||
bar.<!UNRESOLVED_REFERENCE!>e<!>()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
// SKIP_TXT
|
||||
// ISSUE: KT-57513, KT-58169
|
||||
|
||||
fun string(foo: Any) {
|
||||
val string = ""
|
||||
if ("" == foo) <!DEBUG_INFO_SMARTCAST!>foo<!>.length
|
||||
if (string == foo) <!DEBUG_INFO_SMARTCAST!>foo<!>.length
|
||||
if (foo == "") foo.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
|
||||
fun int(foo: Any) {
|
||||
val int = 1
|
||||
if (1 == foo) foo.<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>plus<!>(1)
|
||||
if (int == foo) foo.<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>plus<!>(1)
|
||||
if (foo == 1) foo.<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>plus<!>(1)
|
||||
}
|
||||
|
||||
fun long(foo: Any) {
|
||||
val long = 1L
|
||||
if (1L == foo) foo.<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>plus<!>(1L)
|
||||
if (long == foo) foo.<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>plus<!>(1L)
|
||||
if (foo == 1L) foo.<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>plus<!>(1L)
|
||||
}
|
||||
|
||||
fun char(foo: Any) {
|
||||
val char = 'a'
|
||||
if ('a' == foo) foo.<!UNRESOLVED_REFERENCE!>compareTo<!>('a')
|
||||
if (char == foo) foo.<!UNRESOLVED_REFERENCE!>compareTo<!>('a')
|
||||
if (foo == 'a') foo.<!UNRESOLVED_REFERENCE!>compareTo<!>('a')
|
||||
}
|
||||
|
||||
class A { fun a() = Unit }
|
||||
class B { fun b() = Unit; override fun equals(other: Any?): Boolean = this === other }
|
||||
data class C(val x: Int) { fun c() = Unit }
|
||||
open class D { fun d() = Unit }
|
||||
enum class E { ONE; fun e() = Unit }
|
||||
|
||||
fun testA(foo: A, bar: Any) {
|
||||
if (foo == bar) <!DEBUG_INFO_SMARTCAST!>bar<!>.a()
|
||||
if (bar == foo) bar.<!UNRESOLVED_REFERENCE!>a<!>()
|
||||
}
|
||||
|
||||
fun testNullableA(foo: A?, bar: Any?) {
|
||||
if (foo != null && foo == bar) <!DEBUG_INFO_SMARTCAST!>bar<!>.a()
|
||||
}
|
||||
|
||||
fun testB(foo: B, bar: Any) {
|
||||
if (foo == bar) bar.<!UNRESOLVED_REFERENCE!>b<!>()
|
||||
if (bar == foo) bar.<!UNRESOLVED_REFERENCE!>b<!>()
|
||||
}
|
||||
|
||||
fun testNullableB(foo: B?, bar: B?) {
|
||||
if (foo != null && foo == bar) <!DEBUG_INFO_SMARTCAST!>bar<!>.b()
|
||||
}
|
||||
|
||||
fun testC(foo: C, bar: Any) {
|
||||
if (foo == bar) bar.<!UNRESOLVED_REFERENCE!>c<!>()
|
||||
if (bar == foo) bar.<!UNRESOLVED_REFERENCE!>c<!>()
|
||||
}
|
||||
|
||||
fun testNullableC(foo: C?, bar: C?) {
|
||||
if (foo != null && foo == bar) <!DEBUG_INFO_SMARTCAST!>bar<!>.c()
|
||||
}
|
||||
|
||||
fun testD(foo: D, bar: Any) {
|
||||
if (foo == bar) bar.<!UNRESOLVED_REFERENCE!>d<!>()
|
||||
if (bar == foo) bar.<!UNRESOLVED_REFERENCE!>d<!>()
|
||||
}
|
||||
|
||||
fun testNullableD(foo: D?, bar: D?) {
|
||||
if (foo != null && foo == bar) <!DEBUG_INFO_SMARTCAST!>bar<!>.d()
|
||||
}
|
||||
|
||||
fun testE(foo: E, bar: Any) {
|
||||
if (foo == bar) bar.<!UNRESOLVED_REFERENCE!>e<!>()
|
||||
if (bar == foo) bar.<!UNRESOLVED_REFERENCE!>e<!>()
|
||||
}
|
||||
|
||||
fun testNullableE(foo: E?, bar: E?) {
|
||||
if (foo != null && foo == bar) <!DEBUG_INFO_SMARTCAST!>bar<!>.e()
|
||||
}
|
||||
|
||||
fun testSmartcast(foo: Any, bar: Any) {
|
||||
if (foo is A && foo == bar) {
|
||||
bar.<!UNRESOLVED_REFERENCE!>a<!>()
|
||||
}
|
||||
if (foo is B && foo == bar) {
|
||||
bar.<!UNRESOLVED_REFERENCE!>b<!>()
|
||||
}
|
||||
if (foo is C && foo == bar) {
|
||||
bar.<!UNRESOLVED_REFERENCE!>c<!>()
|
||||
}
|
||||
if (foo is D && foo == bar) {
|
||||
bar.<!UNRESOLVED_REFERENCE!>d<!>()
|
||||
}
|
||||
if (foo is E && foo == bar) {
|
||||
bar.<!UNRESOLVED_REFERENCE!>e<!>()
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
// SKIP_TXT
|
||||
|
||||
fun foo(x: String?) = x
|
||||
|
||||
class Test
|
||||
@@ -23,31 +25,3 @@ fun gav(i: TestWithEquals?, j: TestWithEquals?) {
|
||||
if (i == j) foo(i)
|
||||
}
|
||||
}
|
||||
|
||||
fun string(foo: Any) {
|
||||
val string = ""
|
||||
if ("" == foo) foo.length
|
||||
if (string == foo) foo.length
|
||||
if (foo == "") foo.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
|
||||
fun int(foo: Any) {
|
||||
val int = 1
|
||||
if (1 == foo) foo.<!UNRESOLVED_REFERENCE!>plus<!>(1)
|
||||
if (int == foo) foo.<!UNRESOLVED_REFERENCE!>plus<!>(1)
|
||||
if (foo == 1) foo.<!UNRESOLVED_REFERENCE!>plus<!>(1)
|
||||
}
|
||||
|
||||
fun long(foo: Any) {
|
||||
val long = 1L
|
||||
if (1L == foo) foo.<!UNRESOLVED_REFERENCE!>plus<!>(1L)
|
||||
if (long == foo) foo.<!UNRESOLVED_REFERENCE!>plus<!>(1L)
|
||||
if (foo == 1L) foo.<!UNRESOLVED_REFERENCE!>plus<!>(1L)
|
||||
}
|
||||
|
||||
fun char(foo: Any) {
|
||||
val char = 'a'
|
||||
if ('a' == foo) foo.<!UNRESOLVED_REFERENCE!>compareTo<!>('a')
|
||||
if (char == foo) foo.<!UNRESOLVED_REFERENCE!>compareTo<!>('a')
|
||||
if (foo == 'a') foo.<!UNRESOLVED_REFERENCE!>compareTo<!>('a')
|
||||
}
|
||||
|
||||
+2
-28
@@ -1,3 +1,5 @@
|
||||
// SKIP_TXT
|
||||
|
||||
fun foo(x: String?) = x
|
||||
|
||||
class Test
|
||||
@@ -23,31 +25,3 @@ fun gav(i: TestWithEquals?, j: TestWithEquals?) {
|
||||
if (i == <!DEBUG_INFO_CONSTANT!>j<!>) foo(<!DEBUG_INFO_CONSTANT!>i<!>)
|
||||
}
|
||||
}
|
||||
|
||||
fun string(foo: Any) {
|
||||
val string = ""
|
||||
if ("" == foo) <!DEBUG_INFO_SMARTCAST!>foo<!>.length
|
||||
if (string == foo) <!DEBUG_INFO_SMARTCAST!>foo<!>.length
|
||||
if (foo == "") foo.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
|
||||
fun int(foo: Any) {
|
||||
val int = 1
|
||||
if (1 == foo) foo.<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>plus<!>(1)
|
||||
if (int == foo) foo.<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>plus<!>(1)
|
||||
if (foo == 1) foo.<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>plus<!>(1)
|
||||
}
|
||||
|
||||
fun long(foo: Any) {
|
||||
val long = 1L
|
||||
if (1L == foo) foo.<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>plus<!>(1L)
|
||||
if (long == foo) foo.<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>plus<!>(1L)
|
||||
if (foo == 1L) foo.<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>plus<!>(1L)
|
||||
}
|
||||
|
||||
fun char(foo: Any) {
|
||||
val char = 'a'
|
||||
if ('a' == foo) foo.<!UNRESOLVED_REFERENCE!>compareTo<!>('a')
|
||||
if (char == foo) foo.<!UNRESOLVED_REFERENCE!>compareTo<!>('a')
|
||||
if (foo == 'a') foo.<!UNRESOLVED_REFERENCE!>compareTo<!>('a')
|
||||
}
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
package
|
||||
|
||||
public fun bar(/*0*/ i: Test?): kotlin.Unit
|
||||
public fun bar(/*0*/ i: TestWithEquals?): kotlin.Unit
|
||||
public fun char(/*0*/ foo: kotlin.Any): kotlin.Unit
|
||||
public fun foo(/*0*/ x: kotlin.String?): kotlin.String?
|
||||
public fun gav(/*0*/ i: TestWithEquals?, /*1*/ j: TestWithEquals?): kotlin.Unit
|
||||
public fun int(/*0*/ foo: kotlin.Any): kotlin.Unit
|
||||
public fun long(/*0*/ foo: kotlin.Any): kotlin.Unit
|
||||
public fun string(/*0*/ foo: kotlin.Any): kotlin.Unit
|
||||
|
||||
public final class Test {
|
||||
public constructor Test()
|
||||
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 TestWithEquals {
|
||||
public constructor TestWithEquals()
|
||||
public open override /*1*/ 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
|
||||
}
|
||||
Generated
+6
@@ -35082,6 +35082,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/enumEntryMembers_before.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("equalitySmartcast.kt")
|
||||
public void testEqualitySmartcast() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/equalitySmartcast.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("equals.kt")
|
||||
public void testEquals() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user