[FIR-TEST] Add new testdata generated after changes in previous commit

This commit is contained in:
Dmitriy Novozhilov
2019-12-11 16:16:22 +03:00
parent e9c02a1cca
commit 2536fa0cd5
4578 changed files with 104067 additions and 1 deletions
@@ -0,0 +1,163 @@
@<!SYNTAX!><!>myAnnotation public
package illegal_modifiers
abstract class A() {
abstract final fun f()
abstract open fun g()
final open fun h() {}
open var r: String
get
abstract protected set
}
final interface T {}
class FinalClass() {
open fun foo() {}
val i: Int = 1
open get(): Int = field
var j: Int = 1
open set(v: Int) {}
}
private public class C
private public object D
//A sample annotation to check annotation usage in parameters.
annotation class annotated(val text: String = "not given")
//Check legal modifiers in constructor
class LegalModifier(val a: Int, @annotated private var b: String, @annotated vararg v: Int)
//Check illegal modifier in constructor parameters
class IllegalModifiers1(
in
out
reified
enum
private
const
a: Int)
//Check multiple illegal modifiers in constructor
class IllegalModifiers2(private abstract a: Int)
//Check annotations with illegal modifiers in constructor
class IllegalModifiers3(@annotated public abstract b: String)
//Check annotations and vararg with illegal modifiers in constructor
class IllegalModifiers4(val a: Int, @annotated("a text") protected vararg v: Int)
//Check illegal modifiers for functions and catch block
abstract class IllegalModifiers5() {
//Check illegal modifier in function parameter
abstract fun foo(public a: Int, vararg v: String)
//Check multiple illegal modifiers in function parameter
abstract fun bar(public abstract a: Int, vararg v: String)
//Check annotations with illegal modifiers
abstract fun baz(@annotated("a text") public abstract a: Int)
private fun qux() {
//Check illegal modifier in catch block
try {} catch (in out reified enum public e: Exception) {}
//Check multiple illegal modifiers in catch block
try {} catch (in out reified enum abstract public e: Exception) {}
//Check annotations with illegal modifiers
try {} catch (@annotated("a text") abstract public e: Exception) {}
}
}
//Check illegal modifiers on anonymous initializers
abstract class IllegalModifiers6() {
public init {}
private init {}
protected init {}
vararg init {}
abstract init {}
open init {}
final init {}
public @annotated init {}
private @IllegalModifiers6() init {}
}
// strange inappropriate modifiers usages
override
out
in
vararg
reified
class IllegalModifiers7() {
enum
inner
annotation
out
in
vararg
reified
val x = 1
enum
inner
annotation
out
in
vararg
reified
const
fun foo() {}
}
// Secondary constructors
class IllegalModifiers8 {
abstract
enum
open
inner
annotation
override
out
in
final
vararg
reified
const<!SYNTAX!><!>
constructor() {}
constructor(private enum abstract x: Int) {}
}
class IllegalModifiers9 {
private protected constructor() {}
private internal constructor(x: Int) {}
}
// Illegal modifiers on primary constructor
class IllegalModifiers10
abstract
enum
open
inner
annotation
override
out
in
final
vararg
reified
const constructor()
class IllegalModifiers11 private protected constructor()
class Outer {
inner sealed class Inner
}
@@ -0,0 +1,6 @@
fun foo() {
public class A
private class B
protected class C
internal class D
}
@@ -0,0 +1,12 @@
annotation class My(
public val x: Int,
protected val y: Int,
internal val z: Int,
private val w: Int
)
open class Your {
open val x: Int = 0
}
annotation class His(override val x: Int): Your()
@@ -0,0 +1,110 @@
// !DIAGNOSTICS:-UNUSED_VARIABLE,-CAST_NEVER_SUCCEEDS,-DIVISION_BY_ZERO
import kotlin.reflect.KProperty
const val topLevel: Int = 0
const val topLevelInferred = 1
const var topLeveLVar: Int = 2
private val privateTopLevel = 3
object A {
const val inObject: Int = 4
}
class B(const val constructor: Int = 5)
abstract class C {
open const val x: Int = 6
abstract const val y: Int = 7
companion object {
const val inCompaionObject = 8
}
}
object D : C() {
override const val x: Int = 9
const val inObject = 10
final const val final = 11
const val withoutInitializer: Int
init {
withoutInitializer = 12
}
}
const val delegated: Int by Delegate()
const val withGetter: Int
get() = 13
const val withExplicitDefaultGetter: Int = 1
get
fun foo(): Int {
const val local: Int = 14
return 15
}
enum class MyEnum {
A {
const val inEnumEntry = 16
};
const val inEnum = 17
}
class Outer {
inner class Inner {
object C {
const val a = 18
}
}
}
const val defaultGetter = 19
get
const val nonConstInitializer1 = foo()
const val nonConstInitializer2 = 1 as String
const val nonConstInitializer3 = 1.0 as String
const val nonConstInitializer4 = 1 as Double
const val nonConstInitializer5 = "2" as Int
const val nonConstInitializer6 = 1/0
const val nonConstInitializer7 = -1/0
const val nonConstInitializer8 = 1/0 - 1/0
const val nonConstInitializer9 = 1.0/0.0 - 1/0
const val nonConstInitializer10 = 0/0
const val nonConstInitializer11 = 1 % 0
const val nonConstInitializer12 = 0 % 0
const val nonConstInitializer13 = 0.mod(0)
const val nonConstInitializer14 = 0.rem(0)
const val nonConstInitializer15 = 0.div(0)
const val constInitializer1 = 1.0/0
const val constInitializer2 = 1/0.0
const val constInitializer3 = 1.0/0.0
const val constInitializer4 = -1.0/0
const val constInitializer5 = 0.0/0
const val constInitializer6 = 42 + 1.0/0
const val constInitializer7 = 42 - 1.0/0
const val constInitializer8 = 1.0/0 - 1.0/0
const val constInitializer9 = 0.0/0 + 1.0/0
const val constInitializer10 = 1.0 % 0
const val constInitializer11 = 0.0 % 0
const val constInitializer12 = (-1.0) % 0
const val constInitializer13 = 1.0.rem(0)
const val constInitializer14 = 1.0.mod(0)
const val constInitializer15 = 1.0.div(0)
// ------------------
class Delegate {
operator fun getValue(thisRef: Any?, prop: KProperty<*>): Int = 1
operator fun setValue(thisRef: Any?, prop: KProperty<*>, value: Int) = Unit
}
@@ -0,0 +1,3 @@
// !WITH_NEW_INFERENCE
annotation class A(val a: IntArray = arrayOf(1))
annotation class B(val a: IntArray = intArrayOf(1))
@@ -0,0 +1,18 @@
const val aConst = 1
const val bConst = aConst + 1
const val boolVal = bConst > 1 || (B.boolVal && A.boolVal)
const val stringInterpolation = "Result: ${B.boolVal}"
object A {
const val boolVal = bConst + 3 == 5
const val recursive1: Int = 1 + B.recursive2
}
class B {
companion object {
const val boolVal = A.boolVal
const val recursive2: Int = A.recursive1 + 2
}
}
@@ -0,0 +1,26 @@
// FILE: A.java
public class A {
public static final int X = 1;
public static final int Y;
public final int z = 3;
static {
Y = 2;
}
}
// FILE: main.kt
annotation class Ann(val x: Int)
@Ann(A.X)
fun main1() {}
@Ann(A.Y)
fun main2() {}
val q = A()
@Ann(q.z)
fun main3() {}
@@ -0,0 +1,15 @@
// FILE: A.java
public class A {
public static final String FOO = "foo";
}
// FILE: B.java
public class B extends A {
}
// FILE: main.kt
const val K1 = B.FOO
const val K2 = A.FOO
@@ -0,0 +1,19 @@
// FILE: Bar.java
public class Bar {
public static final int BAR = Foo.FOO + 1;
}
// FILE: Test.kt
class Foo {
companion object {
const val FOO = 1
}
}
class Baz {
companion object {
const val BAZ = Bar.BAR + 1
}
}
@@ -0,0 +1,19 @@
// FILE: Context.java
public interface Context {
String BEAN = "context";
}
// FILE: Test.kt
annotation class Resource(val name: String)
class MyController {
companion object {
private const val foo = Context.BEAN
}
@Resource(name = Context.BEAN)
fun setContext() {
}
}
@@ -0,0 +1,21 @@
// !LANGUAGE: -DivisionByZeroInConstantExpressions
// !DIAGNOSTICS:-DIVISION_BY_ZERO
const val a = 1 / 0.0
const val b = 1.0 / 0
const val c = 0.0 / 0
const val d = 1.0 % 0
const val e = 0.0 % 0
const val f = 0.0.mod(0)
const val g = 0.0.rem(0)
const val h = 0.0.div(0)
const val i = 1 / 0
val nonConst1 = 1.0 / 0
val nonConst2 = 1 / 0
val nonConst3 = 1.0 % 0
val nonConst4 = 1 % 0
val nonConst5 = 1.mod(0)
val nonConst6 = 1.rem(0)
val nonConst7 = 1.div(0)
@@ -0,0 +1,17 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
const val intConst = 1
const val longConst: Long = 1
const val boolConst = true
const val stringConst = "empty"
enum class MyEnum { A }
const val enumConst: MyEnum = MyEnum.A
const val arrayConst: Array<String> = arrayOf("1")
const val intArrayConst: IntArray = intArrayOf()
const val unresolvedConst1 = <!UNRESOLVED_REFERENCE!>Unresolved<!>
const var unresolvedConst2 = <!UNRESOLVED_REFERENCE!>Unresolved<!>
const val unresolvedConst3 = <!UNRESOLVED_REFERENCE!>Unresolved<!>
get() = 10
@@ -0,0 +1,55 @@
companion class A {
companion object {
}
}
class B {
companion object
val c: Int = 1
}
class C {
companion object A {
}
}
class D {
companion object A {
companion object {
}
}
}
companion object G {
companion object
}
companion interface H {
companion object
}
class J {
companion object C {
companion object
}
}
companion enum class Enum {
E1,
E2;
companion object
}
companion fun main() {
}
companion var prop: Int = 1
companion get
companion set
class Z(companion val c: Int)
@@ -0,0 +1,23 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE
interface Foo<T>
interface Foo1<in out T>
interface Foo2<in in T>
fun test1(foo: Foo<in out Int>) = foo
fun test2(): Foo<in in Int> = throw Exception()
fun test3() {
val f: Foo<out out out out Int>
class Bzz<in in T>
}
class A {
fun <out out T> bar() {
}
}
fun test4(a: A) {
a.bar<out out Int>()
}
@@ -0,0 +1,20 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
inline fun foo(noinline x: Int) {}
inline fun bar(y: Int, crossinline x: String) {}
fun gav(noinline x: (Int) -> Unit, crossinline y: (String) -> Int) {}
inline fun correct(noinline x: (Int) -> Unit, crossinline y: (String) -> Int) {}
inline fun incompatible(noinline crossinline x: () -> String) {}
class FunctionSubtype : () -> Unit {
override fun invoke() {}
}
inline fun functionSubtype(
noinline f: FunctionSubtype,
crossinline g: FunctionSubtype
) { }
@@ -0,0 +1,7 @@
interface My {
internal val x: Int
internal val xxx: Int
get() = 0
internal fun foo(): Int
internal fun bar() = 42
}
@@ -0,0 +1,52 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
fun f(vararg x: Int) {}
val inVal: (vararg x: Int)->Unit = {}
fun inParam(fn: (vararg x: Int)->Unit) {}
fun inParamNested(fn1: (fn2: (vararg n: Int)->Unit)->Unit) {}
fun inReturn(): (vararg x: Int)->Unit = {}
class A : (vararg Int)->Unit {
override fun invoke(p1: Int) {
var lambda: (vararg x: Int)->Unit = {}
}
val prop: (vararg x: Int)->Unit
get(): (vararg x: Int)->Unit = {}
}
val allProhibited: (abstract
annotation
companion
const
crossinline
data
enum
external
final
in
inline
inner
internal
lateinit
noinline
open
operator
out
override
private
protected
public
reified
sealed
tailrec
vararg
x: Int)->Unit = {}
val valProhibited: (val x: Int)->Unit = {}
val varProhibited: (var x: Int)->Unit = {}
@@ -0,0 +1,10 @@
interface My {
open fun foo()
open fun bar() {}
open abstract fun baz(): Int
open val x: Int
open val y: String
get() = ""
open abstract val z: Double
}
@@ -0,0 +1,39 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
class Example
fun Example.plus(other: Example) = 0
operator infix fun Example.minus(other: Example) = 0
operator infix fun Example.times(other: Example) = 0
fun Example.div(other: Example) = 0
fun a() {
with (Example()) {
operator infix fun Example.plus(other: Example) = ""
fun Example.minus(other: Example) = ""
operator infix fun Example.times(other: Example) = ""
fun Example.div(other: Example) = ""
with (Example()) {
val a = Example()
val b = Example()
consumeString(a + b)
<!INAPPLICABLE_CANDIDATE!>consumeInt<!>(a - b)
consumeString(a plus b)
<!INAPPLICABLE_CANDIDATE!>consumeInt<!>(a minus b)
a * b
a / b
a times b
a div b
}
}
}
fun consumeInt(i: Int) {}
fun consumeString(s: String) {}
@@ -0,0 +1,45 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER, -EXTENSION_SHADOWED_BY_MEMBER
class Example {
<!INAPPLICABLE_INFIX_MODIFIER!>operator infix fun plus(other: Example) = 0<!>
fun minus(other: Example) = 0
<!INAPPLICABLE_INFIX_MODIFIER!>operator infix fun times(other: Example) = 0<!>
fun div(other: Example) = 0
}
fun Example.plus(other: Example) = ""
operator infix fun Example.minus(other: Example) = ""
operator infix fun Example.times(other: Example) = ""
fun Example.div(other: Example) = ""
fun a() {
val a = Example()
val b = Example()
a + b
a - b
a * b
a / b
a plus b
a minus b
a times b
a div b
with (Example()) {
consumeInt(this + a)
<!INAPPLICABLE_CANDIDATE!>consumeString<!>(this - b)
consumeInt(this * a)
consumeInt(this / b)
consumeInt(this plus a)
<!INAPPLICABLE_CANDIDATE!>consumeString<!>(this minus b)
consumeInt(this times a)
consumeInt(this div b)
}
}
fun consumeInt(i: Int) {}
fun consumeString(s: String) {}
@@ -0,0 +1,45 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER, -EXTENSION_SHADOWED_BY_MEMBER
open class Example {
fun invoke() = 0
fun get(i: Int) = 0
fun component1() = 0
fun component2() = 0
fun inc() = Example()
fun plus(o: Example) = 0
}
class Example2 : Example()
operator fun Example.invoke() = ""
operator fun Example.get(i: Int) = ""
operator fun Example.component1() = ""
operator fun Example.component2() = ""
operator fun Example.inc() = Example2()
infix fun Example.plus(o: Example) = ""
fun test() {
var a = Example()
val b = Example()
<!INAPPLICABLE_CANDIDATE!>consumeString<!>(a())
<!INAPPLICABLE_CANDIDATE!>consumeString<!>(a[1])
val (x, y) = Example()
<!INAPPLICABLE_CANDIDATE!>consumeString<!>(x)
<!INAPPLICABLE_CANDIDATE!>consumeString<!>(y)
<!INAPPLICABLE_CANDIDATE!>consumeExample2<!>(++a)
<!INAPPLICABLE_CANDIDATE!>consumeString<!>(a plus b)
}
fun consumeInt(i: Int) {}
fun consumeString(s: String) {}
fun consumeExample2(e: Example2) {}
@@ -0,0 +1,2 @@
class A private constructor<!SYNTAX!><!> {
}
@@ -0,0 +1,9 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
annotation class Ann(val x: Int = 1)
class A private (val x: Int) {
inner class B @Ann(2) (val y: Int)
fun foo() {
class C private @Ann(3) (args: Int)
}
}
@@ -0,0 +1,12 @@
interface My {
private val x: Int
private abstract val xx: Int
private val xxx: Int
get() = 0
final val y: Int
final val yy: Int
get() = 1
private fun foo(): Int
// ok
private fun bar() = 42
}
@@ -0,0 +1,21 @@
class My(protected val x: Int) {
class Her(protected val x: Int)
inner class Its(protected val x: Int)
}
object Your {
protected fun foo() = 3
}
annotation class His(protected val x: Int)
enum class Our(protected val x: Int) {
FIRST(42) {
protected fun foo() = 13
}
}
interface Their {
protected fun foo() = 7
}
@@ -0,0 +1,10 @@
open interface First
// Now inspection
abstract interface Second
// Now inspection
final enum class Third {
FOURTH,
FIFTH
}
// Now inspection
final object Sixth
@@ -0,0 +1,41 @@
abstract abstract class Foo
public public class Bar
open open final class Baz {
private private fun foo() {}
}
class Bzz(public public val q: Int = 1) {
public public val x: Int = 2
public val y: Int
public public get() = 3
val z: Int
open final get() = 4
public public class B(public public val z: Int = 1) {
public public val y: Int = 2
public val x: Int
public public get() = 3
}
public public object C {
public public val y: Int = 1
public public fun z(): Int = 1
}
}
public public val bar: Int = 1
public public fun foo(): Int = 1
fun test() {
public public class B(public public val z: Int = 1) {
public public val y: Int = 2
public val x: Int
public public get() = 3
}
}