FIR: implement checker for open members

Specifically,

1. NON_FINAL_MEMBER_IN_FINAL_CLASS
2. NON_FINAL_MEMBER_IN_OBJECT
This commit is contained in:
Tianyu Geng
2021-02-16 14:04:34 -08:00
committed by Mikhail Glukhikh
parent 3e9ff3ecda
commit 6b453d9b23
21 changed files with 165 additions and 75 deletions
@@ -10,7 +10,7 @@ inline class A4(var x: Int)
inline class A5(val x: Int, val y: Int)
inline class A6(x: Int, val y: Int)
inline class A7(vararg val x: Int)
inline class A8(open val x: Int)
inline class A8(<!NON_FINAL_MEMBER_IN_FINAL_CLASS!>open<!> val x: Int)
inline class A9(final val x: Int)
class B1 {
@@ -7,14 +7,14 @@ abstract class A() {
<!INCOMPATIBLE_MODIFIERS!>final<!> <!INCOMPATIBLE_MODIFIERS!>open<!> fun h() {}
open var r: String
get
abstract protected set
get
abstract protected set
}
final interface T {}
class FinalClass() {
open fun foo() {}
<!NON_FINAL_MEMBER_IN_FINAL_CLASS!>open<!> fun foo() {}
val i: Int = 1
open get(): Int = field
var j: Int = 1
@@ -32,13 +32,13 @@ class LegalModifier(val a: Int, @annotated private var b: String, @annotated var
//Check illegal modifier in constructor parameters
class IllegalModifiers1(
<!INCOMPATIBLE_MODIFIERS!>in<!>
<!INCOMPATIBLE_MODIFIERS!>out<!>
reified
enum
private
const
a: Int)
<!INCOMPATIBLE_MODIFIERS!>in<!>
<!INCOMPATIBLE_MODIFIERS!>out<!>
reified
enum
private
const
a: Int)
//Check multiple illegal modifiers in constructor
class IllegalModifiers2(<!INCOMPATIBLE_MODIFIERS!>private<!> <!INCOMPATIBLE_MODIFIERS!>abstract<!> a: Int)
@@ -53,26 +53,26 @@ 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 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 (<!INCOMPATIBLE_MODIFIERS!>in<!> <!INCOMPATIBLE_MODIFIERS!>out<!> reified enum public e: Exception) {}
//Check multiple illegal modifiers in catch block
try {} catch (<!INCOMPATIBLE_MODIFIERS!>in<!> <!INCOMPATIBLE_MODIFIERS!>out<!> reified enum abstract public e: Exception) {}
//Check multiple illegal modifiers in function parameter
abstract fun bar(public abstract a: Int, vararg v: String)
//Check annotations with illegal modifiers
try {} catch (@annotated("a text") abstract public e: Exception) {}
}
abstract fun baz(@annotated("a text") public abstract a: Int)
private fun qux() {
//Check illegal modifier in catch block
try {} catch (<!INCOMPATIBLE_MODIFIERS!>in<!> <!INCOMPATIBLE_MODIFIERS!>out<!> reified enum public e: Exception) {}
//Check multiple illegal modifiers in catch block
try {} catch (<!INCOMPATIBLE_MODIFIERS!>in<!> <!INCOMPATIBLE_MODIFIERS!>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
@@ -7,8 +7,8 @@ abstract class A() {
<!INCOMPATIBLE_MODIFIERS!>final<!> <!INCOMPATIBLE_MODIFIERS!>open<!> fun h() {}
<!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>open var r: String<!>
get
<!WRONG_MODIFIER_TARGET!>abstract<!> protected set
get
<!WRONG_MODIFIER_TARGET!>abstract<!> protected set
}
<!WRONG_MODIFIER_TARGET!>final<!> interface T {}
@@ -32,13 +32,13 @@ class LegalModifier(val a: Int, @annotated private var b: String, @annotated var
//Check illegal modifier in constructor parameters
class IllegalModifiers1(
<!WRONG_MODIFIER_TARGET!>in<!>
<!INCOMPATIBLE_MODIFIERS!>out<!>
<!WRONG_MODIFIER_TARGET!>reified<!>
<!WRONG_MODIFIER_TARGET!>enum<!>
<!WRONG_MODIFIER_TARGET!>private<!>
<!WRONG_MODIFIER_TARGET!>const<!>
<!UNUSED_PARAMETER!>a<!>: Int)
<!WRONG_MODIFIER_TARGET!>in<!>
<!INCOMPATIBLE_MODIFIERS!>out<!>
<!WRONG_MODIFIER_TARGET!>reified<!>
<!WRONG_MODIFIER_TARGET!>enum<!>
<!WRONG_MODIFIER_TARGET!>private<!>
<!WRONG_MODIFIER_TARGET!>const<!>
<!UNUSED_PARAMETER!>a<!>: Int)
//Check multiple illegal modifiers in constructor
class IllegalModifiers2(<!WRONG_MODIFIER_TARGET!>private<!> <!INCOMPATIBLE_MODIFIERS!>abstract<!> <!UNUSED_PARAMETER!>a<!>: Int)
@@ -53,26 +53,26 @@ class IllegalModifiers4(val a: Int, @annotated("a text") <!WRONG_MODIFIER_TARGET
//Check illegal modifiers for functions and catch block
abstract class IllegalModifiers5() {
//Check illegal modifier in function parameter
abstract fun foo(<!WRONG_MODIFIER_TARGET!>public<!> a: Int, vararg v: String)
//Check illegal modifier in function parameter
abstract fun foo(<!WRONG_MODIFIER_TARGET!>public<!> a: Int, vararg v: String)
//Check multiple illegal modifiers in function parameter
abstract fun bar(<!WRONG_MODIFIER_TARGET!>public<!> <!WRONG_MODIFIER_TARGET!>abstract<!> a: Int, vararg v: String)
//Check annotations with illegal modifiers
abstract fun baz(@annotated("a text") <!WRONG_MODIFIER_TARGET!>public<!> <!WRONG_MODIFIER_TARGET!>abstract<!> a: Int)
private fun qux() {
//Check illegal modifier in catch block
try {} catch (<!WRONG_MODIFIER_TARGET!>in<!> <!INCOMPATIBLE_MODIFIERS!>out<!> <!WRONG_MODIFIER_TARGET!>reified<!> <!WRONG_MODIFIER_TARGET!>enum<!> <!WRONG_MODIFIER_TARGET!>public<!> e: Exception) {}
//Check multiple illegal modifiers in catch block
try {} catch (<!WRONG_MODIFIER_TARGET!>in<!> <!INCOMPATIBLE_MODIFIERS!>out<!> <!WRONG_MODIFIER_TARGET!>reified<!> <!WRONG_MODIFIER_TARGET!>enum<!> <!WRONG_MODIFIER_TARGET!>abstract<!> <!WRONG_MODIFIER_TARGET!>public<!> e: Exception) {}
//Check multiple illegal modifiers in function parameter
abstract fun bar(<!WRONG_MODIFIER_TARGET!>public<!> <!WRONG_MODIFIER_TARGET!>abstract<!> a: Int, vararg v: String)
//Check annotations with illegal modifiers
try {} catch (@annotated("a text") <!WRONG_MODIFIER_TARGET!>abstract<!> <!WRONG_MODIFIER_TARGET!>public<!> e: Exception) {}
}
abstract fun baz(@annotated("a text") <!WRONG_MODIFIER_TARGET!>public<!> <!WRONG_MODIFIER_TARGET!>abstract<!> a: Int)
private fun qux() {
//Check illegal modifier in catch block
try {} catch (<!WRONG_MODIFIER_TARGET!>in<!> <!INCOMPATIBLE_MODIFIERS!>out<!> <!WRONG_MODIFIER_TARGET!>reified<!> <!WRONG_MODIFIER_TARGET!>enum<!> <!WRONG_MODIFIER_TARGET!>public<!> e: Exception) {}
//Check multiple illegal modifiers in catch block
try {} catch (<!WRONG_MODIFIER_TARGET!>in<!> <!INCOMPATIBLE_MODIFIERS!>out<!> <!WRONG_MODIFIER_TARGET!>reified<!> <!WRONG_MODIFIER_TARGET!>enum<!> <!WRONG_MODIFIER_TARGET!>abstract<!> <!WRONG_MODIFIER_TARGET!>public<!> e: Exception) {}
//Check annotations with illegal modifiers
try {} catch (@annotated("a text") <!WRONG_MODIFIER_TARGET!>abstract<!> <!WRONG_MODIFIER_TARGET!>public<!> e: Exception) {}
}
}
//Check illegal modifiers on anonymous initializers
@@ -1,9 +0,0 @@
object Obj {
fun foo() {}
open fun bar() {}
var x: Int = 0
open var y: Int = 1
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
object Obj {
fun foo() {}
@@ -1,5 +1,5 @@
class Foo {
open fun openFoo() {}
<!NON_FINAL_MEMBER_IN_FINAL_CLASS!>open<!> fun openFoo() {}
fun finalFoo() {}
}
@@ -25,4 +25,4 @@ abstract class A2 {
class B2 : A2()
class C2 : B2() {
override fun foo() {}
}
}
@@ -24,7 +24,7 @@ value class A6(x: Int, val y: Int)
@JvmInline
value class A7(vararg val x: Int)
@JvmInline
value class A8(open val x: Int)
value class A8(<!NON_FINAL_MEMBER_IN_FINAL_CLASS!>open<!> val x: Int)
@JvmInline
value class A9(final val x: Int)
@@ -54,6 +54,6 @@ interface E {
interface F {
companion object {
@JvmField
open val a = 3
<!NON_FINAL_MEMBER_IN_OBJECT!>open<!> val a = 3
}
}
@@ -16,7 +16,7 @@ object B: A() {
@JvmStatic final override fun c() {}
@JvmStatic open fun d() {}
@JvmStatic <!NON_FINAL_MEMBER_IN_OBJECT!>open<!> fun d() {}
}
class C {
@@ -28,6 +28,6 @@ class C {
@JvmStatic final override fun c() {}
@JvmStatic open fun d() {}
@JvmStatic <!NON_FINAL_MEMBER_IN_OBJECT!>open<!> fun d() {}
}
}
}
@@ -30,7 +30,7 @@ class A {
@JvmStatic override val base1: Int = 0
@JvmStatic open fun f() {}
@JvmStatic <!NON_FINAL_MEMBER_IN_OBJECT!>open<!> fun f() {}
override val base2: Int = 0
@JvmStatic get
@@ -42,4 +42,4 @@ class A {
}
@JvmStatic val z2 = 1;
}
}
@@ -30,7 +30,7 @@ class A {
@JvmStatic override val base1: Int = 0
@JvmStatic open fun f() {}
@JvmStatic <!NON_FINAL_MEMBER_IN_OBJECT!>open<!> fun f() {}
override val base2: Int = 0
@JvmStatic get
@@ -42,4 +42,4 @@ class A {
}
@JvmStatic val z2 = 1;
}
}