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 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// KT-4034 An expression of type Nothing may not affect 'definite return' analysis
interface JavaClassifierType
interface TypeUsage
interface JetType
private fun transformClassifierType(classifierType: JavaClassifierType, howThisTypeIsUsed: TypeUsage): JetType? {
null!!
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER
// KT-4034 An expression of type Nothing may not affect 'definite return' analysis
@@ -1,34 +0,0 @@
//KT-1066 false 'Variable cannot be initialized before declaration'
package kt1066
fun randomDigit() = 0.toChar()
fun foo(excluded: Set<Char>) {
var digit : Char
do {
digit = randomDigit()
// ^^^^^ here!
} while (excluded.contains(digit))
}
fun test() {
var sum : Int = 0
var first : Int = 1
var second : Int = 2
var temp : Int //= 0 // variable 'temp' initializer is redundant
while (true)
{
if (second > 4000000)
break
if (second % 2 == 0)
sum += second
temp = second
second = first + second
first = temp
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
//KT-1066 false 'Variable cannot be initialized before declaration'
package kt1066
@@ -1,7 +0,0 @@
//KT-1156 Throwing exception on the right side of elvis operator marks code unreachable
fun foo(maybe: Int?) {
val i : Int = maybe ?: throw RuntimeException("No value")
System.out.println(i)
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
//KT-1156 Throwing exception on the right side of elvis operator marks code unreachable
@@ -1,38 +0,0 @@
//KT-1189 StackOverflow in ide
package kt1189
import java.util.concurrent.locks.ReentrantReadWriteLock
inline fun <T> ReentrantReadWriteLock.write(action: ()->T) : T {
val rl = readLock()
var readCount = 0
val writeCount = getWriteHoldCount()
if(writeCount == 0) {
readCount = getReadHoldCount()
if(readCount > 0)
for(i in 1..readCount)
rl.unlock()
}
val wl = writeLock()
wl.lock()
try {
return action()
}
finally {
if(readCount > 0) {
for(j in 1..readCount) {
rl.lock()
}
}
wl.unlock()
}
}
fun foo() {
try {
return
}
finally {
for (i in 1..10) {}
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
//KT-1189 StackOverflow in ide
package kt1189
import java.util.concurrent.locks.ReentrantReadWriteLock
@@ -1,21 +0,0 @@
//KT-1191 Wrong detection of unused parameters
package kt1191
interface FunctionalList<T> {
val size: Int
val head: T
val tail: FunctionalList<T>
}
fun <T> FunctionalList<T>.plus(element: T) : FunctionalList<T> = object: FunctionalList<T> {
override val size: Int
get() = 1 + this@plus.size
override val tail: FunctionalList<T>
get() = this@plus
override val head: T
get() = element
}
fun foo(unused: Int) = object {
val a : Int get() = unused
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
//KT-1191 Wrong detection of unused parameters
package kt1191
@@ -1,25 +0,0 @@
//KT-1219 Incorrect 'unused value' error in closures
package kt1219
fun <T, R> Iterable<T>.fold(a: R, op: (T, R) -> R) : R {
var r = a
this.foreach { r = op(it, r) } //unused value here
return r
}
//KT-1301 Modification of local of outer function in a local function should not be marked as unused assignment
fun foo(){
var local = 0
fun bar(){
local = 1
}
bar()
System.out.println(local)
}
fun <T> Iterable<T>.foreach(operation: (element: T) -> Unit) {
for (elem in this)
operation(elem)
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
//KT-1219 Incorrect 'unused value' error in closures
package kt1219
@@ -1,17 +0,0 @@
package a
//KT-2166 Control flow analysis doesn't detect that a 'while(true)' loop never terminates
fun foo(): Int {
while (true) {
}
}
//KT-2103 Compiler requires return statement after loop which never exits
fun foo1() : Boolean{
while(true){
if (bar()) continue
return true
}
}
fun bar() : Boolean = true
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
package a
//KT-2166 Control flow analysis doesn't detect that a 'while(true)' loop never terminates
@@ -1,15 +0,0 @@
//KT-2226 Parameter used as delegation by object marked as unused
package a
interface A {
fun foo() : Int
}
class B : A {
override fun foo() = 10
}
fun foo(b: B) : Int {
val o = object : A by b {
}
return o.foo()
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
//KT-2226 Parameter used as delegation by object marked as unused
package a
@@ -1,28 +0,0 @@
//KT-2972 Wrong "unused value" warning when finally is present
import java.io.Closeable
public inline fun <T: Closeable, R> T.use(block: (T)-> R) : R {
var closed = false
try {
return block(this)
} catch (e: Exception) {
closed = true // warning here
try {
this.close()
} catch (closeException: Exception) {
// eat the closeException as we are already throwing the original cause
// and we don't want to mask the real exception
// TODO on Java 7 we should call
// e.addSuppressed(closeException)
// to work like try-with-resources
// http://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html#suppressed-exceptions
}
throw e
} finally {
if (!closed) {
this.close()
}
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
//KT-2972 Wrong "unused value" warning when finally is present
import java.io.Closeable
@@ -1,18 +0,0 @@
//KT-510 `this.` allows initialization without backing field
package kt510
public open class Identifier1() {
var field : Boolean
init {
field = false; // error
}
}
public open class Identifier2() {
var field : Boolean
init {
this.field = false;
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
//KT-510 `this.` allows initialization without backing field
package kt510
@@ -1,38 +0,0 @@
//KT-776 Wrong detection of unreachable code
package kt776
fun test5() : Int {
var x = 0
while(true) {
try {
if(x < 10) {
x++
continue
}
else {
break
}
}
finally {
x++
}
}
return x
}
fun test1() : Int {
try {
if (true) {
return 1
}
else {
return 2
}
}
finally {
doSmth() //unreachable
}
}
fun doSmth() {}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
//KT-776 Wrong detection of unreachable code
package kt776
@@ -1,8 +0,0 @@
//KT-843 Don't highlight incomplete variables as unused
package kt843
fun main() {
// Integer type
val<!SYNTAX!><!> // this word is grey, which looks strange
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
//KT-843 Don't highlight incomplete variables as unused
package kt843
@@ -1,87 +0,0 @@
fun println(obj: Any?) = obj
class Demo0 {
private val some = object {
fun foo() {
println(state)
}
}
private var state: Boolean = true
}
class Demo1 {
private val some = object {
fun foo() {
if (state)
state = true
println(state)
}
}
private var state: Boolean = true
}
class Demo1A {
fun foo() {
if (state)
state = true
println(state)
}
private var state: Boolean = true
}
class Demo2 {
private val some = object {
fun foo() {
if (state)
state = true
else
state = false
println(state)
}
}
private var state: Boolean = true
}
class Demo3 {
private val some = run {
if (state)
state = true
println(state)
}
private var state: Boolean = true
}
fun <T> exec(f: () -> T): T = f()
class Demo4 {
private val some = exec {
if (state)
state = true
println(state)
}
private var state: Boolean = true
}
class Demo5 {
private var state: Boolean = true
private val some = object {
fun foo() {
if (state)
state = true
println(state)
}
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
fun println(obj: Any?) = obj
class Demo0 {
@@ -1,5 +0,0 @@
// !LANGUAGE: -WarningOnMainUnusedParameter
fun main(args: Array<String>) {
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: -WarningOnMainUnusedParameter
fun main(args: Array<String>) {
@@ -1,24 +0,0 @@
fun use(arg: String?) = arg
fun sample(): String? {
try {
if (false) {
return "fail"
} else {
if (false) {
if (false) {
var foo: String? = null
try {
foo = "test"
} catch (e: Exception) {
return "fail"
} finally {
use(foo) // 'foo' is initialized here
}
}
return "fail"
}
}
} finally {}
return null
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
fun use(arg: String?) = arg
fun sample(): String? {
@@ -1,26 +0,0 @@
// !WITH_NEW_INFERENCE
// See also KT-5198 / KT-10186
inline fun doCall(f: () -> Unit) = f()
fun test1(nonLocal: String): String {
val localResult = doCall {
return nonLocal //unreachable
}
return "NON_LOCAL_FAILED $localResult" //unreachable
}
fun doSomething() {}
fun test2() {
fun f(x: Any?) = x
f(null?.let { return })
// false unreachable here
doSomething()
}
fun test3(x: Any?): Boolean =
x?.let {
return true
} ?: false
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !WITH_NEW_INFERENCE
// See also KT-5198 / KT-10186
@@ -1,10 +0,0 @@
fun test(name: String?) {
try {
name?.let {
return
}
}
finally {
name?.hashCode()
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
fun test(name: String?) {
try {
name?.let {
@@ -1,5 +0,0 @@
class AnonymousInitializers(var a: String) {
init {
a = "s"
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
class AnonymousInitializers(var a: String) {
init {
a = "s"
@@ -1,36 +0,0 @@
fun f() {
var foo = 1
try {
foo = 2
throw RuntimeException()
} catch (e: Throwable) {
foo.hashCode()
}
throw Exception()
}
fun g() {
var foo = 1
try {
foo = 2
f()
} catch (e: Throwable) {
foo.hashCode()
}
}
fun h() {
try {
}
finally {
var foo = 1
try {
foo = 2
g()
}
catch (e: Throwable) {
foo.hashCode()
}
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
fun f() {
var foo = 1
try {
@@ -1,6 +0,0 @@
class Test {
lateinit var someRunnable: Runnable
init {
someRunnable = Runnable { someRunnable.run() }
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
class Test {
lateinit var someRunnable: Runnable
init {
@@ -1,8 +0,0 @@
class Foo {
lateinit var bar: String
constructor(baz: Int) {
// At best, we should have error here despite of lateinit
bar += baz
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
class Foo {
lateinit var bar: String
@@ -1,9 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
class Foo() {
lateinit var bar: String
constructor(baz: Int) : this() {
bar = ""
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER
class Foo() {
@@ -1,7 +0,0 @@
class Foo {
lateinit var bar: String
fun init() {
bar = ""
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
class Foo {
lateinit var bar: String
@@ -1,9 +0,0 @@
class Foo {
lateinit var x: String
constructor(y: String) {
x = y
}
constructor()
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
class Foo {
lateinit var x: String
@@ -1,9 +0,0 @@
// !LANGUAGE: -SingleUnderscoreForParameterName
// See KT-8813, KT-9631
fun someApi(f: (Int) -> Unit) = f(42)
fun test() {
someApi(fun(p: Int) {})
// Apparently "p" cannot be removed because the signature is fixed by "someApi
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: -SingleUnderscoreForParameterName
// See KT-8813, KT-9631
@@ -1,15 +0,0 @@
fun foo(numbers: Collection<Int>) {
for (i in numbers) {
val b: Boolean
if (1 < 2) {
b = false
}
else {
b = true
}
use(b)
continue
}
}
fun use(vararg a: Any?) = a
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
fun foo(numbers: Collection<Int>) {
for (i in numbers) {
val b: Boolean