diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java b/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java index f21eeeaf4b8..c84da438691 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java @@ -413,10 +413,16 @@ public abstract class StackValue { put(type, v); } else if (depth == 1) { - if (this.type.getSize() != 1) { + int size = this.type.getSize(); + if (size == 1) { + v.swap(); + } else if (size == 2) { + v.dupX2(); + v.pop(); + } else { throw new UnsupportedOperationException("don't know how to move type " + type + " to top of stack"); } - v.swap(); + coerceTo(type, v); } else { diff --git a/compiler/testData/codegen/box/safeCall/safeCallOnLong.kt b/compiler/testData/codegen/box/safeCall/safeCallOnLong.kt new file mode 100644 index 00000000000..9937adc2991 --- /dev/null +++ b/compiler/testData/codegen/box/safeCall/safeCallOnLong.kt @@ -0,0 +1,6 @@ +fun f(b : Long.(Long)->Long) = 1L?.b(2L) + +fun box(): String { + val x = f { this + it } + return if (x == 3L) "OK" else "fail $x" +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxCodegenTestGenerated.java index 9f10abe65cd..9daa9b6e477 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxCodegenTestGenerated.java @@ -5808,6 +5808,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } + @TestMetadata("safeCallOnLong.kt") + public void testSafeCallOnLong() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/safeCall/safeCallOnLong.kt"); + doTest(fileName); + } + @TestMetadata("staticCall.kt") public void testStaticCall() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/safeCall/staticCall.kt");