JS/RTTI. Fix build and tests
This commit is contained in:
committed by
Alexey Andreev
parent
9bb60b48b2
commit
3a87049359
+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