Skip to content

Commit

Permalink
[fixes #3463] Support argument widening for extension methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Rawi01 committed Aug 7, 2023
1 parent 000ce6d commit 519a482
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 9 deletions.
11 changes: 2 additions & 9 deletions src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethod.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2012-2022 The Project Lombok Authors.
* Copyright (C) 2012-2023 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -64,7 +64,6 @@
import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
import org.eclipse.jdt.internal.compiler.lookup.Scope;
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
import org.eclipse.jdt.internal.compiler.lookup.TypeIds;
import org.eclipse.jdt.internal.compiler.problem.ProblemReporter;
import org.eclipse.jdt.internal.core.search.matching.MethodPattern;

Expand Down Expand Up @@ -346,13 +345,7 @@ public static TypeBinding resolveType(TypeBinding resolvedType, MessageSend meth
arg.resolveType(scope);
}
if (arg.resolvedType != null) {
if (!param.isBaseType() && arg.resolvedType.isBaseType()) {
int id = arg.resolvedType.id;
arg.implicitConversion = TypeIds.BOXING | (id + (id << 4)); // magic see TypeIds
} else if (param.isBaseType() && !arg.resolvedType.isBaseType()) {
int id = parameters[i].id;
arg.implicitConversion = TypeIds.UNBOXING | (id + (id << 4)); // magic see TypeIds
}
arg.computeConversion(scope, param, arg.resolvedType);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class ExtensionMethodWidening {
public void test() {
String string = "test";
ExtensionMethodWidening.Extensions.widening(string, 1);
}


static class Extensions {
public static String widening(String string, long a) {
return string + " " + a;
}
}
}
18 changes: 18 additions & 0 deletions test/transform/resource/after-ecj/ExtensionMethodWidening.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import lombok.experimental.ExtensionMethod;
@ExtensionMethod({ExtensionMethodWidening.Extensions.class}) class ExtensionMethodWidening {
static class Extensions {
Extensions() {
super();
}
public static String widening(String string, long a) {
return ((string + " ") + a);
}
}
ExtensionMethodWidening() {
super();
}
public void test() {
String string = "test";
ExtensionMethodWidening.Extensions.widening(string, 1);
}
}
15 changes: 15 additions & 0 deletions test/transform/resource/before/ExtensionMethodWidening.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import lombok.experimental.ExtensionMethod;

@ExtensionMethod({ExtensionMethodWidening.Extensions.class})
class ExtensionMethodWidening {
public void test() {
String string = "test";
string.widening(1);
}

static class Extensions {
public static String widening(String string, long a) {
return string + " " + a;
}
}
}

0 comments on commit 519a482

Please sign in to comment.