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

Fix compilation on K.CompilationUnit.service #593

Merged
merged 1 commit into from
Feb 6, 2024
Merged

Conversation

timtebeek
Copy link
Contributor

@timtebeek timtebeek added the bug Something isn't working label Feb 6, 2024
@timtebeek timtebeek self-assigned this Feb 6, 2024
@@ -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;
Copy link
Contributor Author

@timtebeek timtebeek Feb 6, 2024

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. 🤔

Copy link
Contributor

@pstreef pstreef Feb 6, 2024

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

@timtebeek timtebeek marked this pull request as draft February 6, 2024 13:16
@timtebeek timtebeek added the help wanted Extra attention is needed label Feb 6, 2024
@timtebeek timtebeek marked this pull request as ready for review February 6, 2024 17:25
@timtebeek timtebeek merged commit bce277f into main Feb 6, 2024
1 check passed
@timtebeek timtebeek deleted the fix-compilation branch February 6, 2024 17:32
timtebeek added a commit to openrewrite/rewrite-javascript that referenced this pull request Feb 6, 2024
@timtebeek
Copy link
Contributor Author

Pushed a similar change to rewrite-javascript such that does not fall out of line with our releases openrewrite/rewrite-javascript@8a6d7e8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants