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

[BUG] Lombok tries to apply an extension method to a wrong type #2741

Closed
vbarhatov opened this issue Feb 4, 2021 · 1 comment · Fixed by #2743
Closed

[BUG] Lombok tries to apply an extension method to a wrong type #2741

vbarhatov opened this issue Feb 4, 2021 · 1 comment · Fixed by #2743

Comments

@vbarhatov
Copy link

I use @ExtensionMethod annotation to add some methods to collections.
I declare an extension method filter() for List<T> but Lombok tries to apply this method to Stream<T> type.

How to reproduce

import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Stream;
import lombok.experimental.ExtensionMethod;

@ExtensionMethod(Main.ExtensionMethods.class)
public class Main
{
    public static class ExtensionMethods
    {
        public static <T> Stream<T> filter(List<T> list, Predicate<? super T> predicate)
        {
            return list.stream().filter(predicate);
        }
    }

    public static void main(String[] args)
    {
        List<Integer> list = Arrays.asList(1, 2, 3);

        Stream<Integer> stream = list.filter(i -> true);
        Stream<Integer> itWorks = stream.filter(i -> true);

        Stream<Integer> itDoesntWork = list.filter(i -> true).filter(i -> true);
    }
}

Expected behavior

It should work.

Actual behavior
Lombok returns the following error during a compilation process:

error: method filter in class ExtensionMethods cannot be applied to given types;
  required: List<T>,Predicate<? super T>
  found: Stream<Integer>,(i)->true
  reason: no instance(s) of type variable(s) T exist so that Stream<T> conforms to List<T>
  where T is a type-variable:
    T extends Object declared in method <T>filter(List<T>,Predicate<? super T>)
1 error

Version info:

  • Lombok version: I tried two versions – 16.16, 18.18
  • Platform Gradle, IntelliJ IDEA,
  • JVM: 1.8.0_252 (Amazon.com Inc. 25.252-b09), 11.0.7 (Amazon.com Inc. 11.0.7+10-LTS)
@Rawi01
Copy link
Collaborator

Rawi01 commented Feb 7, 2021

Thanks for the reproducer, should be fixed with the linked PR.

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

Successfully merging a pull request may close this issue.

2 participants