Files
kotlin-fork/compiler/testData/diagnostics/tests/properties/inferenceFromGetters/primaryConstructorParameter.kt
T
Dmitry Petrov e31e12474f 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.
2017-01-23 10:22:34 +03:00

23 lines
732 B
Kotlin
Vendored

// !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<!> {} }
}