Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KT-2269 fix: hashCode & equals for primitives
- Loading branch information
1 parent
bcec8b7
commit 301b557
Showing
4 changed files
with
70 additions
and
3 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/HashCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* 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.annotations.Nullable; | ||
import org.jetbrains.asm4.Opcodes; | ||
import org.jetbrains.asm4.Type; | ||
import org.jetbrains.asm4.commons.InstructionAdapter; | ||
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.JetExpression; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* @author alex.tkachman | ||
*/ | ||
public class HashCode implements IntrinsicMethod { | ||
@Override | ||
public StackValue generate(ExpressionCodegen codegen, | ||
InstructionAdapter v, | ||
@NotNull Type expectedType, | ||
@Nullable PsiElement element, | ||
@Nullable List<JetExpression> arguments, | ||
StackValue receiver, | ||
@NotNull GenerationState state) { | ||
receiver.put(JetTypeMapper.TYPE_OBJECT, v); | ||
v.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Object", "hashCode", "()I"); | ||
return StackValue.onStack(Type.INT_TYPE); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
fun box() : String { | ||
230?.toByte()?.hashCode() | ||
9.hashCode() | ||
|
||
if(230.equals(9.toByte())) { | ||
return "fail" | ||
} | ||
|
||
if(230 == 9.toByte().toInt()) { | ||
return "fail" | ||
} | ||
return "OK" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters