From 574aa0affee438546695da0417fd323bf315b8a4 Mon Sep 17 00:00:00 2001 From: Ivan Kylchik Date: Tue, 30 Jun 2020 21:40:22 +0300 Subject: [PATCH] [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 --- .../testData/resolveWithStdlib/j+k/kt39076.kt | 13 +++++++++++++ .../testData/resolveWithStdlib/j+k/kt39076.txt | 4 ++++ .../fir/FirDiagnosticsWithStdlibTestGenerated.java | 5 +++++ .../kotlin/fir/resolve/calls/Synthetics.kt | 5 ++--- .../box/properties/javaPropertyBoxedGetter.kt | 1 - .../box/properties/javaPropertyBoxedSetter.kt | 1 - 6 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/kt39076.kt create mode 100644 compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/kt39076.txt diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/kt39076.kt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/kt39076.kt new file mode 100644 index 00000000000..4e7ec6305e8 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/kt39076.kt @@ -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" +} \ No newline at end of file diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/kt39076.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/kt39076.txt new file mode 100644 index 00000000000..8aa7242aa55 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/kt39076.txt @@ -0,0 +1,4 @@ +FILE: main.kt + public final fun main(j: R|JavaClass|): R|kotlin/Unit| { + R|/j|.R|/JavaClass.foo| = R|/j|.R|/JavaClass.foo|.R|kotlin/String.plus|(String(OK)) + } diff --git a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithStdlibTestGenerated.java b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithStdlibTestGenerated.java index a75f8b23420..bece5da1881 100644 --- a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithStdlibTestGenerated.java +++ b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithStdlibTestGenerated.java @@ -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"); diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Synthetics.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Synthetics.kt index 66f24316b67..5f9a6591b90 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Synthetics.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Synthetics.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 }) } diff --git a/compiler/testData/codegen/box/properties/javaPropertyBoxedGetter.kt b/compiler/testData/codegen/box/properties/javaPropertyBoxedGetter.kt index 63593279707..5f19b992956 100644 --- a/compiler/testData/codegen/box/properties/javaPropertyBoxedGetter.kt +++ b/compiler/testData/codegen/box/properties/javaPropertyBoxedGetter.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // TARGET_BACKEND: JVM // FILE: JavaClass.java diff --git a/compiler/testData/codegen/box/properties/javaPropertyBoxedSetter.kt b/compiler/testData/codegen/box/properties/javaPropertyBoxedSetter.kt index 6999726c8dc..cdde2f57f6c 100644 --- a/compiler/testData/codegen/box/properties/javaPropertyBoxedSetter.kt +++ b/compiler/testData/codegen/box/properties/javaPropertyBoxedSetter.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // TARGET_BACKEND: JVM // FILE: JavaClass.java