[FIR, IR] Prohibit actualization of expect Kotlin property to Java field

The problem from KT-63624 was that during matching phase we must choose
only one candidate, but in Java we can have two successfully matched
properties: 1) from field and 2) from method, which overrides Kotlin
property.
See test `propertyAgainstJavaPrivateFieldAndPublicMethod.kt`.
As a result, we choose field candidate, throw away method candidate, and
then fail during visibility check.

Instead of inventing special rule of prioritizing field over method
it was decided to prohibit actualization to Java field at all because:

1. It doesn't seem that Java fields actualization was implemented in K1
on purpose
2. People usually don't use public Java fields, and use instead
private field + getter, especially when compatibility is important, so
it shouldn't be a breaking change

Besides that, such solution simplifies code and is consistent with
the current logic of matcher, which doesn't expect that two members
can be matched successfully. Also, it fixes KT-63624 and KT-63667.

^KT-63624 Fixed
^KT-63667 Fixed
This commit is contained in:
Roman Efremov
2023-12-19 15:32:38 +01:00
committed by Space Team
parent 3f95e99e29
commit 30aad31ece
16 changed files with 89 additions and 7 deletions
@@ -34,6 +34,7 @@ sealed class ExpectActualMatchingCompatibility : ExpectActualCompatibility<Nothi
ExpectActualCompatibility.MismatchOrIncompatible<Nothing>
object CallableKind : Mismatch("callable kinds are different (function vs property)")
object ActualJavaField : Mismatch("actualization to Java field is prohibited")
object ParameterShape : Mismatch("parameter shapes are different (extension vs non-extension)")
object ParameterCount : Mismatch("number of value parameters is different")
object FunctionTypeParameterCount : Mismatch(TYPE_PARAMETER_COUNT)