KT-1865 Calls with default argument values are generated incorrectly
#KT-1865 Fixed
This commit is contained in:
@@ -125,4 +125,8 @@ public final class MiscTest extends AbstractExpressionTest {
|
|||||||
public void testExtensionLiteralCalledInsideExtensionFunction() throws Exception {
|
public void testExtensionLiteralCalledInsideExtensionFunction() throws Exception {
|
||||||
checkFooBoxIsTrue("extensionLiteralCalledInsideExtensionFunction.kt");
|
checkFooBoxIsTrue("extensionLiteralCalledInsideExtensionFunction.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testKt1865() throws Exception {
|
||||||
|
checkFooBoxIsTrue("KT-1865.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -57,7 +57,7 @@ public abstract class AbstractCallExpressionTranslator extends AbstractTranslato
|
|||||||
this.expression = expression;
|
this.expression = expression;
|
||||||
this.resolvedCall = getResolvedCallForCallExpression(bindingContext(), expression);
|
this.resolvedCall = getResolvedCallForCallExpression(bindingContext(), expression);
|
||||||
this.receiver = receiver;
|
this.receiver = receiver;
|
||||||
callType = type;
|
this.callType = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract public boolean shouldWrapVarargInArray();
|
abstract public boolean shouldWrapVarargInArray();
|
||||||
|
|||||||
@@ -268,13 +268,23 @@ public final class BindingUtils {
|
|||||||
@NotNull
|
@NotNull
|
||||||
public static JetExpression getDefaultArgument(@NotNull BindingContext context,
|
public static JetExpression getDefaultArgument(@NotNull BindingContext context,
|
||||||
@NotNull ValueParameterDescriptor parameterDescriptor) {
|
@NotNull ValueParameterDescriptor parameterDescriptor) {
|
||||||
assert parameterDescriptor.hasDefaultValue() : "Unsupplied parameter must have default value.";
|
ValueParameterDescriptor descriptorWhichDeclaresDefaultValue = getOriginalDescriptorWhichDeclaresDefaultValue(parameterDescriptor);
|
||||||
JetParameter psiParameter = getParameterForDescriptor(context, parameterDescriptor);
|
JetParameter psiParameter = getParameterForDescriptor(context, descriptorWhichDeclaresDefaultValue);
|
||||||
JetExpression defaultValue = psiParameter.getDefaultValue();
|
JetExpression defaultValue = psiParameter.getDefaultValue();
|
||||||
assert defaultValue != null : "No default value found in PSI.";
|
assert defaultValue != null : "No default value found in PSI.";
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static ValueParameterDescriptor getOriginalDescriptorWhichDeclaresDefaultValue(
|
||||||
|
@NotNull ValueParameterDescriptor parameterDescriptor) {
|
||||||
|
ValueParameterDescriptor result = parameterDescriptor;
|
||||||
|
assert result.hasDefaultValue() : "Unsupplied parameter must have default value.";
|
||||||
|
while (!result.declaresDefaultValue()) {
|
||||||
|
result = result.getOverriddenDescriptors().iterator().next();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static FunctionDescriptor getIteratorFunction(@NotNull BindingContext context,
|
public static FunctionDescriptor getIteratorFunction(@NotNull BindingContext context,
|
||||||
@NotNull JetExpression rangeExpression) {
|
@NotNull JetExpression rangeExpression) {
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package foo
|
||||||
|
|
||||||
|
open class A {
|
||||||
|
open fun foo(a : Int = 1) = a
|
||||||
|
}
|
||||||
|
|
||||||
|
class B : A() {
|
||||||
|
override fun foo(a : Int) = a + 1
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box() = (B().foo() == 2)
|
||||||
Reference in New Issue
Block a user