[NI] Use original implicit receiver for DSL violation check

There is an inconsistency between old and new inference for storing
 receivers of resolved calls. In new inference, for captured types,
 receiver will be changed and to preserve behavior of the old inference,
 we use original one during important checks.
 This is more a workaround than a solution and should be revisited.

 #KT-31356 Fixed
 #KT-29948 Fixed
 #KT-31360 Fixed
This commit is contained in:
Mikhail Zarechenskiy
2019-05-08 01:21:44 +03:00
parent c283e15425
commit 6c9394f0b2
10 changed files with 165 additions and 1 deletions
@@ -17470,6 +17470,21 @@ public class FirDiagnosticsSmokeTestGenerated extends AbstractFirDiagnosticsSmok
runTest("compiler/testData/diagnostics/tests/resolve/dslMarker/insideTopLevelExtensionAnnotatedType.kt");
}
@TestMetadata("kt29948.kt")
public void testKt29948() throws Exception {
runTest("compiler/testData/diagnostics/tests/resolve/dslMarker/kt29948.kt");
}
@TestMetadata("kt31360.kt")
public void testKt31360() throws Exception {
runTest("compiler/testData/diagnostics/tests/resolve/dslMarker/kt31360.kt");
}
@TestMetadata("markedReceiverWithCapturedTypeArgument.kt")
public void testMarkedReceiverWithCapturedTypeArgument() throws Exception {
runTest("compiler/testData/diagnostics/tests/resolve/dslMarker/markedReceiverWithCapturedTypeArgument.kt");
}
@TestMetadata("markersIntersection.kt")
public void testMarkersIntersection() throws Exception {
runTest("compiler/testData/diagnostics/tests/resolve/dslMarker/markersIntersection.kt");
@@ -31,7 +31,12 @@ object DslScopeViolationCallChecker : CallChecker {
if (!context.languageVersionSettings.supportsFeature(LanguageFeature.DslMarkersSupport)) return
val callImplicitReceivers = resolvedCall.getImplicitReceivers()
for (callImplicitReceiver in callImplicitReceivers) {
val originalReceivers = if (context.languageVersionSettings.supportsFeature(LanguageFeature.NewInference))
callImplicitReceivers.map { it.original }
else
callImplicitReceivers
for (callImplicitReceiver in originalReceivers) {
checkCallImplicitReceiver(callImplicitReceiver, resolvedCall, reportOn, context)
}
}
@@ -0,0 +1,19 @@
@DslMarker
annotation class MyDsl
@MyDsl
interface Foo<T> {
val x: Int
}
val Foo<*>.bad: Int get() = x
fun Foo<*>.badFun(): Int = x
val Foo<Int>.good: Int get() = x
fun test(foo: Foo<*>) {
foo.apply {
x
}
}
@@ -0,0 +1,20 @@
package
public val Foo<*>.bad: kotlin.Int
public val Foo<kotlin.Int>.good: kotlin.Int
public fun test(/*0*/ foo: Foo<*>): kotlin.Unit
public fun Foo<*>.badFun(): kotlin.Int
@MyDsl public interface Foo</*0*/ T> {
public abstract val x: kotlin.Int
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
}
@kotlin.DslMarker public final annotation class MyDsl : kotlin.Annotation {
public constructor MyDsl()
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
}
@@ -0,0 +1,25 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
@DslMarker
annotation class MyDsl
@MyDsl
interface Scope<A, B> {
val something: A
val value: B
}
fun scoped1(block: Scope<Int, String>.() -> Unit) {}
fun scoped2(block: Scope<*, String>.() -> Unit) {}
val <T> Scope<*, T>.property: T get() = value
fun f() {
scoped1 {
value
property
}
scoped2 {
value
property
}
}
@@ -0,0 +1,21 @@
package
public val </*0*/ T> Scope<*, T>.property: T
public fun f(): kotlin.Unit
public fun scoped1(/*0*/ block: Scope<kotlin.Int, kotlin.String>.() -> kotlin.Unit): kotlin.Unit
public fun scoped2(/*0*/ block: Scope<*, kotlin.String>.() -> kotlin.Unit): kotlin.Unit
@kotlin.DslMarker public final annotation class MyDsl : kotlin.Annotation {
public constructor MyDsl()
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
}
@MyDsl public interface Scope</*0*/ A, /*1*/ B> {
public abstract val something: A
public abstract val value: B
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
}
@@ -0,0 +1,11 @@
@DslMarker
annotation class AnnMarker
@AnnMarker
class Inv<T> {
fun bar() {}
}
fun Inv<*>.foo() {
bar()
}
@@ -0,0 +1,18 @@
package
public fun Inv<*>.foo(): kotlin.Unit
@kotlin.DslMarker public final annotation class AnnMarker : kotlin.Annotation {
public constructor AnnMarker()
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
}
@AnnMarker public final class Inv</*0*/ T> {
public constructor Inv</*0*/ T>()
public final fun bar(): kotlin.Unit
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
}
@@ -17482,6 +17482,21 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
runTest("compiler/testData/diagnostics/tests/resolve/dslMarker/insideTopLevelExtensionAnnotatedType.kt");
}
@TestMetadata("kt29948.kt")
public void testKt29948() throws Exception {
runTest("compiler/testData/diagnostics/tests/resolve/dslMarker/kt29948.kt");
}
@TestMetadata("kt31360.kt")
public void testKt31360() throws Exception {
runTest("compiler/testData/diagnostics/tests/resolve/dslMarker/kt31360.kt");
}
@TestMetadata("markedReceiverWithCapturedTypeArgument.kt")
public void testMarkedReceiverWithCapturedTypeArgument() throws Exception {
runTest("compiler/testData/diagnostics/tests/resolve/dslMarker/markedReceiverWithCapturedTypeArgument.kt");
}
@TestMetadata("markersIntersection.kt")
public void testMarkersIntersection() throws Exception {
runTest("compiler/testData/diagnostics/tests/resolve/dslMarker/markersIntersection.kt");
@@ -17472,6 +17472,21 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
runTest("compiler/testData/diagnostics/tests/resolve/dslMarker/insideTopLevelExtensionAnnotatedType.kt");
}
@TestMetadata("kt29948.kt")
public void testKt29948() throws Exception {
runTest("compiler/testData/diagnostics/tests/resolve/dslMarker/kt29948.kt");
}
@TestMetadata("kt31360.kt")
public void testKt31360() throws Exception {
runTest("compiler/testData/diagnostics/tests/resolve/dslMarker/kt31360.kt");
}
@TestMetadata("markedReceiverWithCapturedTypeArgument.kt")
public void testMarkedReceiverWithCapturedTypeArgument() throws Exception {
runTest("compiler/testData/diagnostics/tests/resolve/dslMarker/markedReceiverWithCapturedTypeArgument.kt");
}
@TestMetadata("markersIntersection.kt")
public void testMarkersIntersection() throws Exception {
runTest("compiler/testData/diagnostics/tests/resolve/dslMarker/markersIntersection.kt");