diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java index 2f5ed68b8ec..f31c1c21ff8 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java @@ -183,8 +183,6 @@ public class CallResolver { if (calleeExpression instanceof JetConstructorCalleeExpression) { assert !context.call.getExplicitReceiver().exists(); - prioritizedTasks = Lists.newArrayList(); - JetConstructorCalleeExpression expression = (JetConstructorCalleeExpression) calleeExpression; functionReference = expression.getConstructorReferenceExpression(); if (functionReference == null) { @@ -207,10 +205,8 @@ public class CallResolver { return checkArgumentTypesAndFail(context); } Collection> candidates = TaskPrioritizer.convertWithImpliedThis(context.scope, Collections.singletonList(NO_RECEIVER), constructors); - for (ResolutionCandidate candidate : candidates) { - candidate.setSafeCall(JetPsiUtil.isSafeCall(context.call)); - } - prioritizedTasks.add(new ResolutionTask(candidates, functionReference, context)); // !! DataFlowInfo.EMPTY + prioritizedTasks = TaskPrioritizer.computePrioritizedTasksFromCandidates( + context, functionReference, candidates); } else { context.trace.report(NOT_A_CLASS.on(calleeExpression)); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/tasks/TaskPrioritizer.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/tasks/TaskPrioritizer.java index 26ace9a4d62..099d599d790 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/tasks/TaskPrioritizer.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/tasks/TaskPrioritizer.java @@ -87,32 +87,8 @@ public class TaskPrioritizer { else { scope = context.scope; } - ResolutionTaskHolder.PriorityProvider> visibleStrategy = new ResolutionTaskHolder.PriorityProvider>() { - @Override - public int getPriority(ResolutionCandidate call) { - return (isVisible(call) ? 2 : 0) + (isSynthesized(call) ? 0 : 1); - } - @Override - public int getMaxPriority() { - return 3; - } - - private boolean isVisible(ResolutionCandidate call) { - if (call == null) return false; - D candidateDescriptor = call.getDescriptor(); - if (ErrorUtils.isError(candidateDescriptor)) return true; - return Visibilities.isVisible(candidateDescriptor, context.scope.getContainingDeclaration()); - } - - private boolean isSynthesized(ResolutionCandidate call) { - D descriptor = call.getDescriptor(); - return descriptor instanceof CallableMemberDescriptor && - isOrOverridesSynthesized((CallableMemberDescriptor) descriptor); - } - }; - - ResolutionTaskHolder result = new ResolutionTaskHolder(functionReference, context, visibleStrategy); + ResolutionTaskHolder result = new ResolutionTaskHolder(functionReference, context, new MyPriorityProvider(context)); for (CallableDescriptorCollector callableDescriptorCollector : callableDescriptorCollectors) { doComputeTasks(scope, explicitReceiver, name, result, context, callableDescriptorCollector); } @@ -248,6 +224,48 @@ public class TaskPrioritizer { return false; } + public static List> computePrioritizedTasksFromCandidates( + @NotNull BasicCallResolutionContext context, + @NotNull JetReferenceExpression functionReference, + @NotNull Collection> candidates + ) { + ResolutionTaskHolder result = new ResolutionTaskHolder(functionReference, context, new MyPriorityProvider(context)); + result.addCandidates(candidates); + return result.getTasks(); + } + private TaskPrioritizer() { } + + private static class MyPriorityProvider + implements ResolutionTaskHolder.PriorityProvider> { + private final BasicCallResolutionContext context; + + public MyPriorityProvider(BasicCallResolutionContext context) { + this.context = context; + } + + @Override + public int getPriority(ResolutionCandidate call) { + return (isVisible(call) ? 2 : 0) + (isSynthesized(call) ? 0 : 1); + } + + @Override + public int getMaxPriority() { + return 3; + } + + private boolean isVisible(ResolutionCandidate call) { + if (call == null) return false; + D candidateDescriptor = call.getDescriptor(); + if (ErrorUtils.isError(candidateDescriptor)) return true; + return Visibilities.isVisible(candidateDescriptor, context.scope.getContainingDeclaration()); + } + + private boolean isSynthesized(ResolutionCandidate call) { + D descriptor = call.getDescriptor(); + return descriptor instanceof CallableMemberDescriptor && + isOrOverridesSynthesized((CallableMemberDescriptor) descriptor); + } + } } diff --git a/compiler/testData/codegen/boxWithJava/samAdapters/superconstructor.java b/compiler/testData/codegen/boxWithJava/samAdapters/superconstructor.java new file mode 100644 index 00000000000..2107dda85a7 --- /dev/null +++ b/compiler/testData/codegen/boxWithJava/samAdapters/superconstructor.java @@ -0,0 +1,5 @@ +class JavaClass { + JavaClass(Runnable r) { + if (r != null) r.run(); + } +} diff --git a/compiler/testData/codegen/boxWithJava/samAdapters/superconstructor.kt b/compiler/testData/codegen/boxWithJava/samAdapters/superconstructor.kt new file mode 100644 index 00000000000..e9ff40f394e --- /dev/null +++ b/compiler/testData/codegen/boxWithJava/samAdapters/superconstructor.kt @@ -0,0 +1,7 @@ +class KotlinClass(): JavaClass(null) { +} + +fun box(): String { + KotlinClass() + return "OK" +} diff --git a/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxWithJavaCodegenTestGenerated.java b/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxWithJavaCodegenTestGenerated.java index bafedfe8c53..d6e6f8b39bf 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxWithJavaCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxWithJavaCodegenTestGenerated.java @@ -205,6 +205,11 @@ public class BlackBoxWithJavaCodegenTestGenerated extends AbstractBlackBoxCodege doTestWithJava("compiler/testData/codegen/boxWithJava/samAdapters/simplest.kt"); } + @TestMetadata("superconstructor.kt") + public void testSuperconstructor() throws Exception { + doTestWithJava("compiler/testData/codegen/boxWithJava/samAdapters/superconstructor.kt"); + } + @TestMetadata("typeParameterOfClass.kt") public void testTypeParameterOfClass() throws Exception { doTestWithJava("compiler/testData/codegen/boxWithJava/samAdapters/typeParameterOfClass.kt");