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] ExtensionMethod for generic types does not work with generic parameters in ecj #2648

Closed
Rawi01 opened this issue Nov 17, 2020 · 2 comments · Fixed by #2658
Closed

[BUG] ExtensionMethod for generic types does not work with generic parameters in ecj #2648

Rawi01 opened this issue Nov 17, 2020 · 2 comments · Fixed by #2658

Comments

@Rawi01
Copy link
Collaborator

Rawi01 commented Nov 17, 2020

Describe the bug
Adding extension methods for generic types seems to be broken if there also is a generic parameter. I think I broke this while working a bunch of other bugs. I will try to fix this myself...

To Reproduce

import java.util.Arrays;
import java.util.List;

import lombok.experimental.ExtensionMethod;

@ExtensionMethod(ExtensionMethodGeneric.Extensions.class)
class ExtensionMethodGeneric {
	public void test() {
		List<String> stringList;
		List<Number> numberList;
		
		stringList.test(numberList);
	}
	
	static class Extensions {
		public static <T> void test(List<String> obj, List<T> list) {
			
		}
	}
}
12 ERROR The parameterized method <String>test(List<String>, List<String>) of type ExtensionMethodGeneric.Extensions is not applicable for the arguments (List<String>, List<Number>)

Expected behavior
It compiles without any error as it does if you call the extension method by hand.

Version info:

  • Lombok version: 1.18.16
  • Platform: Eclipse 2020-09

Additional context
This is a simplified example, there might be more problems if you use more complex generic stuff.

@Rawi01
Copy link
Collaborator Author

Rawi01 commented Nov 17, 2020

I added some code to copy generic information which seems to break this example:
https://github.com/rzwitserloot/lombok/blob/e1f82ac4d132769cfc272dccfc916aeba7181718/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethod.java#L307-L314
Removing this code snippet fixes the issue and all tests still pass, I guess that I should share the more complex cases somewhere next time 😄 , now I have to figure out why I added this stuff

Rawi01 added a commit to Rawi01/lombok that referenced this issue Nov 19, 2020
@Rawi01
Copy link
Collaborator Author

Rawi01 commented Nov 19, 2020

Was about to send a PR to remove the block but finally figured out what I tried to solve:

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import lombok.experimental.ExtensionMethod;

@ExtensionMethod(ExtensionMethodGeneric.Extensions.class)
class ExtensionMethodGeneric {
	public void test() {
		Stream.of("a", "b", "c").map(String::toUpperCase).toList();
	}

	static class Extensions {
		public static <T> List<T> toList(Stream<T> stream) {
			return (List<T>) stream.collect(Collectors.toList());
		}
	}
}

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.

1 participant