K2: Support Unit-typed synthetic Java property
^KT-57979 Fixed
This commit is contained in:
committed by
Space Team
parent
c022c451a4
commit
e95b8b843b
+6
@@ -20213,6 +20213,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/properties/staticFieldPropertyOverloads.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("unitVsVoid.kt")
|
||||
public void testUnitVsVoid() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/properties/unitVsVoid.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("val.kt")
|
||||
public void testVal() throws Exception {
|
||||
|
||||
+6
@@ -20213,6 +20213,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/properties/staticFieldPropertyOverloads.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("unitVsVoid.kt")
|
||||
public void testUnitVsVoid() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/properties/unitVsVoid.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("val.kt")
|
||||
public void testVal() throws Exception {
|
||||
|
||||
+6
@@ -20213,6 +20213,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/properties/staticFieldPropertyOverloads.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("unitVsVoid.kt")
|
||||
public void testUnitVsVoid() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/properties/unitVsVoid.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("val.kt")
|
||||
public void testVal() throws Exception {
|
||||
|
||||
+6
@@ -20219,6 +20219,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/properties/staticFieldPropertyOverloads.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("unitVsVoid.kt")
|
||||
public void testUnitVsVoid() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/properties/unitVsVoid.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("val.kt")
|
||||
public void testVal() throws Exception {
|
||||
|
||||
@@ -6,18 +6,21 @@
|
||||
package org.jetbrains.kotlin.fir.resolve.calls
|
||||
|
||||
import org.jetbrains.kotlin.fir.*
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.declarations.FirDeclarationOrigin
|
||||
import org.jetbrains.kotlin.fir.declarations.FirSimpleFunction
|
||||
import org.jetbrains.kotlin.fir.declarations.getDeprecationsProviderFromAccessors
|
||||
import org.jetbrains.kotlin.fir.declarations.synthetic.FirSyntheticProperty
|
||||
import org.jetbrains.kotlin.fir.declarations.synthetic.buildSyntheticProperty
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isStatic
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.ReturnTypeCalculator
|
||||
import org.jetbrains.kotlin.fir.scopes.*
|
||||
import org.jetbrains.kotlin.fir.symbols.SyntheticSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.*
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirSyntheticPropertySymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirVariableSymbol
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.name.CallableId
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.name.StandardClassIds
|
||||
import org.jetbrains.kotlin.types.AbstractTypeChecker
|
||||
|
||||
/**
|
||||
@@ -116,7 +119,9 @@ class FirSyntheticPropertiesScope private constructor(
|
||||
getterReturnType = returnTypeCalculator?.tryCalculateReturnTypeOrNull(getter)?.type?.takeUnless { it is ConeErrorType }
|
||||
}
|
||||
|
||||
if ((getterReturnType as? ConeClassLikeType)?.lookupTag?.classId == StandardClassIds.Unit) return
|
||||
// `void` type is the only case when we've got not-nullable non-enhanced Unit from Java
|
||||
// And it doesn't make sense to make a synthetic property for `void` typed getters
|
||||
if (getterReturnType?.isUnit == true && CompilerConeAttributes.EnhancedNullability !in getterReturnType.attributes) return
|
||||
|
||||
if (!getterSymbol.hasJavaOverridden()) return
|
||||
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
// ISSUE: KT-57979
|
||||
|
||||
// FILE: J.java
|
||||
import org.jetbrains.annotations.*;
|
||||
|
||||
public class J<T> {
|
||||
@Nullable
|
||||
public T getValue1() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setValue1(T value) {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public T getValue2() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setValue2(T value) {
|
||||
}
|
||||
|
||||
public T getValue3() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setValue3(T value) {
|
||||
}
|
||||
}
|
||||
// FILE: main.kt
|
||||
|
||||
fun test(j: J<Unit>) {
|
||||
j.value1 = Unit
|
||||
j.value2 = Unit
|
||||
j.value3 = Unit
|
||||
|
||||
j.value1 = null
|
||||
j.value2 = <!NULL_FOR_NONNULL_TYPE!>null<!>
|
||||
j.value3 = null
|
||||
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Unit?")!>j.value1<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Unit")!>j.value2<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Unit..kotlin.Unit?!")!>j.value3<!>
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
// ISSUE: KT-57979
|
||||
|
||||
// FILE: J.java
|
||||
import org.jetbrains.annotations.*;
|
||||
|
||||
public class J<T> {
|
||||
@Nullable
|
||||
public T getValue1() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setValue1(T value) {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public T getValue2() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setValue2(T value) {
|
||||
}
|
||||
|
||||
public T getValue3() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setValue3(T value) {
|
||||
}
|
||||
}
|
||||
// FILE: main.kt
|
||||
|
||||
fun test(j: J<Unit>) {
|
||||
j.value1 = Unit
|
||||
j.value2 = Unit
|
||||
j.value3 = Unit
|
||||
|
||||
j.value1 = null
|
||||
j.value2 = <!NULL_FOR_NONNULL_TYPE!>null<!>
|
||||
j.value3 = null
|
||||
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Unit?")!>j.value1<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Unit")!>j.value2<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("(kotlin.Unit..kotlin.Unit?)")!>j.value3<!>
|
||||
}
|
||||
Generated
+6
@@ -20219,6 +20219,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/properties/staticFieldPropertyOverloads.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("unitVsVoid.kt")
|
||||
public void testUnitVsVoid() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/properties/unitVsVoid.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("val.kt")
|
||||
public void testVal() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user