FIR: add proper receiver check for protected visibility #KT-48378 Fixed

This commit is contained in:
Mikhail Glukhikh
2021-08-24 12:30:53 +03:00
committed by TeamCityServer
parent 1c1b9547c1
commit 08e498f1f2
16 changed files with 140 additions and 30 deletions
+2 -2
View File
@@ -6,8 +6,8 @@ class B: A()
class C: A() {
fun bar() {
A().foo()
B().foo()
A().<!INVISIBLE_REFERENCE!>foo<!>()
B().<!INVISIBLE_REFERENCE!>foo<!>()
}
}
@@ -13,6 +13,6 @@ class B {
class C: A() {
init {
B.foo() // Error: receiver is not suitable
B.<!INVISIBLE_REFERENCE!>foo<!>() // Error: receiver is not suitable
}
}
@@ -20,6 +20,6 @@ public class AppServiceModule : AbstractModule<String>() {
inline fun <reified T> AbstractModule<Int>.bind() {
val x = <!PROTECTED_CALL_FROM_PUBLIC_INLINE!>bind<!>(javaClass<T>())
x checkType { <!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>_<!><String>() } // check that Class receiver is used instead of extension one
x checkType { _<String>() } // check that Class receiver is used instead of extension one
}
}
@@ -21,7 +21,7 @@ class B : A() {
b.foo
b.bar = b.bar + ""
a.foo
a.<!INVISIBLE_REFERENCE!>foo<!>
// TODO: should be INVISIBLE_SETTER
a.bar = a.bar + ""
@@ -32,7 +32,7 @@ class B : A() {
if (d.x is B) {
d.x.abc // Ok
d.x.foo
d.x.<!INVISIBLE_REFERENCE!>foo<!>
// TODO: should be INVISIBLE_SETTER
d.x.bar = d.x.bar + ""
}
@@ -11,7 +11,7 @@ class Data(var x: A)
class B : A() {
fun baz(a: A, b: B, d: Data) {
a.foo { }
a.<!INVISIBLE_REFERENCE!>foo<!> { }
b.foo { }
@@ -20,7 +20,7 @@ class B : A() {
}
if (d.x is B) {
d.x.foo {}
d.x.<!INVISIBLE_REFERENCE!>foo<!> {}
}
}
}
@@ -11,8 +11,8 @@ fun BaseOuter.foo(): String = ""
class Derived : BaseOuter() {
fun test(foo: Foo) {
if (foo.base is Derived) {
foo.base.foo() checkType { <!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>_<!><String>() } // Resolved to extension
foo.base.bar()
foo.base.foo() checkType { _<String>() } // Resolved to extension
foo.base.<!INVISIBLE_REFERENCE!>bar<!>()
}
}
}
@@ -11,10 +11,10 @@ class Derived : Base() {
override fun bar() { }
protected fun baz(x: Base) {
x.foo()
x.bar()
x.<!INVISIBLE_REFERENCE!>foo<!>()
x.<!INVISIBLE_REFERENCE!>bar<!>()
x.x = x.x + 1
x.<!INVISIBLE_REFERENCE!>x<!> = x.<!INVISIBLE_REFERENCE!>x<!> + 1
x.y = x.y + 1
if (x is Derived) {
@@ -72,7 +72,7 @@ class E : C() {
class F : C() {
fun test8(c: C) {
doSmth(c.i)
doSmth(c.<!INVISIBLE_REFERENCE!>i<!>)
}
}
@@ -12,7 +12,7 @@ fun foo(javaClass: JavaClass) {
class X : JavaClass() {
fun foo(other: JavaClass) {
doSomething { bar() }
other.doSomething { bar() }
other.<!INVISIBLE_REFERENCE!>doSomething<!> { bar() }
}
}