KT-7587 Overloads are not generated during partial compilation of package
#KT-7587 fixed
This commit is contained in:
+1
-1
@@ -70,7 +70,7 @@ public class DefaultParameterValueSubstitutor(val state: GenerationState) {
|
||||
* implementation in the companion object class)
|
||||
* @return true if the overloads annotation was found on the element, false otherwise
|
||||
*/
|
||||
fun generateOverloadsIfNeeded(methodElement: JetElement,
|
||||
fun generateOverloadsIfNeeded(methodElement: JetElement?,
|
||||
functionDescriptor: FunctionDescriptor,
|
||||
delegateFunctionDescriptor: FunctionDescriptor,
|
||||
owner: CodegenContext<*>,
|
||||
|
||||
@@ -118,8 +118,11 @@ public class FunctionCodegen {
|
||||
generateOverloadsWithDefaultValues(function, functionDescriptor, functionDescriptor);
|
||||
}
|
||||
|
||||
public void generateOverloadsWithDefaultValues(@NotNull JetNamedFunction function,
|
||||
FunctionDescriptor functionDescriptor, FunctionDescriptor delegateFunctionDescriptor) {
|
||||
public void generateOverloadsWithDefaultValues(
|
||||
@Nullable JetNamedFunction function,
|
||||
@NotNull FunctionDescriptor functionDescriptor,
|
||||
@NotNull FunctionDescriptor delegateFunctionDescriptor
|
||||
) {
|
||||
new DefaultParameterValueSubstitutor(state).generateOverloadsIfNeeded(function,
|
||||
functionDescriptor,
|
||||
delegateFunctionDescriptor,
|
||||
@@ -303,7 +306,11 @@ public class FunctionCodegen {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static Type getThisTypeForFunction(@NotNull FunctionDescriptor functionDescriptor, @NotNull MethodContext context, @NotNull JetTypeMapper typeMapper) {
|
||||
private static Type getThisTypeForFunction(
|
||||
@NotNull FunctionDescriptor functionDescriptor,
|
||||
@NotNull MethodContext context,
|
||||
@NotNull JetTypeMapper typeMapper
|
||||
) {
|
||||
ReceiverParameterDescriptor dispatchReceiver = functionDescriptor.getDispatchReceiverParameter();
|
||||
if (functionDescriptor instanceof ConstructorDescriptor) {
|
||||
return typeMapper.mapType(functionDescriptor);
|
||||
@@ -382,14 +389,15 @@ public class FunctionCodegen {
|
||||
//add this
|
||||
if (thisType != null) {
|
||||
mv.visitLocalVariable("this", thisType.getDescriptor(), null, methodBegin, methodEnd, shift);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
//TODO: provide thisType for callable reference
|
||||
}
|
||||
shift++;
|
||||
}
|
||||
|
||||
for (int i = 0; i < params.size(); i++) {
|
||||
JvmMethodParameterSignature param = params.get(i);
|
||||
JvmMethodParameterSignature param = params.get(i);
|
||||
JvmMethodParameterKind kind = param.getKind();
|
||||
String parameterName;
|
||||
|
||||
@@ -749,7 +757,8 @@ public class FunctionCodegen {
|
||||
) {
|
||||
int flags = ACC_PUBLIC | ACC_BRIDGE | ACC_SYNTHETIC; // TODO.
|
||||
|
||||
MethodVisitor mv = v.newMethod(DiagnosticsPackage.Bridge(descriptor, origin), flags, delegateTo.getName(), bridge.getDescriptor(), null, null);
|
||||
MethodVisitor mv =
|
||||
v.newMethod(DiagnosticsPackage.Bridge(descriptor, origin), flags, delegateTo.getName(), bridge.getDescriptor(), null, null);
|
||||
if (state.getClassBuilderMode() != ClassBuilderMode.FULL) return;
|
||||
|
||||
mv.visitCode();
|
||||
@@ -776,7 +785,8 @@ public class FunctionCodegen {
|
||||
}
|
||||
|
||||
public void genDelegate(@NotNull FunctionDescriptor functionDescriptor, FunctionDescriptor overriddenDescriptor, StackValue field) {
|
||||
genDelegate(functionDescriptor, overriddenDescriptor.getOriginal(), (ClassDescriptor) overriddenDescriptor.getContainingDeclaration(), field);
|
||||
genDelegate(functionDescriptor, overriddenDescriptor.getOriginal(),
|
||||
(ClassDescriptor) overriddenDescriptor.getContainingDeclaration(), field);
|
||||
}
|
||||
|
||||
public void genDelegate(
|
||||
|
||||
@@ -190,6 +190,8 @@ public class PackageCodegen {
|
||||
memberCodegen.functionCodegen.generateDefaultIfNeeded(
|
||||
context.intoFunction(function), function, OwnerKind.PACKAGE, DefaultParameterValueLoader.DEFAULT, null
|
||||
);
|
||||
|
||||
memberCodegen.functionCodegen.generateOverloadsWithDefaultValues(null, function, function);
|
||||
}
|
||||
else if (member instanceof DeserializedPropertyDescriptor) {
|
||||
memberCodegen.propertyCodegen.generateInPackageFacade((DeserializedPropertyDescriptor) member);
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
public final class C {
|
||||
@kotlin.jvm.overloads
|
||||
@org.jetbrains.annotations.NotNull
|
||||
public final java.lang.String foo(@org.jetbrains.annotations.NotNull java.lang.String o, @org.jetbrains.annotations.NotNull java.lang.String s1, @org.jetbrains.annotations.NotNull java.lang.String k, @org.jetbrains.annotations.Nullable java.lang.String s2) { /* compiled code */ }
|
||||
|
||||
@kotlin.jvm.overloads
|
||||
@org.jetbrains.annotations.NotNull
|
||||
public java.lang.String foo(@org.jetbrains.annotations.NotNull java.lang.String p, @org.jetbrains.annotations.NotNull java.lang.String p1, @org.jetbrains.annotations.Nullable java.lang.String p2) { /* compiled code */ }
|
||||
|
||||
@kotlin.jvm.overloads
|
||||
@org.jetbrains.annotations.NotNull
|
||||
public java.lang.String foo(@org.jetbrains.annotations.NotNull java.lang.String p, @org.jetbrains.annotations.Nullable java.lang.String p1) { /* compiled code */ }
|
||||
|
||||
|
||||
@@ -299,6 +299,12 @@ public class IncrementalJpsTestGenerated extends AbstractIncrementalJpsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("optionalParameter")
|
||||
public void testOptionalParameter() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("jps-plugin/testData/incremental/pureKotlin/optionalParameter/");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("ourClassReferenced")
|
||||
public void testOurClassReferenced() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("jps-plugin/testData/incremental/pureKotlin/ourClassReferenced/");
|
||||
@@ -552,6 +558,12 @@ public class IncrementalJpsTestGenerated extends AbstractIncrementalJpsTest {
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class KotlinUsedInJava extends AbstractIncrementalJpsTest {
|
||||
@TestMetadata("addOptionalParameter")
|
||||
public void testAddOptionalParameter() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("jps-plugin/testData/incremental/withJava/kotlinUsedInJava/addOptionalParameter/");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInKotlinUsedInJava() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("jps-plugin/testData/incremental/withJava/kotlinUsedInJava"), Pattern.compile("^([^\\.]+)$"), true);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
Cleaning output files:
|
||||
out/production/module/test/TestPackage$other$*.class
|
||||
out/production/module/test/TestPackage.class
|
||||
End of files
|
||||
Compiling files:
|
||||
src/other.kt
|
||||
End of files
|
||||
@@ -0,0 +1,6 @@
|
||||
package test
|
||||
|
||||
kotlin.jvm.overloads
|
||||
fun f(a: String, b: Int = 5) {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package test
|
||||
|
||||
fun other() {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package test
|
||||
|
||||
fun other() {
|
||||
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
class JavaUsage {
|
||||
public static void main(String[] args) {
|
||||
test.TestPackage.f("x");
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
Cleaning output files:
|
||||
out/production/module/test/TestPackage$fun$*.class
|
||||
out/production/module/test/TestPackage.class
|
||||
End of files
|
||||
Compiling files:
|
||||
src/fun.kt
|
||||
End of files
|
||||
Cleaning output files:
|
||||
out/production/module/JavaUsage.class
|
||||
out/production/module/test/TestPackage$other$*.class
|
||||
out/production/module/test/TestPackage.class
|
||||
End of files
|
||||
Compiling files:
|
||||
src/other.kt
|
||||
End of files
|
||||
Compiling files:
|
||||
src/JavaUsage.java
|
||||
End of files
|
||||
@@ -0,0 +1,5 @@
|
||||
package test
|
||||
|
||||
fun f(a: String) {
|
||||
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
package test
|
||||
|
||||
kotlin.jvm.overloads
|
||||
fun f(a: String, b: Int = 5) {
|
||||
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package test
|
||||
|
||||
fun other() {
|
||||
|
||||
}
|
||||
@@ -25,5 +25,5 @@ import java.lang.annotation.RetentionPolicy
|
||||
* If a method has N parameters and M of which have default values, M overloads are generated: the first one
|
||||
* takes N-1 parameters (all but the last one that takes a default value), the second takes N-2 parameters, and so on.
|
||||
*/
|
||||
Retention(RetentionPolicy.SOURCE)
|
||||
Retention(RetentionPolicy.CLASS)
|
||||
public annotation class overloads
|
||||
|
||||
Reference in New Issue
Block a user