From 935024db4ec834ab93bde3fa9251ba5783c166aa Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Wed, 14 Oct 2015 22:48:43 +0300 Subject: [PATCH] Fix with hack bridge codegen for indexOf and lastIndexOf methods. More sophisticated solution is required. --- .../src/org/jetbrains/kotlin/codegen/FunctionCodegen.java | 6 +++++- libraries/stdlib/test/collections/CollectionBehaviors.kt | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java index f5d63e78780..f93656c9125 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java @@ -887,7 +887,11 @@ public class FunctionCodegen { iv.ifne(afterBarrier); - StackValue.none().put(bridge.getReturnType(), iv); + String shortName = getFqName(descriptor).shortName().asString(); + StackValue returnValue = + ("indexOf".equals(shortName) || "lastIndexOf".equals(shortName)) ? StackValue.constant(-1, Type.INT_TYPE) : StackValue.none(); + + returnValue.put(bridge.getReturnType(), iv); iv.areturn(bridge.getReturnType()); iv.visitLabel(afterBarrier); diff --git a/libraries/stdlib/test/collections/CollectionBehaviors.kt b/libraries/stdlib/test/collections/CollectionBehaviors.kt index 7f83aaf8b4a..432c03eaf6e 100644 --- a/libraries/stdlib/test/collections/CollectionBehaviors.kt +++ b/libraries/stdlib/test/collections/CollectionBehaviors.kt @@ -32,8 +32,8 @@ public fun CompareContext>.listBehavior() { propertyFails { this[size()] } - propertyEquals { indexOf(elementAtOrNull(0)) } - propertyEquals { lastIndexOf(elementAtOrNull(0)) } + propertyEquals { (this as List).indexOf(elementAtOrNull(0)) } + propertyEquals { (this as List).lastIndexOf(elementAtOrNull(0)) } propertyFails { subList(0, size() + 1)} propertyFails { subList(-1, 0)}