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

Source-incompatibility during #3047: "Make FlowCollector fun interface, remove redundant extensions" #3107

Open
qwwdfsad opened this issue Dec 22, 2021 · 3 comments

Comments

@qwwdfsad
Copy link
Member

@qwwdfsad qwwdfsad commented Dec 22, 2021

In #3047, the Flow.collect(action) extension was removed in the favour of the freshly-added SAM conversion.

The extension was inline, so the change is binary compatible and previously compiled clients continue working without any issues, but such change breaks a pattern with using functional type as a non-inline argument.

The following code no longer compiles:

val action: suspend (value: Int) -> Unit = { println(it) }
flowOf(1, 2, 3).collect(action)

with the following workaround:

flowOf(1, 2, 3).collect { action(it) }

This incompatibility was discovered after the stable release 1.6.0. Our integration and user-project testing along with RC releases haven't revealed the issue, so the scope of the impact stays unclear.

We're aiming to fix it in the following patch release, feel free to comment on the issue if the impact prevents you from upgrading in order for us to be aware of the urgency of the fix

@elizarov
Copy link
Member

@elizarov elizarov commented Dec 22, 2021

@gmk57
Copy link

@gmk57 gmk57 commented Jan 10, 2022

This change broke our small helper function for Android:

fun <T> StateFlow<T>.observe(lifecycleOwner: LifecycleOwner, action: suspend (T) -> Unit) =
    lifecycleOwner.lifecycleScope.launchWhenStarted { collect(action) }

After changing action type to FlowCollector<T> everything seems to work again.

@mhernand40
Copy link

@mhernand40 mhernand40 commented Jan 24, 2022

FWIW, doesn't this also break the following:

flow
    .onEach { … }
    .collect()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

4 participants