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)
|
* implementation in the companion object class)
|
||||||
* @return true if the overloads annotation was found on the element, false otherwise
|
* @return true if the overloads annotation was found on the element, false otherwise
|
||||||
*/
|
*/
|
||||||
fun generateOverloadsIfNeeded(methodElement: JetElement,
|
fun generateOverloadsIfNeeded(methodElement: JetElement?,
|
||||||
functionDescriptor: FunctionDescriptor,
|
functionDescriptor: FunctionDescriptor,
|
||||||
delegateFunctionDescriptor: FunctionDescriptor,
|
delegateFunctionDescriptor: FunctionDescriptor,
|
||||||
owner: CodegenContext<*>,
|
owner: CodegenContext<*>,
|
||||||
|
|||||||
@@ -118,8 +118,11 @@ public class FunctionCodegen {
|
|||||||
generateOverloadsWithDefaultValues(function, functionDescriptor, functionDescriptor);
|
generateOverloadsWithDefaultValues(function, functionDescriptor, functionDescriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void generateOverloadsWithDefaultValues(@NotNull JetNamedFunction function,
|
public void generateOverloadsWithDefaultValues(
|
||||||
FunctionDescriptor functionDescriptor, FunctionDescriptor delegateFunctionDescriptor) {
|
@Nullable JetNamedFunction function,
|
||||||
|
@NotNull FunctionDescriptor functionDescriptor,
|
||||||
|
@NotNull FunctionDescriptor delegateFunctionDescriptor
|
||||||
|
) {
|
||||||
new DefaultParameterValueSubstitutor(state).generateOverloadsIfNeeded(function,
|
new DefaultParameterValueSubstitutor(state).generateOverloadsIfNeeded(function,
|
||||||
functionDescriptor,
|
functionDescriptor,
|
||||||
delegateFunctionDescriptor,
|
delegateFunctionDescriptor,
|
||||||
@@ -303,7 +306,11 @@ public class FunctionCodegen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@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();
|
ReceiverParameterDescriptor dispatchReceiver = functionDescriptor.getDispatchReceiverParameter();
|
||||||
if (functionDescriptor instanceof ConstructorDescriptor) {
|
if (functionDescriptor instanceof ConstructorDescriptor) {
|
||||||
return typeMapper.mapType(functionDescriptor);
|
return typeMapper.mapType(functionDescriptor);
|
||||||
@@ -382,14 +389,15 @@ public class FunctionCodegen {
|
|||||||
//add this
|
//add this
|
||||||
if (thisType != null) {
|
if (thisType != null) {
|
||||||
mv.visitLocalVariable("this", thisType.getDescriptor(), null, methodBegin, methodEnd, shift);
|
mv.visitLocalVariable("this", thisType.getDescriptor(), null, methodBegin, methodEnd, shift);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
//TODO: provide thisType for callable reference
|
//TODO: provide thisType for callable reference
|
||||||
}
|
}
|
||||||
shift++;
|
shift++;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < params.size(); i++) {
|
for (int i = 0; i < params.size(); i++) {
|
||||||
JvmMethodParameterSignature param = params.get(i);
|
JvmMethodParameterSignature param = params.get(i);
|
||||||
JvmMethodParameterKind kind = param.getKind();
|
JvmMethodParameterKind kind = param.getKind();
|
||||||
String parameterName;
|
String parameterName;
|
||||||
|
|
||||||
@@ -749,7 +757,8 @@ public class FunctionCodegen {
|
|||||||
) {
|
) {
|
||||||
int flags = ACC_PUBLIC | ACC_BRIDGE | ACC_SYNTHETIC; // TODO.
|
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;
|
if (state.getClassBuilderMode() != ClassBuilderMode.FULL) return;
|
||||||
|
|
||||||
mv.visitCode();
|
mv.visitCode();
|
||||||
@@ -776,7 +785,8 @@ public class FunctionCodegen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void genDelegate(@NotNull FunctionDescriptor functionDescriptor, FunctionDescriptor overriddenDescriptor, StackValue field) {
|
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(
|
public void genDelegate(
|
||||||
|
|||||||
@@ -190,6 +190,8 @@ public class PackageCodegen {
|
|||||||
memberCodegen.functionCodegen.generateDefaultIfNeeded(
|
memberCodegen.functionCodegen.generateDefaultIfNeeded(
|
||||||
context.intoFunction(function), function, OwnerKind.PACKAGE, DefaultParameterValueLoader.DEFAULT, null
|
context.intoFunction(function), function, OwnerKind.PACKAGE, DefaultParameterValueLoader.DEFAULT, null
|
||||||
);
|
);
|
||||||
|
|
||||||
|
memberCodegen.functionCodegen.generateOverloadsWithDefaultValues(null, function, function);
|
||||||
}
|
}
|
||||||
else if (member instanceof DeserializedPropertyDescriptor) {
|
else if (member instanceof DeserializedPropertyDescriptor) {
|
||||||
memberCodegen.propertyCodegen.generateInPackageFacade((DeserializedPropertyDescriptor) member);
|
memberCodegen.propertyCodegen.generateInPackageFacade((DeserializedPropertyDescriptor) member);
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
public final class C {
|
public final class C {
|
||||||
|
@kotlin.jvm.overloads
|
||||||
@org.jetbrains.annotations.NotNull
|
@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 */ }
|
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
|
@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 */ }
|
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
|
@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 */ }
|
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);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("optionalParameter")
|
||||||
|
public void testOptionalParameter() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("jps-plugin/testData/incremental/pureKotlin/optionalParameter/");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("ourClassReferenced")
|
@TestMetadata("ourClassReferenced")
|
||||||
public void testOurClassReferenced() throws Exception {
|
public void testOurClassReferenced() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("jps-plugin/testData/incremental/pureKotlin/ourClassReferenced/");
|
String fileName = JetTestUtils.navigationMetadata("jps-plugin/testData/incremental/pureKotlin/ourClassReferenced/");
|
||||||
@@ -552,6 +558,12 @@ public class IncrementalJpsTestGenerated extends AbstractIncrementalJpsTest {
|
|||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
public static class KotlinUsedInJava extends AbstractIncrementalJpsTest {
|
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 {
|
public void testAllFilesPresentInKotlinUsedInJava() throws Exception {
|
||||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("jps-plugin/testData/incremental/withJava/kotlinUsedInJava"), Pattern.compile("^([^\\.]+)$"), true);
|
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
|
* 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.
|
* 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
|
public annotation class overloads
|
||||||
|
|||||||
Reference in New Issue
Block a user