Forbid using ext.property type parameter also for delegate ext.receiver

This commit is contained in:
Mikhail Glukhikh
2021-04-08 15:37:07 +03:00
parent e2cc0510de
commit 3e9ef56c31
7 changed files with 49 additions and 1 deletions
@@ -715,8 +715,10 @@ class DeclarationsChecker(
} else if (property.receiverTypeReference != null) {
val delegatedPropertyResolvedCall = trace.get(DELEGATED_PROPERTY_RESOLVED_CALL, propertyDescriptor.getter)
val dispatchReceiverType = delegatedPropertyResolvedCall?.dispatchReceiver?.type
val extensionReceiverType = delegatedPropertyResolvedCall?.extensionReceiver?.type
val usedParameter = propertyDescriptor.typeParameters.find { typeParameter ->
dispatchReceiverType?.contains { it.constructor == typeParameter.typeConstructor } == true
dispatchReceiverType?.contains { it.constructor == typeParameter.typeConstructor } == true ||
extensionReceiverType?.contains { it.constructor == typeParameter.typeConstructor } == true
}
if (usedParameter != null) {
if (languageVersionSettings.supportsFeature(LanguageFeature.ForbidUsingExtensionPropertyTypeParameterInDelegate)) {
@@ -8,6 +8,12 @@ class Delegate<T : Any> {
var <T : Any> List<T>.foo by Delegate<T>()
class Wrapper<T>(val v: T? = null)
operator fun <T> Wrapper<T>.getValue(thisRef: Any?, kp: Any?): T = v!!
val <T : Any> List<T>.bar by Wrapper<T>()
fun useString(s: String) {}
fun main(listInt: List<Int>, listStr: List<String>) {
@@ -8,6 +8,12 @@ class Delegate<T : Any> {
var <T : Any> List<T>.foo <!DELEGATE_USES_EXTENSION_PROPERTY_TYPE_PARAMETER!>by Delegate<T>()<!>
class Wrapper<T>(val v: T? = null)
operator fun <T> Wrapper<T>.getValue(thisRef: Any?, kp: Any?): T = v!!
val <T : Any> List<T>.bar <!DELEGATE_USES_EXTENSION_PROPERTY_TYPE_PARAMETER!>by Wrapper<T>()<!>
fun useString(s: String) {}
fun main(listInt: List<Int>, listStr: List<String>) {
@@ -1,8 +1,10 @@
package
public val </*0*/ T : kotlin.Any> kotlin.collections.List<T>.bar: T
public var </*0*/ T : kotlin.Any> kotlin.collections.List<T>.foo: T
public fun main(/*0*/ listInt: kotlin.collections.List<kotlin.Int>, /*1*/ listStr: kotlin.collections.List<kotlin.String>): kotlin.Unit
public fun useString(/*0*/ s: kotlin.String): kotlin.Unit
public operator fun </*0*/ T> Wrapper<T>.getValue(/*0*/ thisRef: kotlin.Any?, /*1*/ kp: kotlin.Any?): T
public final class Delegate</*0*/ T : kotlin.Any> {
public constructor Delegate</*0*/ T : kotlin.Any>()
@@ -13,3 +15,12 @@ public final class Delegate</*0*/ T : kotlin.Any> {
public final operator fun setValue(/*0*/ thisRef: kotlin.Any?, /*1*/ kp: kotlin.Any?, /*2*/ newValue: T): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class Wrapper</*0*/ T> {
public constructor Wrapper</*0*/ T>(/*0*/ v: T? = ...)
public final val v: T?
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
}
@@ -8,6 +8,12 @@ class Delegate<T : Any> {
var <T : Any> List<T>.foo by Delegate<T>()
class Wrapper<T>(val v: T? = null)
operator fun <T> Wrapper<T>.getValue(thisRef: Any?, kp: Any?): T = v!!
val <T : Any> List<T>.bar by Wrapper<T>()
fun useString(s: String) {}
fun main(listInt: List<Int>, listStr: List<String>) {
@@ -8,6 +8,12 @@ class Delegate<T : Any> {
var <T : Any> List<T>.foo <!DELEGATE_USES_EXTENSION_PROPERTY_TYPE_PARAMETER_WARNING!>by Delegate<T>()<!>
class Wrapper<T>(val v: T? = null)
operator fun <T> Wrapper<T>.getValue(thisRef: Any?, kp: Any?): T = v!!
val <T : Any> List<T>.bar <!DELEGATE_USES_EXTENSION_PROPERTY_TYPE_PARAMETER_WARNING!>by Wrapper<T>()<!>
fun useString(s: String) {}
fun main(listInt: List<Int>, listStr: List<String>) {
@@ -1,8 +1,10 @@
package
public val </*0*/ T : kotlin.Any> kotlin.collections.List<T>.bar: T
public var </*0*/ T : kotlin.Any> kotlin.collections.List<T>.foo: T
public fun main(/*0*/ listInt: kotlin.collections.List<kotlin.Int>, /*1*/ listStr: kotlin.collections.List<kotlin.String>): kotlin.Unit
public fun useString(/*0*/ s: kotlin.String): kotlin.Unit
public operator fun </*0*/ T> Wrapper<T>.getValue(/*0*/ thisRef: kotlin.Any?, /*1*/ kp: kotlin.Any?): T
public final class Delegate</*0*/ T : kotlin.Any> {
public constructor Delegate</*0*/ T : kotlin.Any>()
@@ -13,3 +15,12 @@ public final class Delegate</*0*/ T : kotlin.Any> {
public final operator fun setValue(/*0*/ thisRef: kotlin.Any?, /*1*/ kp: kotlin.Any?, /*2*/ newValue: T): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class Wrapper</*0*/ T> {
public constructor Wrapper</*0*/ T>(/*0*/ v: T? = ...)
public final val v: T?
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
}