From e8131d6e30a12349f8851df52de50e91b7073281 Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Tue, 17 Dec 2019 17:58:49 +0300 Subject: [PATCH] Choose Java field during overload resolution with a pure Kotlin property ^KT-31244 Fixed --- ...irOldFrontendDiagnosticsTestGenerated.java | 20 +++++++++++ ...mPlatformOverloadsSpecificityComparator.kt | 33 +++++++++++++++++++ .../jvm/platform/JvmPlatformConfigurator.kt | 1 + .../results/FlatSignatureForResolvedCall.kt | 4 ++- .../results/ResolutionResultsHandler.java | 5 +-- .../components/CallableReferenceResolver.kt | 3 ++ .../NewOverloadingConflictResolver.kt | 3 ++ .../results/OverloadingConflictResolver.kt | 9 +++++ .../PlatformOverloadsSpecificityComparator.kt | 18 ++++++++++ .../properties/fieldPropertyOverloads.fir.kt | 27 +++++++++++++++ .../j+k/properties/fieldPropertyOverloads.kt | 27 +++++++++++++++ .../fieldPropertyOverloadsDisabled.fir.kt | 26 +++++++++++++++ .../fieldPropertyOverloadsDisabled.kt | 26 +++++++++++++++ .../fieldPropertyOverloadsNI.fir.kt | 27 +++++++++++++++ .../properties/fieldPropertyOverloadsNI.kt | 27 +++++++++++++++ .../staticFieldPropertyOverloads.fir.kt | 16 +++++++++ .../staticFieldPropertyOverloads.kt | 16 +++++++++ .../checkers/DiagnosticsTestGenerated.java | 20 +++++++++++ .../DiagnosticsUsingJavacTestGenerated.java | 20 +++++++++++ .../kotlin/config/LanguageVersionSettings.kt | 1 + 20 files changed, 326 insertions(+), 3 deletions(-) create mode 100644 compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/JvmPlatformOverloadsSpecificityComparator.kt create mode 100644 compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/results/PlatformOverloadsSpecificityComparator.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/properties/fieldPropertyOverloads.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/properties/fieldPropertyOverloads.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/properties/fieldPropertyOverloadsDisabled.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/properties/fieldPropertyOverloadsDisabled.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/properties/fieldPropertyOverloadsNI.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/properties/fieldPropertyOverloadsNI.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/properties/staticFieldPropertyOverloads.fir.kt create mode 100644 compiler/testData/diagnostics/tests/j+k/properties/staticFieldPropertyOverloads.kt diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java index d32649e011c..f10a3fd331b 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java @@ -12775,6 +12775,21 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/j+k/properties"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); } + @TestMetadata("fieldPropertyOverloads.kt") + public void testFieldPropertyOverloads() throws Exception { + runTest("compiler/testData/diagnostics/tests/j+k/properties/fieldPropertyOverloads.kt"); + } + + @TestMetadata("fieldPropertyOverloadsDisabled.kt") + public void testFieldPropertyOverloadsDisabled() throws Exception { + runTest("compiler/testData/diagnostics/tests/j+k/properties/fieldPropertyOverloadsDisabled.kt"); + } + + @TestMetadata("fieldPropertyOverloadsNI.kt") + public void testFieldPropertyOverloadsNI() throws Exception { + runTest("compiler/testData/diagnostics/tests/j+k/properties/fieldPropertyOverloadsNI.kt"); + } + @TestMetadata("interface.kt") public void testInterface() throws Exception { runTest("compiler/testData/diagnostics/tests/j+k/properties/interface.kt"); @@ -12785,6 +12800,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte runTest("compiler/testData/diagnostics/tests/j+k/properties/isName.kt"); } + @TestMetadata("staticFieldPropertyOverloads.kt") + public void testStaticFieldPropertyOverloads() throws Exception { + runTest("compiler/testData/diagnostics/tests/j+k/properties/staticFieldPropertyOverloads.kt"); + } + @TestMetadata("val.kt") public void testVal() throws Exception { runTest("compiler/testData/diagnostics/tests/j+k/properties/val.kt"); diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/JvmPlatformOverloadsSpecificityComparator.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/JvmPlatformOverloadsSpecificityComparator.kt new file mode 100644 index 00000000000..ec4ee6c6ca1 --- /dev/null +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/JvmPlatformOverloadsSpecificityComparator.kt @@ -0,0 +1,33 @@ +/* + * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.resolve.jvm + +import org.jetbrains.kotlin.config.LanguageFeature +import org.jetbrains.kotlin.config.LanguageVersionSettings +import org.jetbrains.kotlin.descriptors.CallableDescriptor +import org.jetbrains.kotlin.descriptors.ClassDescriptor +import org.jetbrains.kotlin.descriptors.PropertyDescriptor +import org.jetbrains.kotlin.load.java.lazy.descriptors.isJavaField +import org.jetbrains.kotlin.resolve.DescriptorEquivalenceForOverrides +import org.jetbrains.kotlin.resolve.calls.results.PlatformOverloadsSpecificityComparator + +class JvmPlatformOverloadsSpecificityComparator( + val languageVersionSettings: LanguageVersionSettings +) : PlatformOverloadsSpecificityComparator { + override fun isMoreSpecificShape(specific: CallableDescriptor, general: CallableDescriptor): Boolean { + if (specific !is PropertyDescriptor || general !is PropertyDescriptor) return false + + if (specific.dispatchReceiverParameter == null || general.dispatchReceiverParameter == null) return false + if (specific.containingDeclaration !is ClassDescriptor) return false + if (!DescriptorEquivalenceForOverrides + .areEquivalent(specific.containingDeclaration, general.containingDeclaration, allowCopiesFromTheSameDeclaration = true) + ) return false + + if (!languageVersionSettings.supportsFeature(LanguageFeature.PreferJavaFieldOverload)) return false + + return specific.isJavaField && !general.isJavaField + } +} diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/platform/JvmPlatformConfigurator.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/platform/JvmPlatformConfigurator.kt index 4f35241021d..c2ca58f638a 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/platform/JvmPlatformConfigurator.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/platform/JvmPlatformConfigurator.kt @@ -102,6 +102,7 @@ object JvmPlatformConfigurator : PlatformConfiguratorBase( container.useImpl() container.useImpl() container.useImpl() + container.useImpl() container.useImpl() container.useImpl() container.useInstance(FunctionWithBigAritySupport.LanguageVersionDependent) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/results/FlatSignatureForResolvedCall.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/results/FlatSignatureForResolvedCall.kt index 1aad908b9ea..5c21cfdabcb 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/results/FlatSignatureForResolvedCall.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/results/FlatSignatureForResolvedCall.kt @@ -54,11 +54,13 @@ fun > RC.createFlatSignature(): FlatSignature { fun createOverloadingConflictResolver( builtIns: KotlinBuiltIns, module: ModuleDescriptor, - specificityComparator: TypeSpecificityComparator + specificityComparator: TypeSpecificityComparator, + platformOverloadsSpecificityComparator: PlatformOverloadsSpecificityComparator ) = OverloadingConflictResolver( builtIns, module, specificityComparator, + platformOverloadsSpecificityComparator, MutableResolvedCall<*>::getResultingDescriptor, ConstraintSystemBuilderImpl.Companion::forSpecificity, MutableResolvedCall<*>::createFlatSignature, diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/results/ResolutionResultsHandler.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/results/ResolutionResultsHandler.java index 11eb1b9bbe9..257f31560c9 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/results/ResolutionResultsHandler.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/results/ResolutionResultsHandler.java @@ -41,10 +41,11 @@ public class ResolutionResultsHandler { public ResolutionResultsHandler( @NotNull KotlinBuiltIns builtIns, @NotNull ModuleDescriptor module, - @NotNull TypeSpecificityComparator specificityComparator + @NotNull TypeSpecificityComparator specificityComparator, + @NotNull PlatformOverloadsSpecificityComparator platformOverloadsSpecificityComparator ) { overloadingConflictResolver = FlatSignatureForResolvedCallKt.createOverloadingConflictResolver( - builtIns, module, specificityComparator + builtIns, module, specificityComparator, platformOverloadsSpecificityComparator ); } diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolver.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolver.kt index 5224e3ba0da..3d67048d6e0 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolver.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolver.kt @@ -26,6 +26,7 @@ import org.jetbrains.kotlin.resolve.calls.inference.components.NewTypeSubstituto import org.jetbrains.kotlin.resolve.calls.model.* import org.jetbrains.kotlin.resolve.calls.results.FlatSignature import org.jetbrains.kotlin.resolve.calls.results.OverloadingConflictResolver +import org.jetbrains.kotlin.resolve.calls.results.PlatformOverloadsSpecificityComparator import org.jetbrains.kotlin.resolve.calls.results.TypeSpecificityComparator import org.jetbrains.kotlin.resolve.calls.tower.ImplicitScopeTower import org.jetbrains.kotlin.resolve.calls.tower.TowerResolver @@ -36,12 +37,14 @@ class CallableReferenceOverloadConflictResolver( builtIns: KotlinBuiltIns, module: ModuleDescriptor, specificityComparator: TypeSpecificityComparator, + platformOverloadsSpecificityComparator: PlatformOverloadsSpecificityComparator, statelessCallbacks: KotlinResolutionStatelessCallbacks, constraintInjector: ConstraintInjector ) : OverloadingConflictResolver( builtIns, module, specificityComparator, + platformOverloadsSpecificityComparator, { it.candidate }, { statelessCallbacks.createConstraintSystemForOverloadResolution(constraintInjector, builtIns) }, Companion::createFlatSignature, diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/NewOverloadingConflictResolver.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/NewOverloadingConflictResolver.kt index f65a712b44a..03ee92566c3 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/NewOverloadingConflictResolver.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/NewOverloadingConflictResolver.kt @@ -24,6 +24,7 @@ import org.jetbrains.kotlin.resolve.calls.model.KotlinResolutionCandidate import org.jetbrains.kotlin.resolve.calls.model.ResolvedCallArgument import org.jetbrains.kotlin.resolve.calls.results.FlatSignature import org.jetbrains.kotlin.resolve.calls.results.OverloadingConflictResolver +import org.jetbrains.kotlin.resolve.calls.results.PlatformOverloadsSpecificityComparator import org.jetbrains.kotlin.resolve.calls.results.TypeSpecificityComparator import org.jetbrains.kotlin.types.KotlinType import java.util.* @@ -32,12 +33,14 @@ class NewOverloadingConflictResolver( builtIns: KotlinBuiltIns, module: ModuleDescriptor, specificityComparator: TypeSpecificityComparator, + platformOverloadsSpecificityComparator: PlatformOverloadsSpecificityComparator, statelessCallbacks: KotlinResolutionStatelessCallbacks, constraintInjector: ConstraintInjector ) : OverloadingConflictResolver( builtIns, module, specificityComparator, + platformOverloadsSpecificityComparator, { // todo investigate it.resolvedCall.candidateDescriptor diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/results/OverloadingConflictResolver.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/results/OverloadingConflictResolver.kt index 1cf2299a93e..8c4ef9988a8 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/results/OverloadingConflictResolver.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/results/OverloadingConflictResolver.kt @@ -37,6 +37,7 @@ open class OverloadingConflictResolver( private val builtIns: KotlinBuiltIns, private val module: ModuleDescriptor, private val specificityComparator: TypeSpecificityComparator, + private val platformOverloadsSpecificityComparator: PlatformOverloadsSpecificityComparator, private val getResultingDescriptor: (C) -> CallableDescriptor, private val createEmptyConstraintSystem: () -> SimpleConstraintSystem, private val createFlatSignature: (C) -> FlatSignature, @@ -364,6 +365,10 @@ open class OverloadingConflictResolver( return false } + if (platformOverloadsSpecificityComparator.isMoreSpecificShape(call2.candidateDescriptor(), call1.candidateDescriptor())) { + return false + } + return true } @@ -411,6 +416,10 @@ open class OverloadingConflictResolver( if (f.isExpect && !g.isExpect) return false } + if (platformOverloadsSpecificityComparator.isMoreSpecificShape(g, f)) { + return false + } + return true } diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/results/PlatformOverloadsSpecificityComparator.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/results/PlatformOverloadsSpecificityComparator.kt new file mode 100644 index 00000000000..264725aa265 --- /dev/null +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/results/PlatformOverloadsSpecificityComparator.kt @@ -0,0 +1,18 @@ +/* + * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.resolve.calls.results + +import org.jetbrains.kotlin.container.DefaultImplementation +import org.jetbrains.kotlin.descriptors.CallableDescriptor + +@DefaultImplementation(impl = PlatformOverloadsSpecificityComparator.None::class) +interface PlatformOverloadsSpecificityComparator { + fun isMoreSpecificShape(specific: CallableDescriptor, general: CallableDescriptor): Boolean + + object None : PlatformOverloadsSpecificityComparator { + override fun isMoreSpecificShape(specific: CallableDescriptor, general: CallableDescriptor) = false + } +} diff --git a/compiler/testData/diagnostics/tests/j+k/properties/fieldPropertyOverloads.fir.kt b/compiler/testData/diagnostics/tests/j+k/properties/fieldPropertyOverloads.fir.kt new file mode 100644 index 00000000000..c8a90d300a7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/properties/fieldPropertyOverloads.fir.kt @@ -0,0 +1,27 @@ +// SKIP_TXT +// !LANGUAGE: +PreferJavaFieldOverload +// !CHECK_TYPE + +// FILE: CompressionType.java +public enum CompressionType { + ZIP(1.0); + public final double name; + CompressionType(double name) { + this.name = name; + } +} + +// FILE: CollectionWithSize.java +public abstract class CollectionWithSize implements java.util.Collection { + public final String size = ""; +} + +// FILE: main.kt + +fun main(c: CollectionWithSize) { + CompressionType.ZIP.name checkType { _() } + c.size checkType { _() } + + CompressionType.ZIP::name checkType { _>() } + c::size checkType { _>() } +} diff --git a/compiler/testData/diagnostics/tests/j+k/properties/fieldPropertyOverloads.kt b/compiler/testData/diagnostics/tests/j+k/properties/fieldPropertyOverloads.kt new file mode 100644 index 00000000000..76f58ec7f95 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/properties/fieldPropertyOverloads.kt @@ -0,0 +1,27 @@ +// SKIP_TXT +// !LANGUAGE: +PreferJavaFieldOverload +// !CHECK_TYPE + +// FILE: CompressionType.java +public enum CompressionType { + ZIP(1.0); + public final double name; + CompressionType(double name) { + this.name = name; + } +} + +// FILE: CollectionWithSize.java +public abstract class CollectionWithSize implements java.util.Collection { + public final String size = ""; +} + +// FILE: main.kt + +fun main(c: CollectionWithSize) { + CompressionType.ZIP.name checkType { _() } + c.size checkType { _() } + + CompressionType.ZIP::name checkType { _>() } + c::size checkType { _>() } +} diff --git a/compiler/testData/diagnostics/tests/j+k/properties/fieldPropertyOverloadsDisabled.fir.kt b/compiler/testData/diagnostics/tests/j+k/properties/fieldPropertyOverloadsDisabled.fir.kt new file mode 100644 index 00000000000..a7437470320 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/properties/fieldPropertyOverloadsDisabled.fir.kt @@ -0,0 +1,26 @@ +// SKIP_TXT +// !CHECK_TYPE + +// FILE: CompressionType.java +public enum CompressionType { + ZIP(1.0); + public final double name; + CompressionType(double name) { + this.name = name; + } +} + +// FILE: CollectionWithSize.java +public abstract class CollectionWithSize implements java.util.Collection { + public final String size = ""; +} + +// FILE: main.kt + +fun main(c: CollectionWithSize) { + CompressionType.ZIP.name checkType { _() } + c.size checkType { _() } + + CompressionType.ZIP::name checkType { _>() } + c::size checkType { _>() } +} diff --git a/compiler/testData/diagnostics/tests/j+k/properties/fieldPropertyOverloadsDisabled.kt b/compiler/testData/diagnostics/tests/j+k/properties/fieldPropertyOverloadsDisabled.kt new file mode 100644 index 00000000000..824367debaa --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/properties/fieldPropertyOverloadsDisabled.kt @@ -0,0 +1,26 @@ +// SKIP_TXT +// !CHECK_TYPE + +// FILE: CompressionType.java +public enum CompressionType { + ZIP(1.0); + public final double name; + CompressionType(double name) { + this.name = name; + } +} + +// FILE: CollectionWithSize.java +public abstract class CollectionWithSize implements java.util.Collection { + public final String size = ""; +} + +// FILE: main.kt + +fun main(c: CollectionWithSize) { + CompressionType.ZIP.name checkType { _() } + c.size checkType { _() } + + CompressionType.ZIP::name checkType { _>() } + c::size checkType { _>() } +} diff --git a/compiler/testData/diagnostics/tests/j+k/properties/fieldPropertyOverloadsNI.fir.kt b/compiler/testData/diagnostics/tests/j+k/properties/fieldPropertyOverloadsNI.fir.kt new file mode 100644 index 00000000000..36a05a378c7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/properties/fieldPropertyOverloadsNI.fir.kt @@ -0,0 +1,27 @@ +// SKIP_TXT +// !LANGUAGE: +PreferJavaFieldOverload +NewInference +// !CHECK_TYPE + +// FILE: CompressionType.java +public enum CompressionType { + ZIP(1.0); + public final double name; + CompressionType(double name) { + this.name = name; + } +} + +// FILE: CollectionWithSize.java +public abstract class CollectionWithSize implements java.util.Collection { + public final String size = ""; +} + +// FILE: main.kt + +fun main(c: CollectionWithSize) { + CompressionType.ZIP.name checkType { _() } + c.size checkType { _() } + + CompressionType.ZIP::name checkType { _>() } + c::size checkType { _>() } +} diff --git a/compiler/testData/diagnostics/tests/j+k/properties/fieldPropertyOverloadsNI.kt b/compiler/testData/diagnostics/tests/j+k/properties/fieldPropertyOverloadsNI.kt new file mode 100644 index 00000000000..77fd034669b --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/properties/fieldPropertyOverloadsNI.kt @@ -0,0 +1,27 @@ +// SKIP_TXT +// !LANGUAGE: +PreferJavaFieldOverload +NewInference +// !CHECK_TYPE + +// FILE: CompressionType.java +public enum CompressionType { + ZIP(1.0); + public final double name; + CompressionType(double name) { + this.name = name; + } +} + +// FILE: CollectionWithSize.java +public abstract class CollectionWithSize implements java.util.Collection { + public final String size = ""; +} + +// FILE: main.kt + +fun main(c: CollectionWithSize) { + CompressionType.ZIP.name checkType { _() } + c.size checkType { _() } + + CompressionType.ZIP::name checkType { _>() } + c::size checkType { _>() } +} diff --git a/compiler/testData/diagnostics/tests/j+k/properties/staticFieldPropertyOverloads.fir.kt b/compiler/testData/diagnostics/tests/j+k/properties/staticFieldPropertyOverloads.fir.kt new file mode 100644 index 00000000000..9369695fe25 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/properties/staticFieldPropertyOverloads.fir.kt @@ -0,0 +1,16 @@ +// SKIP_TXT +// !LANGUAGE: +PreferJavaFieldOverload +// FILE: a/JClass.java +package a; +public class JClass { + public static int foo = 42; +} +// FILE: a.kt +package b +val foo = 42 + +// FILE: b.kt + +import a.JClass.foo +import b.foo +fun test() { foo } diff --git a/compiler/testData/diagnostics/tests/j+k/properties/staticFieldPropertyOverloads.kt b/compiler/testData/diagnostics/tests/j+k/properties/staticFieldPropertyOverloads.kt new file mode 100644 index 00000000000..3100d018d92 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/properties/staticFieldPropertyOverloads.kt @@ -0,0 +1,16 @@ +// SKIP_TXT +// !LANGUAGE: +PreferJavaFieldOverload +// FILE: a/JClass.java +package a; +public class JClass { + public static int foo = 42; +} +// FILE: a.kt +package b +val foo = 42 + +// FILE: b.kt + +import a.JClass.foo +import b.foo +fun test() { foo } diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 4652cc3c7ce..1c3a327db55 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -12782,6 +12782,21 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/j+k/properties"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); } + @TestMetadata("fieldPropertyOverloads.kt") + public void testFieldPropertyOverloads() throws Exception { + runTest("compiler/testData/diagnostics/tests/j+k/properties/fieldPropertyOverloads.kt"); + } + + @TestMetadata("fieldPropertyOverloadsDisabled.kt") + public void testFieldPropertyOverloadsDisabled() throws Exception { + runTest("compiler/testData/diagnostics/tests/j+k/properties/fieldPropertyOverloadsDisabled.kt"); + } + + @TestMetadata("fieldPropertyOverloadsNI.kt") + public void testFieldPropertyOverloadsNI() throws Exception { + runTest("compiler/testData/diagnostics/tests/j+k/properties/fieldPropertyOverloadsNI.kt"); + } + @TestMetadata("interface.kt") public void testInterface() throws Exception { runTest("compiler/testData/diagnostics/tests/j+k/properties/interface.kt"); @@ -12792,6 +12807,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { runTest("compiler/testData/diagnostics/tests/j+k/properties/isName.kt"); } + @TestMetadata("staticFieldPropertyOverloads.kt") + public void testStaticFieldPropertyOverloads() throws Exception { + runTest("compiler/testData/diagnostics/tests/j+k/properties/staticFieldPropertyOverloads.kt"); + } + @TestMetadata("val.kt") public void testVal() throws Exception { runTest("compiler/testData/diagnostics/tests/j+k/properties/val.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java index fc0b234847e..1c2a827db03 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java @@ -12777,6 +12777,21 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/j+k/properties"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); } + @TestMetadata("fieldPropertyOverloads.kt") + public void testFieldPropertyOverloads() throws Exception { + runTest("compiler/testData/diagnostics/tests/j+k/properties/fieldPropertyOverloads.kt"); + } + + @TestMetadata("fieldPropertyOverloadsDisabled.kt") + public void testFieldPropertyOverloadsDisabled() throws Exception { + runTest("compiler/testData/diagnostics/tests/j+k/properties/fieldPropertyOverloadsDisabled.kt"); + } + + @TestMetadata("fieldPropertyOverloadsNI.kt") + public void testFieldPropertyOverloadsNI() throws Exception { + runTest("compiler/testData/diagnostics/tests/j+k/properties/fieldPropertyOverloadsNI.kt"); + } + @TestMetadata("interface.kt") public void testInterface() throws Exception { runTest("compiler/testData/diagnostics/tests/j+k/properties/interface.kt"); @@ -12787,6 +12802,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing runTest("compiler/testData/diagnostics/tests/j+k/properties/isName.kt"); } + @TestMetadata("staticFieldPropertyOverloads.kt") + public void testStaticFieldPropertyOverloads() throws Exception { + runTest("compiler/testData/diagnostics/tests/j+k/properties/staticFieldPropertyOverloads.kt"); + } + @TestMetadata("val.kt") public void testVal() throws Exception { runTest("compiler/testData/diagnostics/tests/j+k/properties/val.kt"); diff --git a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt index d6c5fcbc0ab..ec94688dc28 100644 --- a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt +++ b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt @@ -120,6 +120,7 @@ enum class LanguageFeature( AllowAssigningArrayElementsToVarargsInNamedFormForFunctions(KOTLIN_1_4), AllowNullOperatorsForResult(KOTLIN_1_4), AllowResultInReturnType(KOTLIN_1_4), + PreferJavaFieldOverload(KOTLIN_1_4), ProperVisibilityForCompanionObjectInstanceField(sinceVersion = null, kind = BUG_FIX), // Temporarily disabled, see KT-27084/KT-22379