FIR: bail out early for override check if base candidate is private
This commit is contained in:
committed by
Mikhail Glukhikh
parent
09640d9d63
commit
a884555171
+5
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.fir.scopes.impl
|
package org.jetbrains.kotlin.fir.scopes.impl
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||||
import org.jetbrains.kotlin.fir.FirSession
|
import org.jetbrains.kotlin.fir.FirSession
|
||||||
import org.jetbrains.kotlin.fir.declarations.*
|
import org.jetbrains.kotlin.fir.declarations.*
|
||||||
import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor
|
import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor
|
||||||
@@ -109,6 +110,8 @@ class FirStandardOverrideChecker(session: FirSession) : FirAbstractOverrideCheck
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun isOverriddenFunction(overrideCandidate: FirSimpleFunction, baseDeclaration: FirSimpleFunction): Boolean {
|
override fun isOverriddenFunction(overrideCandidate: FirSimpleFunction, baseDeclaration: FirSimpleFunction): Boolean {
|
||||||
|
if (Visibilities.isPrivate(baseDeclaration.visibility)) return false
|
||||||
|
|
||||||
if (overrideCandidate.valueParameters.size != baseDeclaration.valueParameters.size) return false
|
if (overrideCandidate.valueParameters.size != baseDeclaration.valueParameters.size) return false
|
||||||
|
|
||||||
val substitutor = buildTypeParametersSubstitutorIfCompatible(overrideCandidate, baseDeclaration) ?: return false
|
val substitutor = buildTypeParametersSubstitutorIfCompatible(overrideCandidate, baseDeclaration) ?: return false
|
||||||
@@ -124,6 +127,8 @@ class FirStandardOverrideChecker(session: FirSession) : FirAbstractOverrideCheck
|
|||||||
overrideCandidate: FirCallableMemberDeclaration<*>,
|
overrideCandidate: FirCallableMemberDeclaration<*>,
|
||||||
baseDeclaration: FirProperty
|
baseDeclaration: FirProperty
|
||||||
): Boolean {
|
): Boolean {
|
||||||
|
if (Visibilities.isPrivate(baseDeclaration.visibility)) return false
|
||||||
|
|
||||||
if (overrideCandidate !is FirProperty) return false
|
if (overrideCandidate !is FirProperty) return false
|
||||||
val substitutor = buildTypeParametersSubstitutorIfCompatible(overrideCandidate, baseDeclaration) ?: return false
|
val substitutor = buildTypeParametersSubstitutorIfCompatible(overrideCandidate, baseDeclaration) ?: return false
|
||||||
return isEqualReceiverTypes(overrideCandidate.receiverTypeRef, baseDeclaration.receiverTypeRef, substitutor)
|
return isEqualReceiverTypes(overrideCandidate.receiverTypeRef, baseDeclaration.receiverTypeRef, substitutor)
|
||||||
|
|||||||
@@ -11,3 +11,4 @@ class C : A() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// LAZINESS:NoLaziness
|
// LAZINESS:NoLaziness
|
||||||
|
// FIR_COMPARISON
|
||||||
@@ -1,10 +1,11 @@
|
|||||||
class A(
|
open class A(
|
||||||
private val x: String,
|
private val x: String,
|
||||||
private var y: Double
|
private var y: Double
|
||||||
) {
|
) {
|
||||||
fun foo() {
|
fun foo() {
|
||||||
val r = {
|
val r = {
|
||||||
if (x != "abc") throw AssertionError("$x")
|
if (x != "abc") throw AssertionError("$x")
|
||||||
|
if (y < 0.0) throw AssertionError("$y < 0.0")
|
||||||
y = 0.0
|
y = 0.0
|
||||||
if (y != 0.0) throw AssertionError("$y")
|
if (y != 0.0) throw AssertionError("$y")
|
||||||
}
|
}
|
||||||
@@ -12,7 +13,14 @@ class A(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class B(
|
||||||
|
val x: String,
|
||||||
|
y: Double
|
||||||
|
) : A("abc", y)
|
||||||
|
|
||||||
fun box(): String {
|
fun box(): String {
|
||||||
A("abc", 3.14).foo()
|
A("abc", 3.14).foo()
|
||||||
return "OK"
|
val b = B("OK", 0.42)
|
||||||
|
b.foo()
|
||||||
|
return b.x
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -10,5 +10,5 @@ open class C {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class Subject : C(), A {
|
class Subject : C(), A {
|
||||||
val c = <!HIDDEN!>a<!>
|
val c = <!NONE_APPLICABLE!>a<!>
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user