Git Product home page Git Product logo

Comments (6)

 avatar commented on September 18, 2024

I'm guessing some issue with the Kotlin generics compatibility, so reporting there was def. the right approach
@maxtroy I assume there's not much we can do with the use of generics here, fixing in Kotlin is the only way forward?

from agera.

maxtroy avatar maxtroy commented on September 18, 2024

We can't really do anything, I'm afraid.

Because Android Studio is the recommended way to program Android code, the current design places Android Studio use case first, making sure the IDE sees the right types and auto-completes the right subset of methods available at any given state.

The generics we use in the repository compiler are a bit quirky (and towards the verbose/redundant end of the spectrum), due to Android Studio (or IntelliJ) internal type checker having some difference with the real Java compiler. In particular, Android Studio does NOT like the following class hierarchy:

interface Base<T> {}
interface X<T> extends Base<X<T>> {}
interface Y<T> extends Base<Y<T>> {}

@SuppressWarnings({"rawtypes", "unchecked"})
interface Compiler extends X, Y {}

With the error that "Base<T> cannot be extended with different type parameters", despite the explicit request to ignore the type parameters (suppressing raw types and unchecked casts warnings).

Note that this is IntelliJ-only; the real Java compiler has no issues with this hierarchy. This bug has been reported more than one year ago, with no official solution so far. The way we work around this IntelliJ limitation is to allow the "different" type parameters to unify:

interface Base<T> {}
interface X<T, S extends X<T, S>> extends Base<S> {}
interface Y<T, S extends Y<T, S>> extends Base<S> {}

@SuppressWarnings({"rawtypes", "unchecked"})
interface Compiler extends X, Y {}

Because in this way, the ("unnecessarily smart") IntelliJ type inference system can find a common subclass S that extends both X<T, S> and Y<T, S> (aka Compiler), so the interface Base<S> is inherited with the same type parameter.

I'm guessing that the Kotlin compiler might not be able to handle this type hierarchy and gives up at some point.

from agera.

 avatar commented on September 18, 2024

Closing this, since there's not much that can be done in Agera. Kotlin promises Java interop. so hopefully KT-14725 can be resolve soon.

from agera.

sfcecy7i avatar sfcecy7i commented on September 18, 2024

Hoping this helps.

fun <F : RepositoryCompilerStates.RFlow<*, *, *>, T> F.asT(c: Class<T>? = null): RepositoryCompilerStates.RFlow<T, T, *> = this as RepositoryCompilerStates.RFlow<T, T, *>

fun <F : RepositoryCompilerStates.RFlow<*, *, *>, T> F.asResultT(c: Class<T>? = null): RepositoryCompilerStates.RFlow<Result<T>, T, *> = this as RepositoryCompilerStates.RFlow<Result<T>, T, *>

@TestOnly
fun test(): Repository<Result<String>> {
    return Repositories.repositoryWithInitialValue(Result.absent<String>())
            .observe()
            .onUpdatesPerLoop()
            .goTo(Executors.threadPollExecutor())
            .asT(Result::class.java)
            .attemptGetFrom { Result.present("123") }
            .orEnd { Result.failure<String>() }
            .check { it.isNotEmpty() }
            .orEnd { Result.failure() }
            .asResultT(String::class.java)
            .sendTo { Log.e("TTEST", "sendTo") }
            .asResultT(String::class.java)
            .transform { "111" }
            .thenTransform { Result.present(it) }
            .notifyIf { _, _ -> true }
            .onConcurrentUpdate(RepositoryConfig.SEND_INTERRUPT)
            .compile()
}

from agera.

LouisCAD avatar LouisCAD commented on September 18, 2024

@sfcecy7i Should work with reified too.

inline fun <reified F : RepositoryCompilerStates.RFlow<*, *, *>, T> F.typed(): RepositoryCompilerStates.RFlow<T, T, *> = this as RepositoryCompilerStates.RFlow<T, T, *>

inline fun <reified F : RepositoryCompilerStates.RFlow<*, *, *>, T> F.typedResult(): RepositoryCompilerStates.RFlow<Result<T>, T, *> = this as RepositoryCompilerStates.RFlow<Result<T>, T, *>

@TestOnly
fun test(): Repository<Result<String>> {
    return Repositories.repositoryWithInitialValue(Result.absent<String>())
            .observe()
            .onUpdatesPerLoop()
            .goTo(Executors.threadPollExecutor())
            .typed<Result>()
            .attemptGetFrom { Result.present("123") }
            .orEnd { Result.failure<String>() }
            .check { it.isNotEmpty() }
            .orEnd { Result.failure() }
            .typedResult<String>()
            .sendTo { Log.e("TTEST", "sendTo") }
            .typedResult<String>()
            .transform { "111" }
            .thenTransform { Result.present(it) }
            .notifyIf { _, _ -> true }
            .onConcurrentUpdate(RepositoryConfig.SEND_INTERRUPT)
            .compile()
}

from agera.

sfcecy7i avatar sfcecy7i commented on September 18, 2024

@LouisCAD Thanks for your advice.

inline fun <reified TPre, reified TVal> RepositoryCompilerStates.RFlow<*, *, *>.reify() = this as RepositoryCompilerStates.RFlow<TVal, TPre, *>

inline fun <reified TVal> RepositoryCompilerStates.RFlow<*, *, *>.reify1() = this as RepositoryCompilerStates.RFlow<TVal, *, *>

    @TestOnly
    fun test(): Repository<Result<String>> {
        return Repositories.repositoryWithInitialValue(Result.absent<String>())
                .observe()
                .onUpdatesPerLoop()
                .goTo(KExecutors.threadPollExecutor())
                .reify1<Result<String>>()
                .attemptGetFrom { Result.present("success") }
                .orEnd { Result.failure<String>() }
                .check { it.isNotEmpty() }
                .orEnd { Result.failure() }
                .sendTo { Log.e("TAG", "result: $it") }
                .reify<String, Result<String>>()
                .transform { "$it end" }
                .thenTransform { Result.present(it) }
                .notifyIf { _, _ -> true }
                .onConcurrentUpdate(RepositoryConfig.SEND_INTERRUPT)
                .compile()
    }

from agera.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.