KT-15844
Property with type inferred from getter could access primary constructor parameters inside the getter (which is incorrect, and caused problems in compilation). Fix scopes for property descriptor resolution. 'getScopeForMemberDeclarationResolution' in AbstractLazyMemberScope should always return member declaration resolution scope. Two scopes are required, because both property initializer and property accessors should see property type parameters.
This commit is contained in:
Vendored
+23
@@ -0,0 +1,23 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
object Delegate {
|
||||
operator fun getValue(x: Any?, y: Any?): String = ""
|
||||
}
|
||||
|
||||
fun <T> delegateFactory(p: Any) = Delegate
|
||||
|
||||
class C(p: Any, val v: Any) {
|
||||
|
||||
val test1 get() = <!UNRESOLVED_REFERENCE!>p<!>
|
||||
|
||||
val test2 get() = v
|
||||
|
||||
// NB here we can use both 'T' (property type parameter) and 'p' (primary constructor parameter)
|
||||
val <T> List<T>.test3 by delegateFactory<T>(p)
|
||||
|
||||
<!PROPERTY_WITH_NO_TYPE_NO_INITIALIZER!>val test4<!> get() { return <!UNRESOLVED_REFERENCE!>p<!> }
|
||||
|
||||
<!PROPERTY_WITH_NO_TYPE_NO_INITIALIZER!>var test5<!>
|
||||
get() { return <!UNRESOLVED_REFERENCE!>p<!> }
|
||||
set(nv) { <!UNRESOLVED_REFERENCE!>p<!>.<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>let<!> {} }
|
||||
}
|
||||
Vendored
+24
@@ -0,0 +1,24 @@
|
||||
package
|
||||
|
||||
public fun </*0*/ T> delegateFactory(/*0*/ p: kotlin.Any): Delegate
|
||||
|
||||
public final class C {
|
||||
public constructor C(/*0*/ p: kotlin.Any, /*1*/ v: kotlin.Any)
|
||||
public final val test1: [ERROR : Error function type]
|
||||
public final val test2: kotlin.Any
|
||||
public final val test4: [ERROR : No type, no body]
|
||||
public final var test5: [ERROR : No type, no body]
|
||||
public final val v: kotlin.Any
|
||||
public final val </*0*/ T> kotlin.collections.List<T>.test3: kotlin.String
|
||||
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 object Delegate {
|
||||
private constructor Delegate()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public final operator fun getValue(/*0*/ x: kotlin.Any?, /*1*/ y: kotlin.Any?): kotlin.String
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
Reference in New Issue
Block a user