From ee20d979cbc5b1992f6a37e647cf7e419d34f930 Mon Sep 17 00:00:00 2001 From: Nikolay Lunyak Date: Wed, 21 Feb 2024 13:53:48 +0200 Subject: [PATCH] [FIR] Reproduce one more failure for KT-65972 #2 And refactor another related test to explain the desired behavior. ^KT-65972 --- ...CompilerTestFE10TestdataTestGenerated.java | 6 +++ ...sticCompilerFE10TestDataTestGenerated.java | 6 +++ ...eeOldFrontendDiagnosticsTestGenerated.java | 6 +++ ...siOldFrontendDiagnosticsTestGenerated.java | 6 +++ ...avaOverriddenByIntersectionInKotlin.fir.kt | 35 ++++++++++++++++ ...sInJavaOverriddenByIntersectionInKotlin.kt | 35 ++++++++++++++++ .../intersectionOverridesIntersection.kt | 41 +++++++++++++------ .../test/runners/DiagnosticTestGenerated.java | 6 +++ 8 files changed, 128 insertions(+), 13 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/intersectionWithMultipleDefaultsInJavaOverriddenByIntersectionInKotlin.fir.kt create mode 100644 compiler/testData/diagnostics/tests/intersectionWithMultipleDefaultsInJavaOverriddenByIntersectionInKotlin.kt diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java index 7a5a5731f9b..88d05b12e9a 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java @@ -633,6 +633,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia runTest("compiler/testData/diagnostics/tests/intersectionWithMultipleDefaultsInJava.kt"); } + @Test + @TestMetadata("intersectionWithMultipleDefaultsInJavaOverriddenByIntersectionInKotlin.kt") + public void testIntersectionWithMultipleDefaultsInJavaOverriddenByIntersectionInKotlin() { + runTest("compiler/testData/diagnostics/tests/intersectionWithMultipleDefaultsInJavaOverriddenByIntersectionInKotlin.kt"); + } + @Test @TestMetadata("invalidTargetCrashesCompiler.kt") public void testInvalidTargetCrashesCompiler() { diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java index 67443c6c626..1a28546e882 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java @@ -633,6 +633,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated runTest("compiler/testData/diagnostics/tests/intersectionWithMultipleDefaultsInJava.kt"); } + @Test + @TestMetadata("intersectionWithMultipleDefaultsInJavaOverriddenByIntersectionInKotlin.kt") + public void testIntersectionWithMultipleDefaultsInJavaOverriddenByIntersectionInKotlin() { + runTest("compiler/testData/diagnostics/tests/intersectionWithMultipleDefaultsInJavaOverriddenByIntersectionInKotlin.kt"); + } + @Test @TestMetadata("invalidTargetCrashesCompiler.kt") public void testInvalidTargetCrashesCompiler() { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java index a1474d19fbb..25af8463264 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java @@ -633,6 +633,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir runTest("compiler/testData/diagnostics/tests/intersectionWithMultipleDefaultsInJava.kt"); } + @Test + @TestMetadata("intersectionWithMultipleDefaultsInJavaOverriddenByIntersectionInKotlin.kt") + public void testIntersectionWithMultipleDefaultsInJavaOverriddenByIntersectionInKotlin() { + runTest("compiler/testData/diagnostics/tests/intersectionWithMultipleDefaultsInJavaOverriddenByIntersectionInKotlin.kt"); + } + @Test @TestMetadata("invalidTargetCrashesCompiler.kt") public void testInvalidTargetCrashesCompiler() { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java index 606325add90..b2105578b02 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java @@ -633,6 +633,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia runTest("compiler/testData/diagnostics/tests/intersectionWithMultipleDefaultsInJava.kt"); } + @Test + @TestMetadata("intersectionWithMultipleDefaultsInJavaOverriddenByIntersectionInKotlin.kt") + public void testIntersectionWithMultipleDefaultsInJavaOverriddenByIntersectionInKotlin() { + runTest("compiler/testData/diagnostics/tests/intersectionWithMultipleDefaultsInJavaOverriddenByIntersectionInKotlin.kt"); + } + @Test @TestMetadata("invalidTargetCrashesCompiler.kt") public void testInvalidTargetCrashesCompiler() { diff --git a/compiler/testData/diagnostics/tests/intersectionWithMultipleDefaultsInJavaOverriddenByIntersectionInKotlin.fir.kt b/compiler/testData/diagnostics/tests/intersectionWithMultipleDefaultsInJavaOverriddenByIntersectionInKotlin.fir.kt new file mode 100644 index 00000000000..875986943d1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/intersectionWithMultipleDefaultsInJavaOverriddenByIntersectionInKotlin.fir.kt @@ -0,0 +1,35 @@ +// FILE: ColoredTextContainer.java +public interface ColoredTextContainer { + default void setToolTipText(String text) {} +} + +// FILE: JComponent.java +public abstract class JComponent { + public void setToolTipText(String text) {} +} + +// FILE: SimpleColoredComponent.java +// IDEALLY: +// Provides `IO SimpleColoredComponent::setToolTipText`, because inherits +// `JComponent::setToolTipText` and `ColoredTextContainer::setToolTipText`, +// which don't sumbsume one another, but Java allows picking the class-based one in this case. +// REALITY: +// Contains an IO for the above. We check if this is green Java via a +// modified check that accounts for this case. +public class SimpleColoredComponent extends JComponent implements ColoredTextContainer {} + +// FILE: Main.kt + +// Not important, left for the record +interface TextFragment : ColoredTextContainer + +// IDEALLY: +// Provides `JComponent::setToolTipText`, because inherits +// `ColoredTextContainer::setToolTipText` and `IO SimpleColoredComponent::setToolTipText`, +// and the latter subsumes the former. +// REALITY: +// Contains IO between `ColoredTextContainer::setToolTipText` and `IO SimpleColoredComponent::setToolTipText`. +// In this case `IO SimpleColoredComponent::setToolTipText` should not be unwrapped, otherwise +// we miss `nonSubsumed()` check and since this is a Kotlin class we are not allowed to implicitly choose +// between `JComponent::setToolTipText` and `ColoredTextContainer::setToolTipText`. +private class TextFragmentImpl : TextFragment, SimpleColoredComponent() diff --git a/compiler/testData/diagnostics/tests/intersectionWithMultipleDefaultsInJavaOverriddenByIntersectionInKotlin.kt b/compiler/testData/diagnostics/tests/intersectionWithMultipleDefaultsInJavaOverriddenByIntersectionInKotlin.kt new file mode 100644 index 00000000000..9d0c457348b --- /dev/null +++ b/compiler/testData/diagnostics/tests/intersectionWithMultipleDefaultsInJavaOverriddenByIntersectionInKotlin.kt @@ -0,0 +1,35 @@ +// FILE: ColoredTextContainer.java +public interface ColoredTextContainer { + default void setToolTipText(String text) {} +} + +// FILE: JComponent.java +public abstract class JComponent { + public void setToolTipText(String text) {} +} + +// FILE: SimpleColoredComponent.java +// IDEALLY: +// Provides `IO SimpleColoredComponent::setToolTipText`, because inherits +// `JComponent::setToolTipText` and `ColoredTextContainer::setToolTipText`, +// which don't sumbsume one another, but Java allows picking the class-based one in this case. +// REALITY: +// Contains an IO for the above. We check if this is green Java via a +// modified check that accounts for this case. +public class SimpleColoredComponent extends JComponent implements ColoredTextContainer {} + +// FILE: Main.kt + +// Not important, left for the record +interface TextFragment : ColoredTextContainer + +// IDEALLY: +// Provides `JComponent::setToolTipText`, because inherits +// `ColoredTextContainer::setToolTipText` and `IO SimpleColoredComponent::setToolTipText`, +// and the latter subsumes the former. +// REALITY: +// Contains IO between `ColoredTextContainer::setToolTipText` and `IO SimpleColoredComponent::setToolTipText`. +// In this case `IO SimpleColoredComponent::setToolTipText` should not be unwrapped, otherwise +// we miss `nonSubsumed()` check and since this is a Kotlin class we are not allowed to implicitly choose +// between `JComponent::setToolTipText` and `ColoredTextContainer::setToolTipText`. +private class TextFragmentImpl : TextFragment, SimpleColoredComponent() diff --git a/compiler/testData/diagnostics/tests/override/intersectionOverridesIntersection.kt b/compiler/testData/diagnostics/tests/override/intersectionOverridesIntersection.kt index 80ef17f0644..752a999ff0c 100644 --- a/compiler/testData/diagnostics/tests/override/intersectionOverridesIntersection.kt +++ b/compiler/testData/diagnostics/tests/override/intersectionOverridesIntersection.kt @@ -1,21 +1,36 @@ // FIR_IDENTICAL -// inherits accept from FirDeclarationStatusImpl and FirResolvedDeclarationStatus -class FirResolvedDeclarationStatusImpl : FirDeclarationStatusImpl(), FirResolvedDeclarationStatus - -// inherits accept from FirElement and FirDeclarationStatus -open class FirDeclarationStatusImpl : FirPureAbstractElement(), FirDeclarationStatus - -abstract class FirPureAbstractElement : FirElement - -interface FirResolvedDeclarationStatus : FirDeclarationStatus { - override fun accept() {} +interface FirElement { + fun accept() {} } +// Provides `FirElement::accept`, because has no override for it +abstract class FirPureAbstractElement : FirElement + interface FirDeclarationStatus : FirElement { override fun accept() {} } -interface FirElement { - fun accept() {} -} \ No newline at end of file +interface FirResolvedDeclarationStatus : FirDeclarationStatus { + override fun accept() {} +} + +// IDEALLY: +// Provides `FirDeclarationStatus::accept`, because interits +// `FirElement::accept` and `FirDeclarationStatus::accept`, +// and the latter subsumes the former. +// REALLY: +// Contains an IO, which is an override. So, unlike `FirPureAbstractElement`, +// this class does have some override. We make sure this IO is green Kotlin +// by calculating `nonSubsumed()` for the base functions +open class FirDeclarationStatusImpl : FirPureAbstractElement(), FirDeclarationStatus + +// IDEALLY: +// Provides `FirResolvedDeclarationStatus::accept`, because +// inherits `FirDeclarationStatus::accept` and `FirResolvedDeclarationStatus::accept`, +// and the latter subsumes the former. +// REALLY: +// Inherits `IO FirDeclarationStatusImpl::accept` and `FirResolvedDeclarationStatus::accept`. +// Contains an IO for the above 2 functions. To check if this is green, we unwrap the IO in +// the base and then check `nonSubsumed()`, thus doing what is written in "IDEALLY". +class FirResolvedDeclarationStatusImpl : FirDeclarationStatusImpl(), FirResolvedDeclarationStatus diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index fd75617074f..26a68cfcff8 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -633,6 +633,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/intersectionWithMultipleDefaultsInJava.kt"); } + @Test + @TestMetadata("intersectionWithMultipleDefaultsInJavaOverriddenByIntersectionInKotlin.kt") + public void testIntersectionWithMultipleDefaultsInJavaOverriddenByIntersectionInKotlin() { + runTest("compiler/testData/diagnostics/tests/intersectionWithMultipleDefaultsInJavaOverriddenByIntersectionInKotlin.kt"); + } + @Test @TestMetadata("invalidTargetCrashesCompiler.kt") public void testInvalidTargetCrashesCompiler() {