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
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
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 {
|
||||
if (Visibilities.isPrivate(baseDeclaration.visibility)) return false
|
||||
|
||||
if (overrideCandidate.valueParameters.size != baseDeclaration.valueParameters.size) return false
|
||||
|
||||
val substitutor = buildTypeParametersSubstitutorIfCompatible(overrideCandidate, baseDeclaration) ?: return false
|
||||
@@ -124,6 +127,8 @@ class FirStandardOverrideChecker(session: FirSession) : FirAbstractOverrideCheck
|
||||
overrideCandidate: FirCallableMemberDeclaration<*>,
|
||||
baseDeclaration: FirProperty
|
||||
): Boolean {
|
||||
if (Visibilities.isPrivate(baseDeclaration.visibility)) return false
|
||||
|
||||
if (overrideCandidate !is FirProperty) return false
|
||||
val substitutor = buildTypeParametersSubstitutorIfCompatible(overrideCandidate, baseDeclaration) ?: return false
|
||||
return isEqualReceiverTypes(overrideCandidate.receiverTypeRef, baseDeclaration.receiverTypeRef, substitutor)
|
||||
|
||||
@@ -10,4 +10,5 @@ class C : A() {
|
||||
}
|
||||
}
|
||||
|
||||
// LAZINESS:NoLaziness
|
||||
// LAZINESS:NoLaziness
|
||||
// FIR_COMPARISON
|
||||
@@ -1,10 +1,11 @@
|
||||
class A(
|
||||
private val x: String,
|
||||
private var y: Double
|
||||
open class A(
|
||||
private val x: String,
|
||||
private var y: Double
|
||||
) {
|
||||
fun foo() {
|
||||
val r = {
|
||||
if (x != "abc") throw AssertionError("$x")
|
||||
if (y < 0.0) throw AssertionError("$y < 0.0")
|
||||
y = 0.0
|
||||
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 {
|
||||
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 {
|
||||
val c = <!HIDDEN!>a<!>
|
||||
val c = <!NONE_APPLICABLE!>a<!>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user