From 065d0c66ab0099d7941dd3a665c3a62cd910fac6 Mon Sep 17 00:00:00 2001 From: Jinseong Jeon Date: Wed, 3 Feb 2021 15:02:57 -0800 Subject: [PATCH] FIR checker: reproduce a false alarm on type mismatch of overridden property --- ...irOldFrontendDiagnosticsTestGenerated.java | 6 +++ .../buildLazyValueForMap.fir.kt | 23 +++++++++++ .../testsWithStdLib/buildLazyValueForMap.kt | 21 ++++++++++ .../testsWithStdLib/buildLazyValueForMap.txt | 40 +++++++++++++++++++ .../test/runners/DiagnosticTestGenerated.java | 6 +++ 5 files changed, 96 insertions(+) create mode 100644 compiler/testData/diagnostics/testsWithStdLib/buildLazyValueForMap.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/buildLazyValueForMap.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/buildLazyValueForMap.txt diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java index 6b86afa4a42..79364c10df4 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java @@ -30644,6 +30644,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/testsWithStdLib/assignedInSynchronized.kt"); } + @Test + @TestMetadata("buildLazyValueForMap.kt") + public void testBuildLazyValueForMap() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/buildLazyValueForMap.kt"); + } + @Test @TestMetadata("CallCompanionProtectedNonStatic.kt") public void testCallCompanionProtectedNonStatic() throws Exception { diff --git a/compiler/testData/diagnostics/testsWithStdLib/buildLazyValueForMap.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/buildLazyValueForMap.fir.kt new file mode 100644 index 00000000000..d2698163573 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/buildLazyValueForMap.fir.kt @@ -0,0 +1,23 @@ +// !WITH_NEW_INFERENCE + +interface ClassId + +interface JavaAnnotation { + val classId: ClassId? +} + +interface JavaAnnotationOwner { + val annotations: Collection +} + +interface MapBasedJavaAnnotationOwner : JavaAnnotationOwner { + val annotationsByFqNameHash: Map +} + +fun JavaAnnotationOwner.buildLazyValueForMap() = lazy { + annotations.associateBy { it.classId?.hashCode() } +} + +abstract class BinaryJavaMethodBase(): MapBasedJavaAnnotationOwner { + override val annotationsByFqNameHash by buildLazyValueForMap() +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/buildLazyValueForMap.kt b/compiler/testData/diagnostics/testsWithStdLib/buildLazyValueForMap.kt new file mode 100644 index 00000000000..607e23aabb0 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/buildLazyValueForMap.kt @@ -0,0 +1,21 @@ +interface ClassId + +interface JavaAnnotation { + val classId: ClassId? +} + +interface JavaAnnotationOwner { + val annotations: Collection +} + +interface MapBasedJavaAnnotationOwner : JavaAnnotationOwner { + val annotationsByFqNameHash: Map +} + +fun JavaAnnotationOwner.buildLazyValueForMap() = lazy { + annotations.associateBy { it.classId?.hashCode() } +} + +abstract class BinaryJavaMethodBase(): MapBasedJavaAnnotationOwner { + override val annotationsByFqNameHash by buildLazyValueForMap() +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/buildLazyValueForMap.txt b/compiler/testData/diagnostics/testsWithStdLib/buildLazyValueForMap.txt new file mode 100644 index 00000000000..1ac5e5e1a86 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/buildLazyValueForMap.txt @@ -0,0 +1,40 @@ +package + +public fun JavaAnnotationOwner.buildLazyValueForMap(): kotlin.Lazy> + +public abstract class BinaryJavaMethodBase : MapBasedJavaAnnotationOwner { + public constructor BinaryJavaMethodBase() + public abstract override /*1*/ /*fake_override*/ val annotations: kotlin.collections.Collection + public open override /*1*/ val annotationsByFqNameHash: kotlin.collections.Map + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface ClassId { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface JavaAnnotation { + public abstract val classId: ClassId? + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface JavaAnnotationOwner { + public abstract val annotations: kotlin.collections.Collection + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface MapBasedJavaAnnotationOwner : JavaAnnotationOwner { + public abstract override /*1*/ /*fake_override*/ val annotations: kotlin.collections.Collection + public abstract val annotationsByFqNameHash: kotlin.collections.Map + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} 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 197f76038e4..c9b5822b670 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 @@ -30740,6 +30740,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/testsWithStdLib/assignedInSynchronized.kt"); } + @Test + @TestMetadata("buildLazyValueForMap.kt") + public void testBuildLazyValueForMap() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/buildLazyValueForMap.kt"); + } + @Test @TestMetadata("CallCompanionProtectedNonStatic.kt") public void testCallCompanionProtectedNonStatic() throws Exception {