From 56eabfe07b0e4fc8c92ab10f3f502e8a94de6f5d Mon Sep 17 00:00:00 2001 From: Alex Tkachman Date: Sat, 17 Mar 2012 13:57:45 +0200 Subject: [PATCH] KT-1508 jet.Number -> j.l.Number --- .../src/org/jetbrains/jet/codegen/JetTypeMapper.java | 5 +---- .../jetbrains/jet/lang/types/lang/JetStandardLibrary.java | 7 +++++++ compiler/testData/codegen/regressions/kt1508.kt | 6 ++++++ .../org/jetbrains/jet/codegen/PrimitiveTypesTest.java | 4 ++++ 4 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 compiler/testData/codegen/regressions/kt1508.kt diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java b/compiler/backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java index cb0e114e16c..2c9b0086363 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java @@ -779,6 +779,7 @@ public class JetTypeMapper { knowTypes.put(standardLibrary.getNullablePrimitiveJetType(primitiveType), jvmPrimitiveType.getWrapper().getAsmType()); } + knowTypes.put(standardLibrary.getNumberType(),JL_NUMBER_TYPE); knowTypes.put(standardLibrary.getStringType(),JL_STRING_TYPE); knowTypes.put(standardLibrary.getNullableStringType(),JL_STRING_TYPE); knowTypes.put(standardLibrary.getCharSequenceType(),JL_CHAR_SEQUENCE_TYPE); @@ -798,10 +799,6 @@ public class JetTypeMapper { || className.getFqName().equals("java.lang.String") || className.getFqName().equals("java.lang.Object"); } - public String isKnownTypeInfo(JetType jetType) { - return knowTypeNames.get(jetType); - } - public boolean isGenericsArray(JetType type) { DeclarationDescriptor declarationDescriptor = type.getConstructor().getDeclarationDescriptor(); if(declarationDescriptor instanceof TypeParameterDescriptor) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/JetStandardLibrary.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/JetStandardLibrary.java index 5dde1648790..d2ab90412da 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/JetStandardLibrary.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/JetStandardLibrary.java @@ -96,6 +96,7 @@ public class JetStandardLibrary { private ClassDescriptor volatileClass; private ClassDescriptor throwableClass; + private JetType numberType; private JetType stringType; private JetType volatileType; private JetType nullableStringType; @@ -161,6 +162,7 @@ public class JetStandardLibrary { private void initStdClasses() { if(libraryScope == null) { this.libraryScope = JetStandardClasses.STANDARD_CLASSES_NAMESPACE.getMemberScope(); + this.numberClass = (ClassDescriptor) libraryScope.getClassifier("Number"); this.stringClass = (ClassDescriptor) libraryScope.getClassifier("String"); this.charSequenceClass = (ClassDescriptor) libraryScope.getClassifier("CharSequence"); @@ -172,6 +174,7 @@ public class JetStandardLibrary { this.comparableClass = (ClassDescriptor) libraryScope.getClassifier("Comparable"); this.typeInfoFunction = libraryScope.getFunctions("typeinfo"); + this.numberType = new JetTypeImpl(getNumber()); this.stringType = new JetTypeImpl(getString()); this.charSequenceType = new JetTypeImpl(getCharSequence()); this.nullableCharSequenceType = TypeUtils.makeNullable(charSequenceType); @@ -513,4 +516,8 @@ public class JetStandardLibrary { public JetType getTuple0Type() { return tuple0Type; } + + public JetType getNumberType() { + return numberType; + } } diff --git a/compiler/testData/codegen/regressions/kt1508.kt b/compiler/testData/codegen/regressions/kt1508.kt new file mode 100644 index 00000000000..9e52c4a7e9f --- /dev/null +++ b/compiler/testData/codegen/regressions/kt1508.kt @@ -0,0 +1,6 @@ +fun test( n : Number ) = n.toInt().toLong() + n.toLong() + +fun box() : String { + val n : Number = 10 + return if(test(n) == 20.toLong()) "OK" else "fail" +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/codegen/PrimitiveTypesTest.java b/compiler/tests/org/jetbrains/jet/codegen/PrimitiveTypesTest.java index b1ef3670c39..37fe4d052ba 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/PrimitiveTypesTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/PrimitiveTypesTest.java @@ -419,4 +419,8 @@ public class PrimitiveTypesTest extends CodegenTestCase { public void testKt1093 () { blackBoxFile("regressions/kt1093.kt"); } + + public void testKt1508 () { + blackBoxFile("regressions/kt1508.kt"); + } }