KT-7397: use reference comparison (===) when translating a is A, where A is an object. Use more sophisticated check for reified parameters.
This commit is contained in:
@@ -381,6 +381,15 @@
|
||||
return object instanceof klass;
|
||||
}
|
||||
|
||||
var proto = Object.getPrototypeOf(klass);
|
||||
var constructor = proto != null ? proto.constructor : null;
|
||||
if (constructor != null && "$metadata$" in constructor) {
|
||||
var metadata = constructor.$metadata$;
|
||||
if (metadata.type === Kotlin.TYPE.OBJECT) {
|
||||
return object === klass;
|
||||
}
|
||||
}
|
||||
|
||||
// In WebKit (JavaScriptCore) for some interfaces from DOM typeof returns "object", nevertheless they can be used in RHS of instanceof
|
||||
if (isNativeClass(klass)) {
|
||||
return object instanceof klass;
|
||||
|
||||
+1
-2
@@ -5,8 +5,7 @@ object Obj
|
||||
fun box(): String {
|
||||
val r: Any = Obj
|
||||
|
||||
// TODO: fix KT-13465
|
||||
// if (r !is Obj) return "r !is Obj"
|
||||
if (r !is Obj) return "r !is Obj"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
// NO_INLINE
|
||||
package foo
|
||||
|
||||
object Obj
|
||||
|
||||
private inline fun <reified T> check(a: Any): String {
|
||||
return if (a is T) "OK" else "fail"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var x: Any = Obj
|
||||
return check<Obj>(x)
|
||||
}
|
||||
Reference in New Issue
Block a user