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

Suspend lambda gets mangled during parsing/rewrite #55

Merged
merged 3 commits into from
Apr 3, 2023

Conversation

nomisRev
Copy link
Contributor

A Kotlin suspend lambda gets rewritten incorrectly.

suspend fun example(
  title: String,
  verifyUnique: suspend (String) -> Boolean
): String = TODO()

becomes

suspend fun example(
  title: String,
  verifyUnique: Stringsuspend (String) -> Boolean
): String = TODO()

@timtebeek timtebeek added the bug Something isn't working label Mar 30, 2023
@timtebeek timtebeek requested a review from traceyyoshima March 30, 2023 07:42
import static org.assertj.core.api.Assertions.assertThat;
import static org.openrewrite.kotlin.Assertions.kotlin;

public class SuspendLambdaTest implements RewriteTest {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @nomisRev , thanks for reporting the issue and creating a PR!
I'm happy with the test, but I think it should be added to MethodDeclarationTest.

I'd prefer you to have credit for the changes -- would you please add the test the LambdaTest instead?

Info:
In the test package under org.openrewrite.kotlin.tree each of the tests use ParserAssertions instead of Assertions. ParserAssertions includes an additional step to check if the source is fully parsed by checking if any text exists in Space. All of the parsing tests exist there, and we apply similar conventions across other languages.

Changes:

  • Added issue annotation with a link to the open issue.
  • Changed test name to communicate what is parsed.
    @Issue("https://github.com/openrewrite/rewrite-kotlin/issues/56")
    @Test
    void lambdaMethodParameterWithModifier() {
        rewriteRun(
          kotlin(
            """
            suspend fun example(
              title: String,
              verifyUnique: suspend (String) -> Boolean
            ): String = TODO()
            """,
            """            
            suspend fun example(
              title: String,
              verifyUnique: suspend (String) -> Boolean
            ): String = TODO()
            """
          )
        );
    }

@nomisRev
Copy link
Contributor Author

nomisRev commented Apr 3, 2023

Hey @traceyyoshima,

First of all thank you of thinking about giving me credit! I update the PR according to your feedback but was a little bit confused about:

I'm happy with the test, but I think it should be added to MethodDeclarationTest.

I'd prefer you to have credit for the changes -- would you please add the test the LambdaTest instead?

Looking at the tests in both MethodDeclarationTest and MethodDeclarationTest I felt it made more sense in the former.

Additionally, I also added the empty spaces as done in the other parsers tests. If you have any more feedback please let me know, and I'll happily adjust accordingly. I added @Disabled so we can go ahead and merge this test as discussed on Slack.

@traceyyoshima
Copy link
Contributor

Looking at the tests in both MethodDeclarationTest and MethodDeclarationTest I felt it made more sense in the former.

Ah, that's a great observation -- Initially, I added a comment suggesting LambdaTest, but decided on MethodDeclarationTest, because I don't think suspend would be valid applied to general lambdas.

@traceyyoshima traceyyoshima merged commit 35fd99a into openrewrite:main Apr 3, 2023
@nomisRev
Copy link
Contributor Author

nomisRev commented Apr 3, 2023

because I don't think suspend would be valid applied to general lambdas.

That is actually not the case, there is a special case suspend { } and I've written two failing cases based on them.
One related to this one, I will link it to the same issue.

And another one I am not sure what is happening, so I'll open a new issue for it. I'll raise a PR in a sec.

@nomisRev nomisRev deleted the suspend-lambda-mangled branch April 3, 2023 20:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants