-
Notifications
You must be signed in to change notification settings - Fork 12
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
Fix compilation on K.CompilationUnit.service #593
Conversation
@@ -341,7 +341,7 @@ public K.CompilationUnit withStatements(List<JRightPadded<Statement>> statements | |||
|
|||
@Override | |||
@SuppressWarnings("unchecked") | |||
public <S> S service(Class<S> service) { | |||
public <S, T extends S> T service(Class<S> service) { | |||
String serviceName = service.getName(); | |||
try { | |||
Class<S> serviceClass; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had my doubts here whether Class<S>
should be Class<T>
too here or in the casts below. 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should. As T extends S and you are returning T you can cast T to S but not S to T.
edit: nope, this seems to be intentional. We check for a supertype S and find the subtype T for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sambsnyd any insight here appreciated; wouldn't want to hide a compile error with a misplaced cast.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might not have needed to change this signature originally. Whether it returns S
or T extends S
the meaning, and opportunities for ClassCastException
are largely the same.
Pushed a similar change to rewrite-javascript such that does not fall out of line with our releases openrewrite/rewrite-javascript@8a6d7e8 |
After openrewrite/rewrite@33d8f7d