From 3d06a92eea6adfedf50dc346b4b08f3c135187aa Mon Sep 17 00:00:00 2001 From: "Denis.Zharkov" Date: Wed, 6 Apr 2022 09:59:47 +0300 Subject: [PATCH] K1: Adjust positioning for NO_CONTEXT_RECEIVER --- .../DiagnosticReporterByTrackingStrategy.kt | 4 +-- .../fromKEEP/iterableClass.kt | 4 +-- .../fromKEEP/monoidSum.fir.kt | 34 ------------------- .../contextReceivers/fromKEEP/monoidSum.kt | 5 +-- .../tests/extensions/contextReceivers/lazy.kt | 14 ++++---- .../contextReceivers/typeParameterized.kt | 4 +-- .../typeParameterizedList.fir.kt | 18 ---------- .../contextReceivers/typeParameterizedList.kt | 5 +-- .../withExplicitReceiver.fir.kt | 20 ----------- .../contextReceivers/withExplicitReceiver.kt | 5 +-- .../withExplicitReceiverError.fir.kt | 20 ----------- .../withExplicitReceiverError.kt | 7 ++-- 12 files changed, 26 insertions(+), 114 deletions(-) delete mode 100644 compiler/testData/diagnostics/tests/extensions/contextReceivers/fromKEEP/monoidSum.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/extensions/contextReceivers/typeParameterizedList.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/extensions/contextReceivers/withExplicitReceiver.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/extensions/contextReceivers/withExplicitReceiverError.fir.kt diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt index f7c253f2eff..1b8edb91ac5 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt @@ -35,10 +35,10 @@ import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluat import org.jetbrains.kotlin.resolve.descriptorUtil.module import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedCallableMemberDescriptor -import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.TypeUtils import org.jetbrains.kotlin.types.checker.intersectWrappedTypes +import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.types.expressions.ControlStructureTypingUtils import org.jetbrains.kotlin.types.model.TypeSystemInferenceExtensionContextDelegate import org.jetbrains.kotlin.types.model.TypeVariableMarker @@ -119,7 +119,7 @@ class DiagnosticReporterByTrackingStrategy( val callElement = psiKotlinCall.psiCall.callElement trace.report( NO_CONTEXT_RECEIVER.on( - callElement, + callElement.getCalleeExpressionIfAny() ?: callElement, (diagnostic as NoContextReceiver).receiverDescriptor.value.toString() ) ) diff --git a/compiler/testData/diagnostics/tests/extensions/contextReceivers/fromKEEP/iterableClass.kt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/fromKEEP/iterableClass.kt index ce54e66f7eb..d7358069912 100644 --- a/compiler/testData/diagnostics/tests/extensions/contextReceivers/fromKEEP/iterableClass.kt +++ b/compiler/testData/diagnostics/tests/extensions/contextReceivers/fromKEEP/iterableClass.kt @@ -14,5 +14,5 @@ fun test() { with(f) { listOf(1, 2, 3).iterator(null) } - listOf(1, 2, 3).iterator(null) -} \ No newline at end of file + listOf(1, 2, 3).iterator(null) +} diff --git a/compiler/testData/diagnostics/tests/extensions/contextReceivers/fromKEEP/monoidSum.fir.kt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/fromKEEP/monoidSum.fir.kt deleted file mode 100644 index 18ae34d9070..00000000000 --- a/compiler/testData/diagnostics/tests/extensions/contextReceivers/fromKEEP/monoidSum.fir.kt +++ /dev/null @@ -1,34 +0,0 @@ -// !LANGUAGE: +ContextReceivers - -interface Semigroup { - infix fun T.combine(other: T): T -} - -interface Monoid : Semigroup { - val unit: T -} -object IntMonoid : Monoid { - override fun Int.combine(other: Int): Int = this + other - override val unit: Int = 0 -} -object StringMonoid : Monoid { - override fun String.combine(other: String): String = this + other - override val unit: String = "" -} - -public inline fun Iterable.fold(initial: R, operation: (acc: R, T) -> R): R = TODO() - -context(Monoid) -fun List.sum(): T = fold(unit) { acc, e -> acc.combine(e) } - -fun listOf(vararg items: T): List = null!! - -fun test() { - with(IntMonoid) { - listOf(1, 2, 3).sum() - } - with(StringMonoid) { - listOf(1, 2, 3).sum() - listOf("1", "2", "3").sum() - } -} diff --git a/compiler/testData/diagnostics/tests/extensions/contextReceivers/fromKEEP/monoidSum.kt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/fromKEEP/monoidSum.kt index 936b1ba1213..f4fb3238ff8 100644 --- a/compiler/testData/diagnostics/tests/extensions/contextReceivers/fromKEEP/monoidSum.kt +++ b/compiler/testData/diagnostics/tests/extensions/contextReceivers/fromKEEP/monoidSum.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !LANGUAGE: +ContextReceivers interface Semigroup { @@ -28,7 +29,7 @@ fun test() { listOf(1, 2, 3).sum() } with(StringMonoid) { - listOf(1, 2, 3).sum() + listOf(1, 2, 3).sum() listOf("1", "2", "3").sum() } -} \ No newline at end of file +} diff --git a/compiler/testData/diagnostics/tests/extensions/contextReceivers/lazy.kt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/lazy.kt index a37f52e5fcd..181157cc066 100644 --- a/compiler/testData/diagnostics/tests/extensions/contextReceivers/lazy.kt +++ b/compiler/testData/diagnostics/tests/extensions/contextReceivers/lazy.kt @@ -16,35 +16,35 @@ fun f(lazy1: Lazy, lazy2: Lazy, lazyT: Lazy, lazyLazyT with(lazy2) { test1() test2() - test3() + test3() } } with(lazy2) { with(lazy1) { test1() test2() - test3() + test3() } } with(lazyT) { with(lazy1) { - test1() + test1() test2() - test3() + test3() } } with(lazyLazyT) { with(lazy1) { - test1() + test1() test2() test3() } } with(lazy1) { with(lazyLazyT) { - test1() + test1() test2() test3() } } -} \ No newline at end of file +} diff --git a/compiler/testData/diagnostics/tests/extensions/contextReceivers/typeParameterized.kt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/typeParameterized.kt index 7db8d64e649..c212320626c 100644 --- a/compiler/testData/diagnostics/tests/extensions/contextReceivers/typeParameterized.kt +++ b/compiler/testData/diagnostics/tests/extensions/contextReceivers/typeParameterized.kt @@ -8,5 +8,5 @@ context(T) fun T.f(t: B) {} fun Int.main(a: A, b: B) { - a.f(b) -} \ No newline at end of file + a.f(b) +} diff --git a/compiler/testData/diagnostics/tests/extensions/contextReceivers/typeParameterizedList.fir.kt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/typeParameterizedList.fir.kt deleted file mode 100644 index fd4ef3c5689..00000000000 --- a/compiler/testData/diagnostics/tests/extensions/contextReceivers/typeParameterizedList.fir.kt +++ /dev/null @@ -1,18 +0,0 @@ -// !LANGUAGE: +ContextReceivers -// !DIAGNOSTICS: -UNUSED_PARAMETER - -fun listOf(vararg e: T): List = null!! - -class A - -context(List) -fun A.f() {} - -fun main() { - with(listOf(1, 2, 3)) { - A().f() - } - with(listOf("1", "2", "3")) { - A().f() - } -} diff --git a/compiler/testData/diagnostics/tests/extensions/contextReceivers/typeParameterizedList.kt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/typeParameterizedList.kt index 5c73ea97613..9ae74868522 100644 --- a/compiler/testData/diagnostics/tests/extensions/contextReceivers/typeParameterizedList.kt +++ b/compiler/testData/diagnostics/tests/extensions/contextReceivers/typeParameterizedList.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !LANGUAGE: +ContextReceivers // !DIAGNOSTICS: -UNUSED_PARAMETER @@ -13,6 +14,6 @@ fun main() { A().f() } with(listOf("1", "2", "3")) { - A().f() + A().f() } -} \ No newline at end of file +} diff --git a/compiler/testData/diagnostics/tests/extensions/contextReceivers/withExplicitReceiver.fir.kt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/withExplicitReceiver.fir.kt deleted file mode 100644 index 39e27c18cb6..00000000000 --- a/compiler/testData/diagnostics/tests/extensions/contextReceivers/withExplicitReceiver.fir.kt +++ /dev/null @@ -1,20 +0,0 @@ -// !LANGUAGE: +ContextReceivers - -open class A -class B -class C: A() - -context(A) -fun B.f() {} - -fun main() { - val b = B() - - b.f() - with(A()) { - b.f() - } - with(C()) { - b.f() - } -} diff --git a/compiler/testData/diagnostics/tests/extensions/contextReceivers/withExplicitReceiver.kt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/withExplicitReceiver.kt index 906d8be73c5..74d329641ff 100644 --- a/compiler/testData/diagnostics/tests/extensions/contextReceivers/withExplicitReceiver.kt +++ b/compiler/testData/diagnostics/tests/extensions/contextReceivers/withExplicitReceiver.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !LANGUAGE: +ContextReceivers open class A @@ -10,11 +11,11 @@ fun B.f() {} fun main() { val b = B() - b.f() + b.f() with(A()) { b.f() } with(C()) { b.f() } -} \ No newline at end of file +} diff --git a/compiler/testData/diagnostics/tests/extensions/contextReceivers/withExplicitReceiverError.fir.kt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/withExplicitReceiverError.fir.kt deleted file mode 100644 index d28da3252be..00000000000 --- a/compiler/testData/diagnostics/tests/extensions/contextReceivers/withExplicitReceiverError.fir.kt +++ /dev/null @@ -1,20 +0,0 @@ -// !LANGUAGE: +ContextReceivers - -class A -class B -class C - -context(A) -fun B.f() {} - -fun main() { - val b = B() - - b.f() - with(A()) { - b.f() - } - with(C()) { - b.f() - } -} diff --git a/compiler/testData/diagnostics/tests/extensions/contextReceivers/withExplicitReceiverError.kt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/withExplicitReceiverError.kt index 42884bff50e..96274a84002 100644 --- a/compiler/testData/diagnostics/tests/extensions/contextReceivers/withExplicitReceiverError.kt +++ b/compiler/testData/diagnostics/tests/extensions/contextReceivers/withExplicitReceiverError.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !LANGUAGE: +ContextReceivers class A @@ -10,11 +11,11 @@ fun B.f() {} fun main() { val b = B() - b.f() + b.f() with(A()) { b.f() } with(C()) { - b.f() + b.f() } -} \ No newline at end of file +}