KT-1406 wrong generation of receiver for ext.fun called inside closure

This commit is contained in:
Alex Tkachman
2012-02-24 16:24:16 +02:00
parent 17d34e9d49
commit 6146ec4268
4 changed files with 36 additions and 1 deletions
@@ -1246,11 +1246,11 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
if(resolvedCall == null) {
throw new CompilationException("Cannot resolve: " + callee.getText(), null, expression);
}
receiver = StackValue.receiver(resolvedCall, receiver, this, null);
DeclarationDescriptor funDescriptor = resolvedCall.getResultingDescriptor();
if (funDescriptor instanceof ConstructorDescriptor) {
receiver = StackValue.receiver(resolvedCall, receiver, this, null);
return generateConstructorCall(expression, (JetSimpleNameExpression) callee, receiver);
}
else if (funDescriptor instanceof FunctionDescriptor) {
@@ -1295,6 +1295,10 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
return returnValueAsStackValue((FunctionDescriptor) fd, callReturnType);
}
else {
ResolvedCall<? extends CallableDescriptor> resolvedCall = bindingContext.get(BindingContext.RESOLVED_CALL, expression.getCalleeExpression());
assert resolvedCall != null;
receiver = StackValue.receiver(resolvedCall, receiver, this, null);
IntrinsicMethod intrinsic = (IntrinsicMethod) callable;
List<JetExpression> args = new ArrayList<JetExpression>();
for (ValueArgument argument : expression.getValueArguments()) {
@@ -0,0 +1,26 @@
package pack
import java.util.Collection
import java.util.ArrayList
import java.util.regex.Pattern
class C{
public fun foo(){
val items : Collection<Item> = java.util.Collections.singleton(Item()).sure()
val result = ArrayList<Item>()
val pattern: Pattern? = Pattern.compile("...")
items.filterTo(result) {
pattern.sure().matcher(it.name()).sure().matches()
}
}
private fun Item.name() : String = ""
}
class Item{
}
fun box() : String {
C().foo()
return "OK"
}
@@ -199,6 +199,7 @@ public class PropertyGenTest extends CodegenTestCase {
}
public void testKt1170() throws Exception {
createEnvironmentWithFullJdk();
blackBoxFile("regressions/kt1170.kt");
}
@@ -116,4 +116,8 @@ public class StdlibTest extends CodegenTestCase {
throw t instanceof Exception ? (Exception)t : new RuntimeException(t);
}
}
public void testKt1406() throws Exception {
blackBoxFile("regressions/kt1406.kt");
}
}