From defb0cf611cec7deabfb46761d5c80b340189f63 Mon Sep 17 00:00:00 2001 From: Ivan Kochurkin Date: Fri, 14 Jan 2022 14:04:31 +0300 Subject: [PATCH] [FIR] Fix ambiguity between Sequence.forEach and Iterable.forEach (with @HidesMembers) ^KT-50776 Fixed --- ...CompilerTestFE10TestdataTestGenerated.java | 6 + .../testData/resolve/cfg/complex.dot | 324 +++++++++--------- .../testData/resolve/cfg/complex.fir.txt | 4 +- .../testData/resolve/cfg/complex.kt | 2 - ...irOldFrontendDiagnosticsTestGenerated.java | 6 + ...DiagnosticsWithLightTreeTestGenerated.java | 6 + .../calls/ConeOverloadConflictResolver.kt | 8 +- .../calls/tower/FirTowerResolveTask.kt | 22 +- .../fir/resolve/calls/tower/TowerLevels.kt | 9 +- ...ithHidesMemberAnnotationVsMemberWithout.kt | 12 + ...thHidesMemberAnnotationVsMemberWithout.txt | 37 ++ .../test/runners/DiagnosticTestGenerated.java | 6 + .../jetbrains/kotlin/name/StandardClassIds.kt | 2 + 13 files changed, 257 insertions(+), 187 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/resolve/priority/memberWithHidesMemberAnnotationVsMemberWithout.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/priority/memberWithHidesMemberAnnotationVsMemberWithout.txt diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java index d89740ec26e..267241e0de4 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java @@ -25721,6 +25721,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag runTest("compiler/testData/diagnostics/tests/resolve/priority/memberVsLocalExt.kt"); } + @Test + @TestMetadata("memberWithHidesMemberAnnotationVsMemberWithout.kt") + public void testMemberWithHidesMemberAnnotationVsMemberWithout() throws Exception { + runTest("compiler/testData/diagnostics/tests/resolve/priority/memberWithHidesMemberAnnotationVsMemberWithout.kt"); + } + @Test @TestMetadata("staticVsImplicitReceiverMember.kt") public void testStaticVsImplicitReceiverMember() throws Exception { diff --git a/compiler/fir/analysis-tests/testData/resolve/cfg/complex.dot b/compiler/fir/analysis-tests/testData/resolve/cfg/complex.dot index 324c5835f6b..3115c4d5717 100644 --- a/compiler/fir/analysis-tests/testData/resolve/cfg/complex.dot +++ b/compiler/fir/analysis-tests/testData/resolve/cfg/complex.dot @@ -19,102 +19,88 @@ digraph complex_kt { subgraph cluster_2 { color=red - 4 [label="Enter function addSuppressed" style="filled" fillcolor=red]; + 4 [label="Enter function closeFinally" style="filled" fillcolor=red]; subgraph cluster_3 { color=blue 5 [label="Enter block"]; - 6 [label="Exit block"]; - } - 7 [label="Exit function addSuppressed" style="filled" fillcolor=red]; - } - 4 -> {5}; - 5 -> {6}; - 6 -> {7}; - - subgraph cluster_4 { - color=red - 8 [label="Enter function closeFinally" style="filled" fillcolor=red]; - subgraph cluster_5 { - color=blue - 9 [label="Enter block"]; - subgraph cluster_6 { + subgraph cluster_4 { color=blue - 10 [label="Enter when"]; + 6 [label="Enter when"]; + subgraph cluster_5 { + color=blue + 7 [label="Enter when branch condition "]; + 8 [label="Access variable this@R|/closeFinally|"]; + 9 [label="Const: Null(null)"]; + 10 [label="Equality operator =="]; + 11 [label="Exit when branch condition"]; + } + subgraph cluster_6 { + color=blue + 12 [label="Enter when branch condition "]; + 13 [label="Access variable R|/cause|"]; + 14 [label="Const: Null(null)"]; + 15 [label="Equality operator =="]; + 16 [label="Exit when branch condition"]; + } subgraph cluster_7 { color=blue - 11 [label="Enter when branch condition "]; - 12 [label="Access variable this@R|/closeFinally|"]; - 13 [label="Const: Null(null)"]; - 14 [label="Equality operator =="]; - 15 [label="Exit when branch condition"]; + 17 [label="Enter when branch condition else"]; + 18 [label="Exit when branch condition"]; } + 19 [label="Enter when branch result"]; subgraph cluster_8 { color=blue - 16 [label="Enter when branch condition "]; - 17 [label="Access variable R|/cause|"]; - 18 [label="Const: Null(null)"]; - 19 [label="Equality operator =="]; - 20 [label="Exit when branch condition"]; - } - subgraph cluster_9 { - color=blue - 21 [label="Enter when branch condition else"]; - 22 [label="Exit when branch condition"]; - } - 23 [label="Enter when branch result"]; - subgraph cluster_10 { - color=blue - 24 [label="Enter block"]; - subgraph cluster_11 { + 20 [label="Enter block"]; + subgraph cluster_9 { color=blue - 25 [label="Try expression enter"]; + 21 [label="Try expression enter"]; + subgraph cluster_10 { + color=blue + 22 [label="Try main block enter"]; + subgraph cluster_11 { + color=blue + 23 [label="Enter block"]; + 24 [label="Function call: this@R|/closeFinally|.R|/AutoCloseable.close|()"]; + 25 [label="Exit block"]; + } + 26 [label="Try main block exit"]; + } subgraph cluster_12 { color=blue - 26 [label="Try main block enter"]; + 27 [label="Catch enter"]; subgraph cluster_13 { color=blue - 27 [label="Enter block"]; - 28 [label="Function call: this@R|/closeFinally|.R|/AutoCloseable.close|()"]; - 29 [label="Exit block"]; + 28 [label="Enter block"]; + 29 [label="Access variable R|/cause|"]; + 30 [label="Access variable R|/closeException|"]; + 31 [label="Function call: R|/cause|.R|kotlin/Throwable.addSuppressed|(...)"]; + 32 [label="Exit block"]; } - 30 [label="Try main block exit"]; + 33 [label="Catch exit"]; } - subgraph cluster_14 { - color=blue - 31 [label="Catch enter"]; - subgraph cluster_15 { - color=blue - 32 [label="Enter block"]; - 33 [label="Access variable R|/cause|"]; - 34 [label="Access variable R|/closeException|"]; - 35 [label="Function call: R|/cause|.R|/addSuppressed|(...)"]; - 36 [label="Exit block"]; - } - 37 [label="Catch exit"]; - } - 38 [label="Try expression exit"]; + 34 [label="Try expression exit"]; } - 39 [label="Exit block"]; + 35 [label="Exit block"]; } - 40 [label="Exit when branch result"]; - 41 [label="Enter when branch result"]; - subgraph cluster_16 { + 36 [label="Exit when branch result"]; + 37 [label="Enter when branch result"]; + subgraph cluster_14 { color=blue - 42 [label="Enter block"]; - 43 [label="Function call: this@R|/closeFinally|.R|/AutoCloseable.close|()"]; + 38 [label="Enter block"]; + 39 [label="Function call: this@R|/closeFinally|.R|/AutoCloseable.close|()"]; + 40 [label="Exit block"]; + } + 41 [label="Exit when branch result"]; + 42 [label="Enter when branch result"]; + subgraph cluster_15 { + color=blue + 43 [label="Enter block"]; 44 [label="Exit block"]; } 45 [label="Exit when branch result"]; - 46 [label="Enter when branch result"]; - subgraph cluster_17 { - color=blue - 47 [label="Enter block"]; - 48 [label="Exit block"]; - } - 49 [label="Exit when branch result"]; - 50 [label="Exit when"]; + 46 [label="Exit when"]; } - 51 [label="Jump: ^closeFinally when () { + 47 [label="Jump: ^closeFinally when () { ==(this@R|/closeFinally|, Null(null)) -> { } ==(R|/cause|, Null(null)) -> { @@ -125,174 +111,174 @@ digraph complex_kt { this@R|/closeFinally|.R|/AutoCloseable.close|() } catch (closeException: R|kotlin/Throwable|) { - R|/cause|.R|/addSuppressed|(R|/closeException|) + R|/cause|.R|kotlin/Throwable.addSuppressed|(R|/closeException|) } } } "]; - 52 [label="Stub" style="filled" fillcolor=gray]; - 53 [label="Exit block" style="filled" fillcolor=gray]; + 48 [label="Stub" style="filled" fillcolor=gray]; + 49 [label="Exit block" style="filled" fillcolor=gray]; } - 54 [label="Exit function closeFinally" style="filled" fillcolor=red]; + 50 [label="Exit function closeFinally" style="filled" fillcolor=red]; } + 4 -> {5}; + 5 -> {6}; + 6 -> {7}; + 7 -> {8}; 8 -> {9}; 9 -> {10}; 10 -> {11}; - 11 -> {12}; + 11 -> {42 12}; 12 -> {13}; 13 -> {14}; 14 -> {15}; - 15 -> {46 16}; - 16 -> {17}; + 15 -> {16}; + 16 -> {37 17}; 17 -> {18}; 18 -> {19}; 19 -> {20}; - 20 -> {41 21}; - 21 -> {22}; + 20 -> {21}; + 21 -> {22 27}; 22 -> {23}; 23 -> {24}; 24 -> {25}; - 25 -> {26 31}; - 26 -> {27}; + 25 -> {26}; + 26 -> {34 27}; 27 -> {28}; + 27 -> {50} [label=onUncaughtException]; 28 -> {29}; 29 -> {30}; - 30 -> {38 31}; + 30 -> {31}; 31 -> {32}; - 31 -> {54} [label=onUncaughtException]; 32 -> {33}; 33 -> {34}; 34 -> {35}; 35 -> {36}; - 36 -> {37}; + 36 -> {46}; 37 -> {38}; 38 -> {39}; 39 -> {40}; - 40 -> {50}; - 41 -> {42}; + 40 -> {41}; + 41 -> {46}; 42 -> {43}; 43 -> {44}; 44 -> {45}; - 45 -> {50}; + 45 -> {46}; 46 -> {47}; - 47 -> {48}; - 48 -> {49}; - 49 -> {50}; - 50 -> {51}; - 51 -> {54}; - 51 -> {52} [style=dotted]; - 52 -> {53} [style=dotted]; - 53 -> {54} [style=dotted]; + 47 -> {50}; + 47 -> {48} [style=dotted]; + 48 -> {49} [style=dotted]; + 49 -> {50} [style=dotted]; - subgraph cluster_18 { + subgraph cluster_16 { color=red - 55 [label="Enter function firstIsInstanceOrNull" style="filled" fillcolor=red]; - subgraph cluster_19 { + 51 [label="Enter function firstIsInstanceOrNull" style="filled" fillcolor=red]; + subgraph cluster_17 { color=blue - 56 [label="Enter block"]; - subgraph cluster_20 { + 52 [label="Enter block"]; + subgraph cluster_18 { color=blue - 57 [label="Enter block"]; - 58 [label="Access variable this@R|/firstIsInstanceOrNull|"]; - 59 [label="Function call: this@R|/firstIsInstanceOrNull|.R|SubstitutionOverride|>|()"]; - 60 [label="Variable declaration: lval : R|kotlin/collections/Iterator|"]; - subgraph cluster_21 { + 53 [label="Enter block"]; + 54 [label="Access variable this@R|/firstIsInstanceOrNull|"]; + 55 [label="Function call: this@R|/firstIsInstanceOrNull|.R|SubstitutionOverride|>|()"]; + 56 [label="Variable declaration: lval : R|kotlin/collections/Iterator|"]; + subgraph cluster_19 { color=blue - 61 [label="Enter while loop"]; - subgraph cluster_22 { + 57 [label="Enter while loop"]; + subgraph cluster_20 { color=blue - 62 [label="Enter loop condition"]; - 63 [label="Access variable R|/|"]; - 64 [label="Function call: R|/|.R|SubstitutionOverride|()"]; - 65 [label="Exit loop condition"]; + 58 [label="Enter loop condition"]; + 59 [label="Access variable R|/|"]; + 60 [label="Function call: R|/|.R|SubstitutionOverride|()"]; + 61 [label="Exit loop condition"]; } - subgraph cluster_23 { + subgraph cluster_21 { color=blue - 66 [label="Enter loop block"]; - subgraph cluster_24 { + 62 [label="Enter loop block"]; + subgraph cluster_22 { color=blue - 67 [label="Enter block"]; - 68 [label="Access variable R|/|"]; - 69 [label="Function call: R|/|.R|SubstitutionOverride|()"]; - 70 [label="Variable declaration: lval element: R|kotlin/Any?|"]; - subgraph cluster_25 { + 63 [label="Enter block"]; + 64 [label="Access variable R|/|"]; + 65 [label="Function call: R|/|.R|SubstitutionOverride|()"]; + 66 [label="Variable declaration: lval element: R|kotlin/Any?|"]; + subgraph cluster_23 { color=blue - 71 [label="Enter when"]; - subgraph cluster_26 { + 67 [label="Enter when"]; + subgraph cluster_24 { color=blue - 72 [label="Enter when branch condition "]; - 73 [label="Access variable R|/element|"]; - 74 [label="Type operator: (R|/element| is R|T|)"]; - 75 [label="Exit when branch condition"]; + 68 [label="Enter when branch condition "]; + 69 [label="Access variable R|/element|"]; + 70 [label="Type operator: (R|/element| is R|T|)"]; + 71 [label="Exit when branch condition"]; } - 76 [label="Synthetic else branch"]; - 77 [label="Enter when branch result"]; - subgraph cluster_27 { + 72 [label="Synthetic else branch"]; + 73 [label="Enter when branch result"]; + subgraph cluster_25 { color=blue - 78 [label="Enter block"]; - 79 [label="Access variable R|/element|"]; - 80 [label="Jump: ^firstIsInstanceOrNull R|/element|"]; - 81 [label="Stub" style="filled" fillcolor=gray]; - 82 [label="Exit block" style="filled" fillcolor=gray]; + 74 [label="Enter block"]; + 75 [label="Access variable R|/element|"]; + 76 [label="Jump: ^firstIsInstanceOrNull R|/element|"]; + 77 [label="Stub" style="filled" fillcolor=gray]; + 78 [label="Exit block" style="filled" fillcolor=gray]; } - 83 [label="Exit when branch result" style="filled" fillcolor=gray]; - 84 [label="Exit when"]; + 79 [label="Exit when branch result" style="filled" fillcolor=gray]; + 80 [label="Exit when"]; } - 85 [label="Exit block"]; + 81 [label="Exit block"]; } - 86 [label="Exit loop block"]; + 82 [label="Exit loop block"]; } - 87 [label="Exit whileloop"]; + 83 [label="Exit whileloop"]; } - 88 [label="Exit block"]; + 84 [label="Exit block"]; } - 89 [label="Const: Null(null)"]; - 90 [label="Jump: ^firstIsInstanceOrNull Null(null)"]; - 91 [label="Stub" style="filled" fillcolor=gray]; - 92 [label="Exit block" style="filled" fillcolor=gray]; + 85 [label="Const: Null(null)"]; + 86 [label="Jump: ^firstIsInstanceOrNull Null(null)"]; + 87 [label="Stub" style="filled" fillcolor=gray]; + 88 [label="Exit block" style="filled" fillcolor=gray]; } - 93 [label="Exit function firstIsInstanceOrNull" style="filled" fillcolor=red]; + 89 [label="Exit function firstIsInstanceOrNull" style="filled" fillcolor=red]; } + 51 -> {52}; + 52 -> {53}; + 53 -> {54}; + 54 -> {55}; 55 -> {56}; 56 -> {57}; 57 -> {58}; 58 -> {59}; 59 -> {60}; 60 -> {61}; - 61 -> {62}; + 61 -> {83 62}; 62 -> {63}; 63 -> {64}; 64 -> {65}; - 65 -> {87 66}; + 65 -> {66}; 66 -> {67}; 67 -> {68}; 68 -> {69}; 69 -> {70}; 70 -> {71}; - 71 -> {72}; - 72 -> {73}; + 71 -> {73 72}; + 72 -> {80}; 73 -> {74}; 74 -> {75}; - 75 -> {77 76}; - 76 -> {84}; - 77 -> {78}; - 78 -> {79}; - 79 -> {80}; - 80 -> {93}; - 80 -> {81} [style=dotted]; - 81 -> {82} [style=dotted]; - 82 -> {83} [style=dotted]; - 83 -> {84} [style=dotted]; + 75 -> {76}; + 76 -> {89}; + 76 -> {77} [style=dotted]; + 77 -> {78} [style=dotted]; + 78 -> {79} [style=dotted]; + 79 -> {80} [style=dotted]; + 80 -> {81}; + 81 -> {82}; + 82 -> {58} [color=green style=dashed]; + 83 -> {84}; 84 -> {85}; 85 -> {86}; - 86 -> {62} [color=green style=dashed]; - 87 -> {88}; - 88 -> {89}; - 89 -> {90}; - 90 -> {93}; - 90 -> {91} [style=dotted]; - 91 -> {92} [style=dotted]; - 92 -> {93} [style=dotted]; + 86 -> {89}; + 86 -> {87} [style=dotted]; + 87 -> {88} [style=dotted]; + 88 -> {89} [style=dotted]; } diff --git a/compiler/fir/analysis-tests/testData/resolve/cfg/complex.fir.txt b/compiler/fir/analysis-tests/testData/resolve/cfg/complex.fir.txt index 66278d30dbf..b16f73c7bbf 100644 --- a/compiler/fir/analysis-tests/testData/resolve/cfg/complex.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolve/cfg/complex.fir.txt @@ -2,8 +2,6 @@ FILE: complex.kt public abstract interface AutoCloseable : R|kotlin/Any| { public abstract fun close(): R|kotlin/Unit| - } - public final fun R|kotlin/Throwable|.addSuppressed(other: R|kotlin/Throwable|): R|kotlin/Unit| { } internal final fun R|AutoCloseable?|.closeFinally(cause: R|kotlin/Throwable?|): R|kotlin/Unit| { ^closeFinally when () { @@ -17,7 +15,7 @@ FILE: complex.kt this@R|/closeFinally|.R|/AutoCloseable.close|() } catch (closeException: R|kotlin/Throwable|) { - R|/cause|.R|/addSuppressed|(R|/closeException|) + R|/cause|.R|kotlin/Throwable.addSuppressed|(R|/closeException|) } } diff --git a/compiler/fir/analysis-tests/testData/resolve/cfg/complex.kt b/compiler/fir/analysis-tests/testData/resolve/cfg/complex.kt index ec9eac70bc4..064c92a92d7 100644 --- a/compiler/fir/analysis-tests/testData/resolve/cfg/complex.kt +++ b/compiler/fir/analysis-tests/testData/resolve/cfg/complex.kt @@ -3,8 +3,6 @@ interface AutoCloseable { fun close() } -fun Throwable.addSuppressed(other: Throwable) {} - internal fun AutoCloseable?.closeFinally(cause: Throwable?) = when { this == null -> {} cause == null -> close() 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 68d83febb1e..5cd58644395 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 @@ -25721,6 +25721,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/resolve/priority/memberVsLocalExt.kt"); } + @Test + @TestMetadata("memberWithHidesMemberAnnotationVsMemberWithout.kt") + public void testMemberWithHidesMemberAnnotationVsMemberWithout() throws Exception { + runTest("compiler/testData/diagnostics/tests/resolve/priority/memberWithHidesMemberAnnotationVsMemberWithout.kt"); + } + @Test @TestMetadata("staticVsImplicitReceiverMember.kt") public void testStaticVsImplicitReceiverMember() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java index ac63169aa3f..373c14d4664 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java @@ -25721,6 +25721,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac runTest("compiler/testData/diagnostics/tests/resolve/priority/memberVsLocalExt.kt"); } + @Test + @TestMetadata("memberWithHidesMemberAnnotationVsMemberWithout.kt") + public void testMemberWithHidesMemberAnnotationVsMemberWithout() throws Exception { + runTest("compiler/testData/diagnostics/tests/resolve/priority/memberWithHidesMemberAnnotationVsMemberWithout.kt"); + } + @Test @TestMetadata("staticVsImplicitReceiverMember.kt") public void testStaticVsImplicitReceiverMember() throws Exception { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ConeOverloadConflictResolver.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ConeOverloadConflictResolver.kt index 02e278ff2de..7c5de45eac2 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ConeOverloadConflictResolver.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ConeOverloadConflictResolver.kt @@ -8,6 +8,7 @@ package org.jetbrains.kotlin.fir.resolve.calls import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.declarations.FirMemberDeclaration +import org.jetbrains.kotlin.fir.declarations.getAnnotationByClassId import org.jetbrains.kotlin.fir.declarations.utils.modality import org.jetbrains.kotlin.fir.render import org.jetbrains.kotlin.fir.resolve.inference.ConeTypeParameterBasedTypeVariable @@ -15,6 +16,7 @@ import org.jetbrains.kotlin.fir.resolve.inference.InferenceComponents import org.jetbrains.kotlin.fir.resolve.substitution.substitutorByMap import org.jetbrains.kotlin.fir.symbols.ConeTypeParameterLookupTag import org.jetbrains.kotlin.fir.types.coneType +import org.jetbrains.kotlin.name.StandardClassIds.Annotations.HidesMembers import org.jetbrains.kotlin.resolve.calls.inference.model.NewConstraintSystemImpl import org.jetbrains.kotlin.resolve.calls.inference.model.SimpleConstraintSystemConstraintPosition import org.jetbrains.kotlin.resolve.calls.results.FlatSignature @@ -43,7 +45,11 @@ class ConeOverloadConflictResolver( candidates return chooseMaximallySpecificCandidates( - fixedCandidates, discriminateGenerics, discriminateAbstracts, discriminateSAMs = true, discriminateSuspendConversions = true + fixedCandidates, + discriminateGenerics, + discriminateAbstracts, + discriminateSAMs = true, + discriminateSuspendConversions = true ) } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/FirTowerResolveTask.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/FirTowerResolveTask.kt index 64fef96ba8c..48acb9d2928 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/FirTowerResolveTask.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/FirTowerResolveTask.kt @@ -78,11 +78,11 @@ internal abstract class FirBaseTowerResolveTask( protected fun FirScope.toScopeTowerLevel( extensionReceiver: ReceiverValue? = null, - extensionsOnly: Boolean = false, + withHideMembersOnly: Boolean = false, includeInnerConstructors: Boolean = extensionReceiver != null, ): ScopeTowerLevel = ScopeTowerLevel( session, components, this, - extensionReceiver, extensionsOnly, includeInnerConstructors + extensionReceiver, withHideMembersOnly, includeInnerConstructors ) protected fun ReceiverValue.toMemberScopeTowerLevel( @@ -386,12 +386,14 @@ internal open class FirTowerResolveTask( depth: Int?, explicitReceiverKind: ExplicitReceiverKind, parentGroup: TowerGroup - ) = processLevel( - topLevelScope.toScopeTowerLevel( - extensionReceiver = receiverValue, extensionsOnly = true - ), - info, - parentGroup.TopPrioritized(index).let { if (depth != null) it.Implicit(depth) else it }, - explicitReceiverKind, - ) + ) { + processLevel( + topLevelScope.toScopeTowerLevel( + extensionReceiver = receiverValue, withHideMembersOnly = true + ), + info, + parentGroup.TopPrioritized(index).let { if (depth != null) it.Implicit(depth) else it }, + explicitReceiverKind, + ) + } } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/TowerLevels.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/TowerLevels.kt index 0bb262aa38a..a9ad829b5fe 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/TowerLevels.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/TowerLevels.kt @@ -7,6 +7,7 @@ package org.jetbrains.kotlin.fir.resolve.calls.tower import org.jetbrains.kotlin.fir.* import org.jetbrains.kotlin.fir.declarations.FirConstructor +import org.jetbrains.kotlin.fir.declarations.getAnnotationByClassId import org.jetbrains.kotlin.fir.declarations.utils.isInner import org.jetbrains.kotlin.fir.expressions.builder.buildResolvedQualifier import org.jetbrains.kotlin.fir.resolve.BodyResolveComponents @@ -23,6 +24,7 @@ import org.jetbrains.kotlin.fir.scopes.processClassifiersByName import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol import org.jetbrains.kotlin.fir.symbols.impl.* import org.jetbrains.kotlin.fir.types.* +import org.jetbrains.kotlin.name.StandardClassIds.Annotations.HidesMembers import org.jetbrains.kotlin.types.AbstractTypeChecker import org.jetbrains.kotlin.util.OperatorNameConventions import org.jetbrains.kotlin.utils.SmartList @@ -220,7 +222,7 @@ class ScopeTowerLevel( private val bodyResolveComponents: BodyResolveComponents, val scope: FirScope, val extensionReceiver: ReceiverValue?, - private val extensionsOnly: Boolean, + private val withHideMembersOnly: Boolean, private val includeInnerConstructors: Boolean ) : SessionBasedTowerLevel(session) { @@ -286,7 +288,10 @@ class ScopeTowerLevel( processor: TowerScopeLevelProcessor ) { val candidateReceiverTypeRef = candidate.fir.receiverTypeRef - val receiverExpected = extensionsOnly || extensionReceiver != null + if (withHideMembersOnly && candidate.getAnnotationByClassId(HidesMembers) == null) { + return + } + val receiverExpected = withHideMembersOnly || extensionReceiver != null if (candidateReceiverTypeRef == null == receiverExpected) return val dispatchReceiverValue = dispatchReceiverValue(candidate) if (dispatchReceiverValue == null && shouldSkipCandidateWithInconsistentExtensionReceiver(candidate)) { diff --git a/compiler/testData/diagnostics/tests/resolve/priority/memberWithHidesMemberAnnotationVsMemberWithout.kt b/compiler/testData/diagnostics/tests/resolve/priority/memberWithHidesMemberAnnotationVsMemberWithout.kt new file mode 100644 index 00000000000..6b9c84bc8ce --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/priority/memberWithHidesMemberAnnotationVsMemberWithout.kt @@ -0,0 +1,12 @@ +// FIR_IDENTICAL +// WITH_STDLIB +// ISSUE: KT-50776 +interface Entities : MutableCollection, Sequence + +abstract class StringEntities : Entities { + fun foo() { + forEach { + println(it) + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/priority/memberWithHidesMemberAnnotationVsMemberWithout.txt b/compiler/testData/diagnostics/tests/resolve/priority/memberWithHidesMemberAnnotationVsMemberWithout.txt new file mode 100644 index 00000000000..e2d31e1116f --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/priority/memberWithHidesMemberAnnotationVsMemberWithout.txt @@ -0,0 +1,37 @@ +package + +public interface Entities : kotlin.collections.MutableCollection, kotlin.sequences.Sequence { + public abstract override /*1*/ /*fake_override*/ val size: kotlin.Int + public abstract override /*1*/ /*fake_override*/ fun add(/*0*/ element: Target): kotlin.Boolean + public abstract override /*1*/ /*fake_override*/ fun addAll(/*0*/ elements: kotlin.collections.Collection): kotlin.Boolean + public abstract override /*1*/ /*fake_override*/ fun clear(): kotlin.Unit + public abstract override /*1*/ /*fake_override*/ fun contains(/*0*/ element: Target): kotlin.Boolean + public abstract override /*1*/ /*fake_override*/ fun containsAll(/*0*/ elements: kotlin.collections.Collection): kotlin.Boolean + public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int + public abstract override /*1*/ /*fake_override*/ fun isEmpty(): kotlin.Boolean + public abstract override /*2*/ /*fake_override*/ fun iterator(): kotlin.collections.MutableIterator + public abstract override /*1*/ /*fake_override*/ fun remove(/*0*/ element: Target): kotlin.Boolean + public abstract override /*1*/ /*fake_override*/ fun removeAll(/*0*/ elements: kotlin.collections.Collection): kotlin.Boolean + public abstract override /*1*/ /*fake_override*/ fun retainAll(/*0*/ elements: kotlin.collections.Collection): kotlin.Boolean + public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String +} + +public abstract class StringEntities : Entities { + public constructor StringEntities() + public abstract override /*1*/ /*fake_override*/ val size: kotlin.Int + public abstract override /*1*/ /*fake_override*/ fun add(/*0*/ element: kotlin.String): kotlin.Boolean + public abstract override /*1*/ /*fake_override*/ fun addAll(/*0*/ elements: kotlin.collections.Collection): kotlin.Boolean + public abstract override /*1*/ /*fake_override*/ fun clear(): kotlin.Unit + public abstract override /*1*/ /*fake_override*/ fun contains(/*0*/ element: kotlin.String): kotlin.Boolean + public abstract override /*1*/ /*fake_override*/ fun containsAll(/*0*/ elements: kotlin.collections.Collection): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final fun foo(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public abstract override /*1*/ /*fake_override*/ fun isEmpty(): kotlin.Boolean + public abstract override /*1*/ /*fake_override*/ fun iterator(): kotlin.collections.MutableIterator + public abstract override /*1*/ /*fake_override*/ fun remove(/*0*/ element: kotlin.String): kotlin.Boolean + public abstract override /*1*/ /*fake_override*/ fun removeAll(/*0*/ elements: kotlin.collections.Collection): kotlin.Boolean + public abstract override /*1*/ /*fake_override*/ fun retainAll(/*0*/ elements: kotlin.collections.Collection): kotlin.Boolean + 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 17620929ee0..ebc0987b6ac 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 @@ -25733,6 +25733,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/resolve/priority/memberVsLocalExt.kt"); } + @Test + @TestMetadata("memberWithHidesMemberAnnotationVsMemberWithout.kt") + public void testMemberWithHidesMemberAnnotationVsMemberWithout() throws Exception { + runTest("compiler/testData/diagnostics/tests/resolve/priority/memberWithHidesMemberAnnotationVsMemberWithout.kt"); + } + @Test @TestMetadata("staticVsImplicitReceiverMember.kt") public void testStaticVsImplicitReceiverMember() throws Exception { diff --git a/core/compiler.common/src/org/jetbrains/kotlin/name/StandardClassIds.kt b/core/compiler.common/src/org/jetbrains/kotlin/name/StandardClassIds.kt index 6528635d5bc..ebbd78c0806 100644 --- a/core/compiler.common/src/org/jetbrains/kotlin/name/StandardClassIds.kt +++ b/core/compiler.common/src/org/jetbrains/kotlin/name/StandardClassIds.kt @@ -142,6 +142,8 @@ object StandardClassIds { val Deprecated = "Deprecated".baseId() val DeprecatedSinceKotlin = "DeprecatedSinceKotlin".baseId() + val HidesMembers = "HidesMembers".internalId() + val Retention = "Retention".annotationId() val Target = "Target".annotationId() val Repeatable = "Repeatable".annotationId()