JS: prohibit is checks against native interfaces. Warn about casts to native interfaces. Fix #KT-14037, fix #KT-14038
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
// FILE: castToNativeClassChecked.kt
|
||||
@native abstract class S() {
|
||||
abstract fun foo(): String
|
||||
}
|
||||
|
||||
@native class A(x: String) {
|
||||
fun foo(): String = noImpl
|
||||
}
|
||||
|
||||
fun createObject(): Any = A("fail: CCE not thrown")
|
||||
|
||||
fun box(): String {
|
||||
try {
|
||||
return (createObject() as S).foo()
|
||||
}
|
||||
catch (e: ClassCastException) {
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: castToNativeClassChecked.js
|
||||
function S() {
|
||||
}
|
||||
function A(x) {
|
||||
this.x = x;
|
||||
}
|
||||
A.prototype.foo = function() {
|
||||
return this.x;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// FILE: castToNativeInterface.kt
|
||||
@native interface I {
|
||||
fun foo(): String
|
||||
}
|
||||
|
||||
@native class A(x: String) : I {
|
||||
override fun foo(): String = noImpl
|
||||
}
|
||||
|
||||
fun createObject(): Any = A("OK")
|
||||
|
||||
fun box() = (createObject() as I).foo()
|
||||
|
||||
// FILE: castToNativeInterface.js
|
||||
function A(x) {
|
||||
this.x = x;
|
||||
}
|
||||
A.prototype.foo = function() {
|
||||
return this.x;
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
// FILE: castToTypeParamBoundedByNativeInterface.kt
|
||||
@native interface I {
|
||||
fun foo(): String
|
||||
}
|
||||
|
||||
interface J {
|
||||
fun bar(): String
|
||||
}
|
||||
|
||||
@native abstract class B() : I
|
||||
|
||||
@native class A(x: String) : B() {
|
||||
override fun foo(): String = noImpl
|
||||
}
|
||||
|
||||
fun createObject(): Any = A("OK")
|
||||
|
||||
fun <T> castToI(o: Any): T where T : I, T : B = o as T
|
||||
|
||||
fun box() = castToI<A>(createObject()).foo()
|
||||
|
||||
// FILE: castToTypeParamBoundedByNativeInterface.js
|
||||
function B() {
|
||||
}
|
||||
|
||||
function A(x) {
|
||||
this.x = x;
|
||||
}
|
||||
A.prototype = Object.create(B.prototype);
|
||||
A.prototype.foo = function() {
|
||||
return this.x;
|
||||
}
|
||||
Reference in New Issue
Block a user