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:
Dmitry Petrov
2017-01-20 16:38:38 +03:00
parent 2edcd369a8
commit e31e12474f
8 changed files with 115 additions and 35 deletions
@@ -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<!> {} }
}