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

ReplaceLambdaWithMethodReference breaks with local record definition #336

Open
mbruggmann opened this issue Sep 9, 2024 · 0 comments
Open
Labels
bug Something isn't working

Comments

@mbruggmann
Copy link
Contributor

mbruggmann commented Sep 9, 2024

What version of OpenRewrite are you using?

I am using

  • OpenRewrite 8.34.4
  • rewrite-static-analysis 1.15.0

What is the smallest, simplest way to reproduce the problem?

I can reproduce the issue with this testcase:

  @Test
  void methodReferenceForLocalRecord() {
    rewriteRun(
        spec -> spec.recipe(new ReplaceLambdaWithMethodReference()),
        java(
            """
            package com.helloworld;

            import java.util.stream.Stream;

            public class Main {
              public Stream<String> get() {
                record R(String s) {}
                return Stream.of(new R("hello world"))
                    .map(r -> r.s());
              }
            }""",
            """
            package com.helloworld;

            import java.util.stream.Stream;

            public class Main {
              public Stream<String> get() {
                record R(String s) {}
                return Stream.of(new R("hello world"))
                    .map(R::s);
              }
            }"""));
  }

What did you expect to see?

For the method reference to point to the record name, like R::...

What did you see instead?

The method reference starts with a number, like 1R::.... Possibly because the record is defined inline in the method?

Are you interested in contributing a fix to OpenRewrite?

Sorry, I don't have any spare hack time at the moment.

@mbruggmann mbruggmann added the bug Something isn't working label Sep 9, 2024
@timtebeek timtebeek moved this to Backlog in OpenRewrite Sep 12, 2024
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
Status: Backlog
Development

No branches or pull requests

1 participant