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

Kotlin IntelliJ plugin crashes on StatefulWorkflow and action builder #100

Closed
zach-klippenstein opened this issue Mar 2, 2020 · 19 comments
Assignees
Milestone

Comments

@zach-klippenstein
Copy link
Collaborator

There is a bug in the plugin that crashes the parser when it encounters action. @kirillzh filed JetBrains an issue about it.

I've created a minimal Android Studio project that demonstrates this bug: https://github.com/zach-klippenstein/repro-KT-34524

Open the project in Android Studio and open the file app/src/main/java/com/example/kt_34524repro/SampleWorkflow.kt to see the bug in action.

There are a few other issues that look to be related or duplicates:

@zach-klippenstein
Copy link
Collaborator Author

Verified this still occurs with plugin version 1.3.70-eap-274-Studio4.0-1.

@zach-klippenstein
Copy link
Collaborator Author

Posted about this issue in the Kotlin Slack's #compiler channel.

@zach-klippenstein
Copy link
Collaborator Author

We just heard from a contact at JetBrains that they're aware of this issue and considering how to prioritize it. There's maybe even a small chance it could be fixed in 1.3.70, but no guarantees.

@zach-klippenstein
Copy link
Collaborator Author

A related issue, https://youtrack.jetbrains.com/issue/KT-34759, has been marked as Fixed.

Our issue, https://youtrack.jetbrains.com/issue/KT-34524, is still In Progress.

@zach-klippenstein
Copy link
Collaborator Author

Our issue (https://youtrack.jetbrains.com/issue/KT-34524) has had its Target versions updated to 1.4-M2. Unfortunately, this means we won't see a fix probably at least for a couple months. However, it does mean that it's likely being actively worked on and so there's not much point in us trying to solve it ourselves.

@rjrjr rjrjr self-assigned this Mar 23, 2020
@rjrjr
Copy link
Contributor

rjrjr commented Mar 23, 2020

After an offline conversation w/Zach, going to see if changing RenderContext to an inner class of StatefulWorkflow improves things any.

@rjrjr
Copy link
Contributor

rjrjr commented Mar 23, 2020

One of the differences between Mutator and Updater is that the latter made OutputT a function argument instead of a return value. To make that work we had to change the OutputT on RenderContext to an in type, while it's an out type on Workflow.

Given the timing of this bug, I'll bet you anything that this mismatch is related.

@rjrjr
Copy link
Contributor

rjrjr commented Mar 23, 2020

I'm playing with dropping in and out from the OutputT declarations. But wouldn't it be funny if the fix were as simple as changing the name of the type param on RenderContext from OutputT to O?

@rjrjr
Copy link
Contributor

rjrjr commented Mar 23, 2020

Dropping in and out didn't change anything.

@rjrjr
Copy link
Contributor

rjrjr commented Mar 23, 2020

Wellllll…

This change does indeed fix the IDE. There are issues.

    override fun render(
        props: Unit,
        context: StatefulWorkflow<Unit, Unit, Nothing, Unit>.RenderContext
    ) {
  • I think I saw a couple of spots where inline action {} breaks down with Nothing output type, not sure.

@rjrjr
Copy link
Contributor

rjrjr commented Mar 23, 2020

Looking at our internal stats, StatelessWorkflow is pretty popular, accounts for about a quarter of all Workflow implementations.

@zach-klippenstein
Copy link
Collaborator Author

But StatelessWorkflow gets worse:

If we go this route, I think we should just define a different context type for StatelessWorkflow. Then we can drop that weird Nothing type parameter altogether.

@rjrjr
Copy link
Contributor

rjrjr commented Mar 23, 2020

That makes a lot of sense. Winds up being a net usability win.

@rjrjr
Copy link
Contributor

rjrjr commented Mar 23, 2020

But we'll wind up needing two implementations of RenderTester. Yuck.

Maybe there's a base context type they can share, and then the inner classes are little facades with the two workflow base classes.

abstract class AbstractRenderContext<P, S, O> { ... }

abstract class StatefulWorkflow<P, S, O, R>() : Workflow<P, O , R> {
  inner class RenderContext : AbstractRenderContext<P, S, O> { ... }
}

class StatefulRenderTester <P, S, O, R>: AbstractRenderContext<P, S, O> { }

abstract class StatelessWorkflow<P, O, R>() : Workflow<P, Unit, O , R> {
  inner class RenderContext : AbstractRenderContext<P, Unit, Nothing> { ... }
}

class StatelessRenderTester <P, O, R>: AbstractRenderContext<P, Unit, O> { }

@rjrjr
Copy link
Contributor

rjrjr commented Mar 24, 2020

That's not right, but you get the idea.

@zach-klippenstein
Copy link
Collaborator Author

Yea, something like that. I'm not too worried about exploding the number of RenderContext types because so far all the abstract *Workflow classes I've written/thought about writing, that aren't StatefulWorkflow/StatelessWorkflow, don't actually need a RenderContext at all.

@zach-klippenstein
Copy link
Collaborator Author

zach-klippenstein commented Apr 16, 2020

Good news, upgrading Android Studio to Kotlin plugin 1.4-M1 seems to fix the issue in our repro project (https://github.com/zach-klippenstein/repro-KT-34524). The kotlin file is parsed, the action {} builder is highlighted as missing and offered to be imported, and the uncommented prose is highlighted as invalid syntax. Haven't tested with our big internal codebase yet, but this is a good step in the right direction!

@zach-klippenstein
Copy link
Collaborator Author

zach-klippenstein commented Jun 12, 2020

1.4-M1 didn't fix for everyone. But latest comms from Jetbrains is that it's been fixed in M3. I'll mark as blocked until then and leave it open, but there's no action items on our part. I will remove from the 1.0.0 milestone as well.

@zach-klippenstein zach-klippenstein transferred this issue from square/workflow Jul 6, 2020
@zach-klippenstein zach-klippenstein added this to the post-v1.0.0 milestone Jul 6, 2020
@zach-klippenstein
Copy link
Collaborator Author

One report that plugin 1.4-M3 has fixed this issue in AS 4.0 (internal message).

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

2 participants