Delegates.mapVal and mapVar preserve type of the receiver to when calling default value lambda.

This commit is contained in:
Ilya Gorbunov
2015-11-18 04:20:27 +03:00
parent 0f70def3db
commit 9d24f1d1cf
2 changed files with 32 additions and 17 deletions
@@ -55,9 +55,9 @@ public object Delegates {
* @param map the map where the property values are stored.
* @param default the function returning the value of the property for a given object if it's missing from the given map.
*/
public fun <T> mapVar(map: MutableMap<in String, Any?>,
default: (thisRef: Any?, desc: String) -> T): ReadWriteProperty<Any?, T> {
return FixedMapVar<Any?, String, T>(map, propertyNameSelector, default)
public fun <R, T> mapVar(map: MutableMap<in String, Any?>,
default: (thisRef: R, propertyName: String) -> T): ReadWriteProperty<R, T> {
return FixedMapVar<R, String, T>(map, propertyNameSelector, default)
}
/**
@@ -76,9 +76,9 @@ public object Delegates {
* @param map the map where the property values are stored.
* @param default the function returning the value of the property for a given object if it's missing from the given map.
*/
public fun <T> mapVal(map: Map<in String, Any?>,
default: (thisRef: Any?, desc: String) -> T): ReadOnlyProperty<Any?, T> {
return FixedMapVal<Any?, String, T>(map, propertyNameSelector, default)
public fun <R, T> mapVal(map: Map<in String, Any?>,
default: (thisRef: R, propertyName: String) -> T): ReadOnlyProperty<R, T> {
return FixedMapVal<R, String, T>(map, propertyNameSelector, default)
}
}