https://kotlinlang.org logo
#intellij
Title
# intellij
d

dave08

10/11/2023, 6:36 AM
I have this:
Copy code
interface MessageReceiver {
    operator fun <T : Any> invoke(
        subject: String,
        queue: String? = null,
        type: KClass<T>,
        block: suspend (T) -> Unit
    )
}

inline operator fun <reified T : Any> MessageReceiver.invoke(
    subject: String,
    queue: String? = null,
    noinline block: suspend (T) -> Unit
) = invoke(subject, queue, T::class, block)
and neither Intellij nor Fleet know how to import the second one automatically... I keep on having to write the import myself... is there any way to get this to auto-import?
x

xoangon

10/11/2023, 6:53 PM
You could try having a factory function with the same name as the interface (the same as the
List
or
CoroutineScope
factory functions)
d

dave08

10/12/2023, 6:39 AM
I can't really, since I need the MessageReceiver context that's initialized elsewhere... 😞
k

Klitos Kyriacou

10/12/2023, 8:58 AM
That's interesting; for simpler functions, it manages to offer "Import extension function". But not for this one.
d

dave08

10/12/2023, 8:59 AM
I wonder if I can put it straight in the interface... I think I tried, and there was some problem with that...
Yup
'inline' modifier is not allowed on virtual members. Only private or final members can be inlined
...
Can't do that either...
x

xoangon

10/12/2023, 9:03 AM
What about changing the
interface
for an
abstract class
?
d

dave08

10/12/2023, 9:08 AM
That's one option, I guess... although I don't like `abstract class`es too much, here I don't see why I would derive from it and something else... I'm just wondering if this is a known bug in Intellij... or just something normal.
k

Klitos Kyriacou

10/12/2023, 9:15 AM
"Bug" might be too strong a term, but certainly an arbitrary limitation to this feature, worth reporting at https://youtrack.jetbrains.com/newIssue