KT-1441 proper identityEquals
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.codegen.intrinsics;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
||||
import org.jetbrains.jet.codegen.GenerationState;
|
||||
import org.jetbrains.jet.codegen.JetTypeMapper;
|
||||
import org.jetbrains.jet.codegen.StackValue;
|
||||
import org.jetbrains.jet.lang.psi.JetCallExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.commons.InstructionAdapter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author alex.tkachman
|
||||
*/
|
||||
public class IdentityEquals implements IntrinsicMethod {
|
||||
@Override
|
||||
public StackValue generate(ExpressionCodegen codegen, InstructionAdapter v, Type expectedType, PsiElement element, List<JetExpression> arguments, StackValue receiver, @NotNull GenerationState state) {
|
||||
receiver.put(JetTypeMapper.TYPE_OBJECT, v);
|
||||
codegen.gen(arguments.get(0)).put(JetTypeMapper.TYPE_OBJECT, v);
|
||||
return StackValue.cmp(JetTokens.EQEQEQ, JetTypeMapper.TYPE_OBJECT);
|
||||
}
|
||||
}
|
||||
@@ -59,6 +59,7 @@ public class IntrinsicMethods {
|
||||
public static final IntrinsicMethod ARRAY_SIZE = new ArraySize();
|
||||
public static final IntrinsicMethod ARRAY_INDICES = new ArrayIndices();
|
||||
public static final Equals EQUALS = new Equals();
|
||||
public static final IdentityEquals IDENTITY_EQUALS = new IdentityEquals();
|
||||
public static final IteratorNext ITERATOR_NEXT = new IteratorNext();
|
||||
public static final ArraySet ARRAY_SET = new ArraySet();
|
||||
public static final ArrayGet ARRAY_GET = new ArrayGet();
|
||||
@@ -129,7 +130,7 @@ public class IntrinsicMethods {
|
||||
|
||||
declareOverload(myStdLib.getLibraryScope().getFunctions("toString"), 0, new ToString());
|
||||
declareOverload(myStdLib.getLibraryScope().getFunctions("equals"), 1, EQUALS);
|
||||
declareOverload(myStdLib.getLibraryScope().getFunctions("identityEquals"), 1, EQUALS);
|
||||
declareOverload(myStdLib.getLibraryScope().getFunctions("identityEquals"), 1, IDENTITY_EQUALS);
|
||||
declareOverload(myStdLib.getLibraryScope().getFunctions("plus"), 1, STRING_PLUS);
|
||||
declareOverload(myStdLib.getLibraryScope().getFunctions("Array"), 1, new NewArray());
|
||||
declareOverload(myStdLib.getLibraryScope().getFunctions("sure"), 0, new Sure());
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
class Foo {
|
||||
var rnd = 10
|
||||
|
||||
public fun equals(that : Any) : Boolean = that is Foo && (that.rnd == rnd)
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
val a = Foo()
|
||||
val b = Foo()
|
||||
if (!a.identityEquals(a)) return "fail 1"
|
||||
if (!b.identityEquals(b)) return "fail 2"
|
||||
if (b.identityEquals(a)) return "fail 3"
|
||||
if (a.identityEquals(b)) return "fail 4"
|
||||
if( a !=b ) return "fail5"
|
||||
return "OK"
|
||||
}
|
||||
@@ -290,4 +290,8 @@ public class ControlStructuresTest extends CodegenTestCase {
|
||||
public void testKt628() throws Exception {
|
||||
blackBoxFile("regressions/kt628.kt");
|
||||
}
|
||||
|
||||
public void testKt1441() throws Exception {
|
||||
blackBoxFile("regressions/kt1441.kt");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user