JS/RTTI. Fix build and tests
This commit is contained in:
committed by
Alexey Andreev
parent
9bb60b48b2
commit
3a87049359
@@ -500,11 +500,6 @@ public class TypeUtils {
|
||||
return typeParameterDescriptor != null && !typeParameterDescriptor.isReified();
|
||||
}
|
||||
|
||||
public static boolean isReifiedTypeParameter(@NotNull KotlinType type) {
|
||||
TypeParameterDescriptor typeParameterDescriptor = getTypeParameterDescriptorOrNull(type);
|
||||
return typeParameterDescriptor != null && typeParameterDescriptor.isReified();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static TypeParameterDescriptor getTypeParameterDescriptorOrNull(@NotNull KotlinType type) {
|
||||
if (type.getConstructor().getDeclarationDescriptor() instanceof TypeParameterDescriptor) {
|
||||
|
||||
@@ -1088,11 +1088,11 @@ fun main(args: Array<String>) {
|
||||
model("reified/cases")
|
||||
}
|
||||
|
||||
testClass(javaClass<AbstractRttiTest>()) {
|
||||
testClass<AbstractRttiTest>() {
|
||||
model("rtti/cases")
|
||||
}
|
||||
|
||||
testClass(javaClass<AbstractCastTest>()) {
|
||||
testClass<AbstractCastTest>() {
|
||||
model("expression/cast/cases")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2010-2016 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 java.lang
|
||||
|
||||
@library
|
||||
@@ -27,7 +43,7 @@ public class NumberFormatException(message: String? = null) : RuntimeException(m
|
||||
@library
|
||||
public class NullPointerException(message: String? = null) : RuntimeException(message) {}
|
||||
|
||||
library
|
||||
@library
|
||||
public class ClassCastException(message: String? = null) : RuntimeException(message) {}
|
||||
|
||||
@library
|
||||
|
||||
@@ -217,7 +217,7 @@ private fun RegExp.findNext(input: String, from: Int): MatchResult? {
|
||||
get() {
|
||||
if (groupValues_ == null) {
|
||||
groupValues_ = object : java.util.AbstractList<String>() {
|
||||
override val size: Int get() = match.size
|
||||
override val size: Int get() = match.length
|
||||
override fun get(index: Int): String = match[index] ?: ""
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
* Copyright 2010-2016 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.
|
||||
@@ -45,6 +45,6 @@ public fun RegExp.reset() {
|
||||
public val input: String
|
||||
public val length: Int
|
||||
|
||||
nativeGetter
|
||||
public fun get(index: Int): String?
|
||||
@nativeGetter
|
||||
public operator fun get(index: Int): String?
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
* Copyright 2010-2016 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.
|
||||
@@ -54,13 +54,13 @@ class RegExpTest {
|
||||
@test fun regExpExec() {
|
||||
val string = "R2D2 beats A5D5 "
|
||||
var re = RegExp("""(\w\d)(\w\d)""", "g")
|
||||
val m1: Array<out String?> = re.exec(string)!!
|
||||
assertEquals(arrayOf("R2D2", "R2", "D2"), m1)
|
||||
val m1 = re.exec(string)!!
|
||||
assertEquals(arrayOf("R2D2", "R2", "D2"), m1.toArray())
|
||||
assertEquals(0, m1.index)
|
||||
assertEquals(4, re.lastIndex)
|
||||
|
||||
val m2: Array<out String?> = re.exec(string)!!
|
||||
assertEquals(arrayOf("A5D5", "A5", "D5"), m2)
|
||||
val m2 = re.exec(string)!!
|
||||
assertEquals(arrayOf("A5D5", "A5", "D5"), m2.toArray())
|
||||
assertEquals(string.indexOf(m2[0]!!), m2.index)
|
||||
|
||||
val noMatch = re.exec(string)
|
||||
@@ -68,4 +68,9 @@ class RegExpTest {
|
||||
assertEquals(0, re.lastIndex)
|
||||
}
|
||||
|
||||
fun RegExpMatch.toArray(): Array<out String?> {
|
||||
val array = arrayOfNulls<String>(length)
|
||||
array.indices.forEach { array[it] = this[it] }
|
||||
return array
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
* Copyright 2010-2016 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.
|
||||
@@ -326,9 +326,9 @@ public abstract class BasicTest extends KotlinTestWithEnvironment {
|
||||
@NotNull String moduleId,
|
||||
@NotNull EcmaVersion ecmaVersion,
|
||||
@Nullable List<String> libraries,
|
||||
List<JetFile> jetFiles
|
||||
List<KtFile> jetFiles
|
||||
) {
|
||||
for (JetFile file : jetFiles) {
|
||||
for (KtFile file : jetFiles) {
|
||||
String text = file.getText();
|
||||
|
||||
if (isDirectiveDefined(text, NO_INLINE_DIRECTIVE)) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
* Copyright 2010-2016 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.
|
||||
@@ -18,7 +18,7 @@ package org.jetbrains.kotlin.js.test.semantics;
|
||||
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
|
||||
import org.jetbrains.kotlin.test.JetTestUtils;
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||
import org.jetbrains.kotlin.test.TestMetadata;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@@ -32,108 +32,108 @@ import java.util.regex.Pattern;
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public class CastTestGenerated extends AbstractCastTest {
|
||||
public void testAllFilesPresentInCases() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("js/js.translator/testData/expression/cast/cases"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("js/js.translator/testData/expression/cast/cases"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("castToAny.kt")
|
||||
public void testCastToAny() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/castToAny.kt");
|
||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/castToAny.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("castToArray.kt")
|
||||
public void testCastToArray() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/castToArray.kt");
|
||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/castToArray.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("castToFunction.kt")
|
||||
public void testCastToFunction() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/castToFunction.kt");
|
||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/castToFunction.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("castToGenericType.kt")
|
||||
public void testCastToGenericType() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/castToGenericType.kt");
|
||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/castToGenericType.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("castToGenericTypeWithUpperBound.kt")
|
||||
public void testCastToGenericTypeWithUpperBound() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/castToGenericTypeWithUpperBound.kt");
|
||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/castToGenericTypeWithUpperBound.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("castToNotNull.kt")
|
||||
public void testCastToNotNull() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/castToNotNull.kt");
|
||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/castToNotNull.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("castToNullable.kt")
|
||||
public void testCastToNullable() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/castToNullable.kt");
|
||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/castToNullable.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("reifiedToNotNull.kt")
|
||||
public void testReifiedToNotNull() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/reifiedToNotNull.kt");
|
||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/reifiedToNotNull.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("reifiedToNullable1.kt")
|
||||
public void testReifiedToNullable1() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/reifiedToNullable1.kt");
|
||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/reifiedToNullable1.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("reifiedToNullable2.kt")
|
||||
public void testReifiedToNullable2() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/reifiedToNullable2.kt");
|
||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/reifiedToNullable2.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("safeCastToGenericTypeWithUpperBound.kt")
|
||||
public void testSafeCastToGenericTypeWithUpperBound() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/safeCastToGenericTypeWithUpperBound.kt");
|
||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/safeCastToGenericTypeWithUpperBound.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("safeCastToNotNull.kt")
|
||||
public void testSafeCastToNotNull() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/safeCastToNotNull.kt");
|
||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/safeCastToNotNull.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("safeCastToNullable.kt")
|
||||
public void testSafeCastToNullable() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/safeCastToNullable.kt");
|
||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/safeCastToNullable.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("safeCastToReifiedNotNull.kt")
|
||||
public void testSafeCastToReifiedNotNull() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/safeCastToReifiedNotNull.kt");
|
||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/safeCastToReifiedNotNull.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("safeCastToReifiedNullable.kt")
|
||||
public void testSafeCastToReifiedNullable() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/safeCastToReifiedNullable.kt");
|
||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/safeCastToReifiedNullable.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("smartCastInExtensionFunction.kt")
|
||||
public void testSmartCastInExtensionFunction() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/smartCastInExtensionFunction.kt");
|
||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/smartCastInExtensionFunction.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("smartCastInFunction.kt")
|
||||
public void testSmartCastInFunction() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/smartCastInFunction.kt");
|
||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/expression/cast/cases/smartCastInFunction.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ public class ReifiedTestGenerated extends AbstractReifiedTest {
|
||||
|
||||
@TestMetadata("isTNullable.kt")
|
||||
public void testIsTNullable() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/reified/cases/isTNullable.kt");
|
||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/reified/cases/isTNullable.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ public class ReifiedTestGenerated extends AbstractReifiedTest {
|
||||
|
||||
@TestMetadata("withInlineTurnedOff.kt")
|
||||
public void testWithInlineTurnedOff() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/reified/cases/withInlineTurnedOff.kt");
|
||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/reified/cases/withInlineTurnedOff.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
* Copyright 2010-2016 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.
|
||||
@@ -18,7 +18,7 @@ package org.jetbrains.kotlin.js.test.semantics;
|
||||
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
|
||||
import org.jetbrains.kotlin.test.JetTestUtils;
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||
import org.jetbrains.kotlin.test.TestMetadata;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@@ -32,72 +32,72 @@ import java.util.regex.Pattern;
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public class RttiTestGenerated extends AbstractRttiTest {
|
||||
public void testAllFilesPresentInCases() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("js/js.translator/testData/rtti/cases"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("js/js.translator/testData/rtti/cases"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("collectionClassesIsCheck.kt")
|
||||
public void testCollectionClassesIsCheck() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/rtti/cases/collectionClassesIsCheck.kt");
|
||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/rtti/cases/collectionClassesIsCheck.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("isComparable.kt")
|
||||
public void testIsComparable() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/rtti/cases/isComparable.kt");
|
||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/rtti/cases/isComparable.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("isJsPrimitiveType.kt")
|
||||
public void testIsJsPrimitiveType() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/rtti/cases/isJsPrimitiveType.kt");
|
||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/rtti/cases/isJsPrimitiveType.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("isSameClass.kt")
|
||||
public void testIsSameClass() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/rtti/cases/isSameClass.kt");
|
||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/rtti/cases/isSameClass.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("notIsOtherClass.kt")
|
||||
public void testNotIsOtherClass() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/rtti/cases/notIsOtherClass.kt");
|
||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/rtti/cases/notIsOtherClass.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("rttiForClass.kt")
|
||||
public void testRttiForClass() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/rtti/cases/rttiForClass.kt");
|
||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/rtti/cases/rttiForClass.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("rttiForTrait.kt")
|
||||
public void testRttiForTrait() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/rtti/cases/rttiForTrait.kt");
|
||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/rtti/cases/rttiForTrait.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("rttiForTrait2.kt")
|
||||
public void testRttiForTrait2() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/rtti/cases/rttiForTrait2.kt");
|
||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/rtti/cases/rttiForTrait2.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("sideEffectMethod.kt")
|
||||
public void testSideEffectMethod() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/rtti/cases/sideEffectMethod.kt");
|
||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/rtti/cases/sideEffectMethod.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("sideEffectProperty.kt")
|
||||
public void testSideEffectProperty() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/rtti/cases/sideEffectProperty.kt");
|
||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/rtti/cases/sideEffectProperty.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("stdlibEmptyListClass.kt")
|
||||
public void testStdlibEmptyListClass() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("js/js.translator/testData/rtti/cases/stdlibEmptyListClass.kt");
|
||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/rtti/cases/stdlibEmptyListClass.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
+12
-12
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
* Copyright 2010-2016 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.
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.jetbrains.kotlin.js.translate.expression;
|
||||
|
||||
import com.google.dart.compiler.backend.js.ast.*;
|
||||
import com.google.dart.compiler.backend.js.ast.metadata.MetadataProperties;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.KtNodeTypes;
|
||||
@@ -25,9 +24,8 @@ import org.jetbrains.kotlin.descriptors.CallableDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor;
|
||||
import org.jetbrains.kotlin.js.descriptorUtils.DescriptorUtilsKt;
|
||||
import org.jetbrains.kotlin.js.patterns.NamePredicate;
|
||||
import org.jetbrains.kotlin.js.patterns.typePredicates.TypePredicatesPackage;
|
||||
import org.jetbrains.kotlin.js.patterns.typePredicates.TypePredicatesKt;
|
||||
import org.jetbrains.kotlin.js.translate.context.Namer;
|
||||
import org.jetbrains.kotlin.js.translate.context.TemporaryVariable;
|
||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext;
|
||||
@@ -42,16 +40,18 @@ import org.jetbrains.kotlin.psi.KtIsExpression;
|
||||
import org.jetbrains.kotlin.psi.KtTypeReference;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.types.TypeIntersector;
|
||||
|
||||
import static org.jetbrains.kotlin.builtins.KotlinBuiltIns.*;
|
||||
import static org.jetbrains.kotlin.js.descriptorUtils.DescriptorUtilsPackage.getNameIfStandardType;
|
||||
import static org.jetbrains.kotlin.builtins.FunctionTypesKt.isFunctionTypeOrSubtype;
|
||||
import static org.jetbrains.kotlin.builtins.KotlinBuiltIns.isAnyOrNullableAny;
|
||||
import static org.jetbrains.kotlin.builtins.KotlinBuiltIns.isArray;
|
||||
import static org.jetbrains.kotlin.js.descriptorUtils.DescriptorUtilsKt.getNameIfStandardType;
|
||||
import static org.jetbrains.kotlin.js.translate.utils.JsAstUtils.equality;
|
||||
import static org.jetbrains.kotlin.js.translate.utils.JsAstUtils.negated;
|
||||
import static org.jetbrains.kotlin.psi.KtPsiUtil.findChildByType;
|
||||
import static org.jetbrains.kotlin.types.TypeUtils.*;
|
||||
import static org.jetbrains.kotlin.types.TypeUtils.getTypeParameterDescriptorOrNull;
|
||||
import static org.jetbrains.kotlin.types.TypeUtils.isNullableType;
|
||||
import static org.jetbrains.kotlin.types.TypeUtils.isReifiedTypeParameter;
|
||||
|
||||
public final class PatternTranslator extends AbstractTranslator {
|
||||
|
||||
@@ -143,7 +143,7 @@ public final class PatternTranslator extends AbstractTranslator {
|
||||
return getIsTypeCheckCallableForReifiedType(typeParameterDescriptor);
|
||||
}
|
||||
|
||||
return doGetIsTypeCheckCallable(typeParameterDescriptor.getUpperBoundsAsType());
|
||||
return doGetIsTypeCheckCallable(TypeIntersector.getUpperBoundsAsType(typeParameterDescriptor));
|
||||
}
|
||||
|
||||
JsNameRef typeName = getClassNameReference(type);
|
||||
@@ -154,18 +154,18 @@ public final class PatternTranslator extends AbstractTranslator {
|
||||
private JsExpression getIsTypeCheckCallableForBuiltin(@NotNull KotlinType type) {
|
||||
if (isAnyOrNullableAny(type)) return namer().isAny();
|
||||
|
||||
if (isFunctionOrExtensionFunctionType(type)) return namer().isTypeOf(program().getStringLiteral("function"));
|
||||
if (isFunctionTypeOrSubtype(type)) return namer().isTypeOf(program().getStringLiteral("function"));
|
||||
|
||||
if (isArray(type)) return Namer.IS_ARRAY_FUN_REF;
|
||||
|
||||
if (TypePredicatesPackage.getCOMPARABLE().apply(type)) return namer().isComparable();
|
||||
if (TypePredicatesKt.getCOMPARABLE().apply(type)) return namer().isComparable();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private JsExpression getIsTypeCheckCallableForBuiltin(@NotNull KotlinType type) {
|
||||
Name typeName = DescriptorUtilsKt.getNameIfStandardType(type);
|
||||
private JsExpression getIsTypeCheckCallableForPrimitiveBuiltin(@NotNull KotlinType type) {
|
||||
Name typeName = getNameIfStandardType(type);
|
||||
|
||||
if (NamePredicate.STRING.apply(typeName)) {
|
||||
return namer().isTypeOf(program().getStringLiteral("string"));
|
||||
|
||||
+4
-4
@@ -4,13 +4,13 @@ open class A
|
||||
class B : A()
|
||||
class C
|
||||
|
||||
fun notNullToNotNullT<T : A>(a: Any): T = a as T
|
||||
fun <T : A> notNullToNotNullT(a: Any): T = a as T
|
||||
|
||||
fun nullableToNotNullT<T : A>(a: Any?): T = a as T
|
||||
fun <T : A> nullableToNotNullT(a: Any?): T = a as T
|
||||
|
||||
fun notNullToNullableT<T : A>(a: Any): T? = a as T?
|
||||
fun <T : A> notNullToNullableT(a: Any): T? = a as T?
|
||||
|
||||
fun nullableToNullableT<T : A>(a: Any?): T? = a as T?
|
||||
fun <T : A> nullableToNullableT(a: Any?): T? = a as T?
|
||||
|
||||
fun box(): String {
|
||||
val a = A()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package foo
|
||||
|
||||
trait A
|
||||
interface A
|
||||
|
||||
class AImpl: A
|
||||
|
||||
@@ -15,4 +15,4 @@ fun box(): String {
|
||||
failsClassCast("test(object{})") { test(object{}) }
|
||||
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,12 +2,12 @@ package foo
|
||||
|
||||
// CHECK_NOT_CALLED: test
|
||||
|
||||
trait A
|
||||
interface A
|
||||
|
||||
class AImpl: A
|
||||
|
||||
inline
|
||||
fun test<reified T>(x: Any?): T = x as T
|
||||
fun <reified T> test(x: Any?): T = x as T
|
||||
|
||||
fun box(): String {
|
||||
var a: A = AImpl()
|
||||
@@ -18,4 +18,4 @@ fun box(): String {
|
||||
failsClassCast("test(object{})") { test<A>(object{}) }
|
||||
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ interface A
|
||||
class AImpl : A {}
|
||||
|
||||
inline
|
||||
fun test<reified T>(x: Any?): T = x as T
|
||||
fun <reified T> test(x: Any?): T = x as T
|
||||
|
||||
fun box(): String {
|
||||
var a: A? = AImpl()
|
||||
@@ -16,4 +16,4 @@ fun box(): String {
|
||||
failsClassCast("test(object{})") { test<A?>(object{}) }
|
||||
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ interface A
|
||||
class AImpl : A {}
|
||||
|
||||
inline
|
||||
fun test<reified T>(x: Any?): T? = x as T?
|
||||
fun <reified T> test(x: Any?): T? = x as T?
|
||||
|
||||
fun box(): String {
|
||||
var a: A? = AImpl()
|
||||
@@ -16,4 +16,4 @@ fun box(): String {
|
||||
failsClassCast("test(object{})") { test<A>(object{}) }
|
||||
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -4,9 +4,9 @@ open class A
|
||||
class B : A()
|
||||
class C
|
||||
|
||||
fun notNullToNullableT<T : A>(a: Any): T? = a as? T?
|
||||
fun <T : A> notNullToNullableT(a: Any): T? = a as? T?
|
||||
|
||||
fun nullableToNullableT<T : A>(a: Any?): T? = a as? T?
|
||||
fun <T : A> nullableToNullableT(a: Any?): T? = a as? T?
|
||||
|
||||
fun box(): String {
|
||||
val a = A()
|
||||
|
||||
+2
-2
@@ -6,7 +6,7 @@ class A
|
||||
class B
|
||||
|
||||
inline
|
||||
fun Any?.castTo<reified T>(): T? = this as? T
|
||||
fun <reified T> Any?.castTo(): T? = this as? T
|
||||
|
||||
fun box(): String {
|
||||
val a: Any? = A()
|
||||
@@ -18,4 +18,4 @@ fun box(): String {
|
||||
assertEquals(null, b.castTo<A>(), "b")
|
||||
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -6,7 +6,7 @@ class A
|
||||
class B
|
||||
|
||||
inline
|
||||
fun Any?.castTo<reified T>(): T? = this as? T?
|
||||
fun <reified T> Any?.castTo(): T? = this as? T?
|
||||
|
||||
fun box(): String {
|
||||
val a: Any? = A()
|
||||
@@ -18,4 +18,4 @@ fun box(): String {
|
||||
assertEquals(null, b.castTo<A>(), "b")
|
||||
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -4,7 +4,7 @@ package foo
|
||||
// CHECK_NULLS_COUNT: function=box count=8
|
||||
|
||||
inline
|
||||
fun Any?.isTypeOfOrNull<reified T>() = this is T?
|
||||
fun <reified T> Any?.isTypeOfOrNull() = this is T?
|
||||
|
||||
class A
|
||||
class B
|
||||
@@ -18,4 +18,4 @@ fun box(): String {
|
||||
assertEquals(false, A().isTypeOfOrNull<B?>(), "A().isTypeOfOrNull<B?>()")
|
||||
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user