[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:
@@ -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))
|
||||||
|
}
|
||||||
+5
@@ -870,6 +870,11 @@ public class FirDiagnosticsWithStdlibTestGenerated extends AbstractFirDiagnostic
|
|||||||
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/KotlinClassParameterGeneric.kt");
|
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")
|
@TestMetadata("LoggerInstance.kt")
|
||||||
public void testLoggerInstance() throws Exception {
|
public void testLoggerInstance() throws Exception {
|
||||||
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/LoggerInstance.kt");
|
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.StandardClassIds
|
||||||
import org.jetbrains.kotlin.fir.symbols.SyntheticSymbol
|
import org.jetbrains.kotlin.fir.symbols.SyntheticSymbol
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.*
|
import org.jetbrains.kotlin.fir.symbols.impl.*
|
||||||
import org.jetbrains.kotlin.fir.types.ConeClassLikeType
|
import org.jetbrains.kotlin.fir.types.*
|
||||||
import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
|
|
||||||
import org.jetbrains.kotlin.load.java.propertyNameByGetMethodName
|
import org.jetbrains.kotlin.load.java.propertyNameByGetMethodName
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.util.capitalizeDecapitalize.capitalizeAsciiOnly
|
import org.jetbrains.kotlin.util.capitalizeDecapitalize.capitalizeAsciiOnly
|
||||||
@@ -102,7 +101,7 @@ class FirSyntheticPropertiesScope(
|
|||||||
val parameter = setter.valueParameters.singleOrNull() ?: return
|
val parameter = setter.valueParameters.singleOrNull() ?: return
|
||||||
if (setter.typeParameters.isNotEmpty() || setter.isStatic) return
|
if (setter.typeParameters.isNotEmpty() || setter.isStatic) return
|
||||||
val parameterType = (parameter.returnTypeRef as? FirResolvedTypeRef)?.type ?: 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
|
matchingSetter = setter
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
|
|
||||||
// FILE: JavaClass.java
|
// FILE: JavaClass.java
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
|
|
||||||
// FILE: JavaClass.java
|
// FILE: JavaClass.java
|
||||||
|
|||||||
Reference in New Issue
Block a user