Introduce FIR_IDENTICAL for FIR vs old frontend tests #KT-36879 Fixed

This commit is contained in:
Mikhail Glukhikh
2020-03-04 17:54:33 +03:00
parent 186e0b0cba
commit 8884cbe415
2268 changed files with 1175 additions and 19754 deletions
@@ -1,11 +0,0 @@
// See KT-10276
class Bar() {
var test: String? = null
fun foo() {
if (test != null) {
// No warning: test is a mutable property
test?.hashCode()
}
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// See KT-10276
class Bar() {
@@ -1,7 +0,0 @@
// See also KT-7801
class A
fun <T> test(v: T): T {
val a: T = if (v !is A) v else v
return a
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// See also KT-7801
class A
@@ -1,11 +0,0 @@
open class A {
open fun foo() = "FAIL"
fun bar() = if (this is C) foo() else "FAIL"
}
open class B : A()
open class C : B() {
override fun foo() = "OK"
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
open class A {
open fun foo() = "FAIL"
@@ -1,13 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_LAMBDA_EXPRESSION -VARIABLE_WITH_REDUNDANT_INITIALIZER -UNUSED_EXPRESSION
object Test {
fun <T> foo(actual: T) {}
fun <T : Number> foo(actual: T) {}
}
fun main() {
var y: Number? = null
y = 2
{ y = 1 }
Test.foo(y)
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_LAMBDA_EXPRESSION -VARIABLE_WITH_REDUNDANT_INITIALIZER -UNUSED_EXPRESSION
object Test {
@@ -1,12 +0,0 @@
interface A {
fun foo()
}
interface C: A
interface B: A
fun test(c: C) {
if (c is B) {
c.foo() // OVERLOAD_RESOLUTION_AMBIGUITY: B.foo() and C.foo()
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
interface A {
fun foo()
}
@@ -1,15 +0,0 @@
// !CHECK_TYPE
interface A {
fun <T, E> foo(): E
}
interface B : A {
override fun <Q, W> foo(): W
}
fun test(a: A) {
if (a is B) {
a.foo<String, Int>().checkType { _<Int>() }
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !CHECK_TYPE
interface A {
@@ -1,12 +0,0 @@
// Should work already in M11
open class A(val s : String)
class B(s : String) : A(s)
fun test(a : A): String? {
if (a is B) {
// Earlier (14.01.2013) reported overload ambiguity over s
return a.s
}
return null
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// Should work already in M11
open class A(val s : String)
@@ -1,17 +0,0 @@
interface Printer {
fun print()
}
class OKPrinter : Printer {
override fun print() { }
}
class MyClass(var printer: Printer)
fun main(m: MyClass) {
if (m.printer is OKPrinter) {
// We do not need smart cast here, so we should not get SMARTCAST_IMPOSSIBLE
m.printer.print()
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
interface Printer {
fun print()
}
@@ -1,19 +0,0 @@
class Indexed<T>(val x: T, val y: Int)
class Value<out T>(val x: T)
interface WithValue<out T> {
fun value(): Value<T>
}
class Singleton<T>(val x: T) : WithValue<T> {
override fun value() = Value(x)
}
class WithValueIndexed<T>(val f: () -> Value<T>) : WithValue<Indexed<T>> {
override fun value() = Value(Indexed(f().x, 0))
}
fun <T> Singleton<out T>.indexed(): WithValue<Indexed<T>> {
return WithValueIndexed { value() }
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
class Indexed<T>(val x: T, val y: Int)
class Value<out T>(val x: T)
@@ -1,7 +0,0 @@
fun Any?.foo() {}
fun test(a: Any?) {
if (a != null) {
a.foo()
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
fun Any?.foo() {}
fun test(a: Any?) {
@@ -1,17 +0,0 @@
open class VeryBase
open class Base : VeryBase()
class Derived : Base() {
fun original(): VeryBase = this
}
class Another : Base()
fun foo(d: Derived, a: Another?): Base? {
// d is compared with d.original(): VeryBase but should retain its own type
if (d.original() != d) return null
// ad should be of type Base, not VeryBase
val ad = a ?: d
return ad
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
open class VeryBase
open class Base : VeryBase()
@@ -1,12 +0,0 @@
fun x(): Boolean { return true }
public fun foo(pp: Any): Int {
var p = pp
do {
(p as String).length
if (p == "abc") break
p = 42
} while (!x())
// Smart cast is NOT possible here
return p.<!UNRESOLVED_REFERENCE!>length<!>()
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
fun x(): Boolean { return true }
public fun foo(pp: Any): Int {
@@ -1,8 +0,0 @@
fun foo() {
var v: Any = "xyz"
// It is possible in principle to provide smart cast here
// but now we decide that v is Any
v.<!UNRESOLVED_REFERENCE!>length<!>()
v = 42
v.<!UNRESOLVED_REFERENCE!>length<!>()
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
fun foo() {
var v: Any = "xyz"
// It is possible in principle to provide smart cast here
@@ -1,23 +0,0 @@
interface A {
fun ok(): Boolean
}
class B: A {
override fun ok(): Boolean { return true }
}
class C: A {
override fun ok(): Boolean { return false }
}
fun foo(): Boolean {
var v: A
v = B()
// No smart cast needed, but not a problem if ever
if (v.ok()) {
v = C()
}
// No smart cast needed, and no smart cast possible!
// We cannot choose between B and C
return v.ok()
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
interface A {
fun ok(): Boolean
}
@@ -1,10 +0,0 @@
class MyClass(var p: String?)
fun bar(s: String?): Int {
return s?.length ?: -1
}
fun foo(m: MyClass): Int {
m.p = "xyz"
return bar(m.p)
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
class MyClass(var p: String?)
fun bar(s: String?): Int {
@@ -1,10 +0,0 @@
class MyClass(var p: Any)
fun bar(s: Any): Int {
return s.hashCode()
}
fun foo(m: MyClass): Int {
m.p = "xyz"
return bar(m.p)
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
class MyClass(var p: Any)
fun bar(s: Any): Int {
@@ -1,10 +0,0 @@
fun bar(s: Any): Int {
return s.hashCode()
}
class MyClass(var p: Any) {
fun foo(): Int {
p = "xyz"
return bar(p)
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
fun bar(s: Any): Int {
return s.hashCode()
}
@@ -1,13 +0,0 @@
fun bar(s: Any): Int {
return s.hashCode()
}
class MyClass(var p: Any) {
fun foo(): Int {
p = "xyz"
if (p is String) {
return bar(p)
}
return -1
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
fun bar(s: Any): Int {
return s.hashCode()
}
@@ -1,13 +0,0 @@
fun x(): Boolean { return true }
public fun foo(pp: Any): Int {
var p = pp
while(true) {
(p as String).length
if (x()) break
p = 42
}
// Smart cast is NOT possible here
// (we could provide it but p = 42 makes it difficult to understand)
return p.<!UNRESOLVED_REFERENCE!>length<!>()
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
fun x(): Boolean { return true }
public fun foo(pp: Any): Int {
@@ -1,12 +0,0 @@
fun String?.foo(): String {
return this ?: ""
}
class MyClass {
private var s: String? = null
fun bar(): String {
s = "42"
return s.foo()
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
fun String?.foo(): String {
return this ?: ""
}
@@ -1,12 +0,0 @@
fun String?.foo(): String {
return this ?: ""
}
class MyClass {
fun bar(): String {
var s: String? = null
if (4 < 2)
s = "42"
return s.foo()
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
fun String?.foo(): String {
return this ?: ""
}
@@ -1,10 +0,0 @@
// See KT-10061
class My {
val x: Int? get() = 42
}
fun foo(my: My) {
my.x!!
when (my.x) { }
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// See KT-10061
class My {
@@ -1,11 +0,0 @@
// See KT-10061
// FILE: My.java
public class My {
String getSomething() { return "xyz"; }
}
// FILE: My.kt
fun foo(my: My) {
my.something!!
when (my.something) { }
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// See KT-10061
// FILE: My.java
public class My {