Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

delay extension reduces type detection (for Observable.create series) #249

Open
samuelchou opened this issue Aug 18, 2022 · 0 comments
Open

Comments

@samuelchou
Copy link

It seems that kotlin type recognition for Observable.create extension series will fail, after adding delay functions.

For example, consider code below:

data class User(val id: String, val name: String, val age: Int)

val exampleUser("test0001", "Samuel", 27)

fun getUserById(id: String): Single<User> {
    return Single.create { single ->
         exampleUser.copy(id = id).let { single.onSuccess(it) }
    }
}

Everything works fine.

Now, if I add .delay behind:

fun getUserById(id: String): Single<User> {
    return Single.create { single ->
         exampleUser.copy(id = id).let { single.onSuccess(it) }
    }.delay(500, TimeUnit.MILLISECDONDS)
}

And then build it. The editor would throw build errors at Single.create line:

at end of `Single.create`:
Not enough information to infer type variable T

at start of `single`:
Cannot infer a type for this parameter. Please specify it explicitly.

If I specify the type, the build errors will disappear:

fun getUserById(id: String): Single<User> {
    return Single.create<User> { single ->
         exampleUser.copy(id = id).let { single.onSuccess(it) }
    }.delay(500, TimeUnit.MILLISECDONDS)
}

However, some editor/kotlin plugin might suggest to "Remove explicit type arguments" then.

These errors seems not only happen at Single.create, but also at Observable.create. I guess the errors happen in all .create series?

Versions

I'm using 3.0.1 in Android Studio.

All Rx related version:

implementation 'io.reactivex.rxjava3:rxkotlin:3.0.1'
implementation 'io.reactivex.rxjava3:rxandroid:3.0.0'
implementation 'com.uber.rxdogtag2:rxdogtag:2.0.1'
implementation 'com.squareup.retrofit2:adapter-rxjava3:2.9.0'
implementation 'androidx.room:room-rxjava3:2.4.1'

The editor and plugin version:

Android Studio Chipmunk | 2021.2.1 Patch 1
Build #AI-212.5712.43.2112.8609683, built on May 19, 2022

Kotlin Plugin:
212-1.7.10-release-333-AS5457.46
@samuelchou samuelchou changed the title delay extension reduces type detection (for Observable.create extension series) delay extension reduces type detection (for Observable.create series) Aug 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant