0
votes

The following code:

package com.gitlab.morality.navigable.support

import android.support.v4.app.Fragment
import android.support.v4.app.FragmentActivity
import kotlin.reflect.primaryConstructor

interface Navigable

val <FragmentType> FragmentType.parameters : MutableMap<String, in Any>
    where FragmentType : Fragment,
          FragmentType : Navigable
    by lazy { mutableMapOf<String, Any>() }

inline fun <reified FragmentType>
    FragmentType.navigate(containerViewId : Int, vararg parameters : Pair<String, Any>)
    where FragmentType : Fragment,
          FragmentType : Navigable {
    val fragment = FragmentType::class.primaryConstructor!!.call()
    parameters.forEach { fragment.parameters[it.first] = it.second }
    activity.supportFragmentManager.beginTransaction()
            .replace(containerViewId, fragment)
            .commit()
}

Causes the following compiler errors with Kotlin 1.0.5:

Error:(34, 9) Public-API inline function cannot access non-public-API 'internal open fun (): [ERROR : ] defined in root package'

Error:(34, 18) Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: public val FragmentType#1 (type parameter of com.gitlab.morality.navigable.support.navigate).parameters: MutableMap where FragmentType : Navigable defined in com.gitlab.morality.navigable.support

I don't understand what I'm doing wrong here. What do these error messages mean?

I can work around the issue by instead making the parameters property a member of Navigable, but then an implementor is required to implement the property, which takes away from the attraction of this technique which is that an implementing class doesn't need to do anything special beyond being marked as Navigable to make use of Navigable functionality.

1

1 Answers

3
votes

Extension properties with multiple receiver types are not supported at this time. You can vote for KT-10468 to get notified when the issue is fixed.