From f1c4ab7188aa4be6f275d592bf9d6a46b0eb4dc7 Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Fri, 31 Aug 2012 12:28:48 +0400 Subject: [PATCH] Fix for RangeTo intrinsic for the case of LongRange --- .../jet/codegen/intrinsics/RangeTo.java | 2 +- .../intrinsics/longRangeWithExplicitDot.kt | 6 ++ .../codegen/AbstractIntrinsicsTestCase.java | 56 +++++++++++++++++++ .../jet/codegen/IntrinsicsTestGenerated.java | 40 +++++++++++++ 4 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/codegen/intrinsics/longRangeWithExplicitDot.kt create mode 100644 compiler/tests/org/jetbrains/jet/codegen/AbstractIntrinsicsTestCase.java create mode 100644 compiler/tests/org/jetbrains/jet/codegen/IntrinsicsTestGenerated.java diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/RangeTo.java b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/RangeTo.java index fd6a5ea838b..8a432e28e02 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/RangeTo.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/RangeTo.java @@ -50,7 +50,7 @@ public class RangeTo implements IntrinsicMethod { if (arguments.size() == 1) { final Type leftType = receiver.type; final Type rightType = codegen.expressionType(arguments.get(0)); - receiver.put(Type.INT_TYPE, v); + receiver.put(leftType, v); codegen.gen(arguments.get(0), rightType); v.invokestatic("jet/runtime/Ranges", "rangeTo", "(" + receiver.type.getDescriptor() + leftType.getDescriptor() + ")" + expectedType.getDescriptor()); diff --git a/compiler/testData/codegen/intrinsics/longRangeWithExplicitDot.kt b/compiler/testData/codegen/intrinsics/longRangeWithExplicitDot.kt new file mode 100644 index 00000000000..5663f07ec66 --- /dev/null +++ b/compiler/testData/codegen/intrinsics/longRangeWithExplicitDot.kt @@ -0,0 +1,6 @@ +fun box(): String { + val l: Long = 1 + val l2: Long = 2 + val r = l.rangeTo(l2) + return if (r.start == l && r.end == l2) "OK" else "fail" +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/codegen/AbstractIntrinsicsTestCase.java b/compiler/tests/org/jetbrains/jet/codegen/AbstractIntrinsicsTestCase.java new file mode 100644 index 00000000000..6d37281e78b --- /dev/null +++ b/compiler/tests/org/jetbrains/jet/codegen/AbstractIntrinsicsTestCase.java @@ -0,0 +1,56 @@ +/* + * 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; + +import org.jetbrains.jet.test.generator.SimpleTestClassModel; +import org.jetbrains.jet.test.generator.TestGenerator; + +import java.io.File; +import java.io.IOException; +import java.util.Arrays; + +/** + * @author svtk + */ +public abstract class AbstractIntrinsicsTestCase extends CodegenTestCase { + @Override + protected String getPrefix() { + return "intrinsic"; + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + createEnvironmentWithMockJdkAndIdeaAnnotations(); + } + + public static void main(String[] args) throws IOException { + Class thisClass = AbstractIntrinsicsTestCase.class; + String aPackage = thisClass.getPackage().getName(); + new TestGenerator( + "compiler/tests/", + aPackage, + "IntrinsicsTestGenerated", + thisClass, + Arrays.asList( + new SimpleTestClassModel(new File("compiler/testData/codegen/intrinsics"), true, "kt", "blackBoxFileByFullPath") + ), + thisClass + ).generateAndSave(); + + } +} diff --git a/compiler/tests/org/jetbrains/jet/codegen/IntrinsicsTestGenerated.java b/compiler/tests/org/jetbrains/jet/codegen/IntrinsicsTestGenerated.java new file mode 100644 index 00000000000..dfafb42c92c --- /dev/null +++ b/compiler/tests/org/jetbrains/jet/codegen/IntrinsicsTestGenerated.java @@ -0,0 +1,40 @@ +/* + * 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; + +import junit.framework.Assert; +import junit.framework.Test; +import junit.framework.TestSuite; + +import java.io.File; +import org.jetbrains.jet.JetTestUtils; +import org.jetbrains.jet.test.TestMetadata; + +import org.jetbrains.jet.codegen.AbstractIntrinsicsTestCase; + +/** This class is generated by {@link org.jetbrains.jet.codegen.AbstractIntrinsicsTestCase}. DO NOT MODIFY MANUALLY */ +@TestMetadata("compiler/testData/codegen/intrinsics") +public class IntrinsicsTestGenerated extends AbstractIntrinsicsTestCase { + public void testAllFilesPresentInIntrinsics() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.codegen.AbstractIntrinsicsTestCase", new File("compiler/testData/codegen/intrinsics"), "kt", false); + } + + @TestMetadata("longRangeWithExplicitDot.kt") + public void testLongRangeWithExplicitDot() throws Exception { + blackBoxFileByFullPath("compiler/testData/codegen/intrinsics/longRangeWithExplicitDot.kt"); + } + +}