[FIR] Fix synthetic property is not var due to Nullable on parameter

Synthetic property is var when it have setter. The latter is set up
in property when its parameter type is equal to getter return type. In
case of using @Nullable, parameter type of setter is not equal to
return type of getter, because the latter is flexible type. So to fix
this verification should occur using not null types

#KT-39076 Fixed
This commit is contained in:
Ivan Kylchik
2020-06-30 21:40:22 +03:00
parent 48c5f48af0
commit 574aa0affe
6 changed files with 24 additions and 5 deletions
@@ -0,0 +1,13 @@
// FILE: JavaClass.java
import org.jetbrains.annotations.Nullable;
public class JavaClass {
private String myFoo = "";
public String getFoo() { return myFoo; }
public void setFoo(@Nullable String s) { myFoo = s; }
}
// FILE: main.kt
fun main(j: JavaClass) {
j.foo += "OK"
}
@@ -0,0 +1,4 @@
FILE: main.kt
public final fun main(j: R|JavaClass|): R|kotlin/Unit| {
R|<local>/j|.R|/JavaClass.foo| = R|<local>/j|.R|/JavaClass.foo|.R|kotlin/String.plus|(String(OK))
}
@@ -870,6 +870,11 @@ public class FirDiagnosticsWithStdlibTestGenerated extends AbstractFirDiagnostic
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/KotlinClassParameterGeneric.kt");
}
@TestMetadata("kt39076.kt")
public void testKt39076() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/kt39076.kt");
}
@TestMetadata("LoggerInstance.kt")
public void testLoggerInstance() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/LoggerInstance.kt");
@@ -18,8 +18,7 @@ import org.jetbrains.kotlin.fir.symbols.CallableId
import org.jetbrains.kotlin.fir.symbols.StandardClassIds
import org.jetbrains.kotlin.fir.symbols.SyntheticSymbol
import org.jetbrains.kotlin.fir.symbols.impl.*
import org.jetbrains.kotlin.fir.types.ConeClassLikeType
import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
import org.jetbrains.kotlin.fir.types.*
import org.jetbrains.kotlin.load.java.propertyNameByGetMethodName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.util.capitalizeDecapitalize.capitalizeAsciiOnly
@@ -102,7 +101,7 @@ class FirSyntheticPropertiesScope(
val parameter = setter.valueParameters.singleOrNull() ?: return
if (setter.typeParameters.isNotEmpty() || setter.isStatic) return
val parameterType = (parameter.returnTypeRef as? FirResolvedTypeRef)?.type ?: return
if (parameterType != getterReturnType) return
if (getterReturnType.withNullability(ConeNullability.NOT_NULL) != parameterType.withNullability(ConeNullability.NOT_NULL)) return
matchingSetter = setter
})
}
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM
// FILE: JavaClass.java
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM
// FILE: JavaClass.java