Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't I use @PublishedApi on typealias?

Tags:

kotlin

In my current project I have a public interface for different kind of queries

interface Query<T>

and an internal implementation for that interface. Since I have public inline functions to create different queries I need to use @PublishedApi on that class

@PublishedApi
internal class QueryImpl<T> : Query<T>

Now for convenience I want to define some type-aliases for the different kind of queries.

typealias MatchQuery = Query<MatchQueryProperties>

this works very well for that public interface but I need to create one instance of it in my public inline function

inline fun match(init: MatchQuery.() -> Unit) {
    // It would look nicer if I could use MatchQueryImpl().init()
    QueryImpl<MatchQueryProperties>().init()
}

But instead of having to write QueryImpl<PropertiesType> for every kind of query I want to use an internal typealias for the implementation as well.

// fails because it needs to be internal
typealias MatchQueryImpl = QueryImpl<MatchQueryProperties>

// can't be used in public inline functions
internal typealias MatchQueryImpl = QueryImpl<MatchQueryProperties> 

// annotation can't be used on typealias
@PublishedApi internal typealias MatchQueryImpl = QueryImpl<MatchQueryProperties>

So my questions are:
Can I somehow use an @PublishedApi internal typealias?
If not why can't I use one?
Is there another way of archiving what I want?

like image 708
danielspaniol Avatar asked Nov 22 '25 16:11

danielspaniol


1 Answers

Currently you cannot use a non-public typealias in a public inline function. That's a current shortcoming of how the inline function checks whether it's ok to use non-public API inside its body.

I've opened an issue KT-19407 to track and discuss this problem.

like image 101
Ilya Avatar answered Nov 25 '25 10:11

Ilya