Move everything under kotlin-native folder
I was forced to manually do update the following files, because otherwise they would be ignored according .gitignore settings. Probably they should be deleted from repo. Interop/.idea/compiler.xml Interop/.idea/gradle.xml Interop/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_runtime_1_0_3.xml Interop/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_1_0_3.xml Interop/.idea/modules.xml Interop/.idea/modules/Indexer/Indexer.iml Interop/.idea/modules/Runtime/Runtime.iml Interop/.idea/modules/StubGenerator/StubGenerator.iml backend.native/backend.native.iml backend.native/bc.frontend/bc.frontend.iml backend.native/cli.bc/cli.bc.iml backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.kt backend.native/tests/link/lib/foo.kt backend.native/tests/link/lib/foo2.kt backend.native/tests/teamcity-test.property
This commit is contained in:
@@ -0,0 +1,178 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package coroutines
|
||||
|
||||
import kotlin.coroutines.*
|
||||
import kotlin.coroutines.cancellation.CancellationException
|
||||
import kotlin.coroutines.intrinsics.*
|
||||
import kotlin.native.concurrent.isFrozen
|
||||
import kotlin.native.internal.ObjCErrorException
|
||||
import kotlin.test.*
|
||||
|
||||
class CoroutineException : Throwable()
|
||||
|
||||
suspend fun suspendFun() = 42
|
||||
|
||||
@Throws(CoroutineException::class, CancellationException::class)
|
||||
suspend fun suspendFun(result: Any?, doSuspend: Boolean, doThrow: Boolean): Any? {
|
||||
if (doSuspend) {
|
||||
suspendCoroutineUninterceptedOrReturn<Unit> {
|
||||
it.resume(Unit)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
}
|
||||
|
||||
if (doThrow) throw CoroutineException()
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
class ContinuationHolder<T> {
|
||||
internal lateinit var continuation: Continuation<T>
|
||||
|
||||
fun resume(value: T) {
|
||||
continuation.resume(value)
|
||||
}
|
||||
|
||||
fun resumeWithException(exception: Throwable) {
|
||||
continuation.resumeWithException(exception)
|
||||
}
|
||||
}
|
||||
|
||||
@Throws(CoroutineException::class, CancellationException::class)
|
||||
suspend fun suspendFunAsync(result: Any?, continuationHolder: ContinuationHolder<Any?>): Any? =
|
||||
suspendCoroutineUninterceptedOrReturn<Any?> {
|
||||
continuationHolder.continuation = it
|
||||
COROUTINE_SUSPENDED
|
||||
} ?: result
|
||||
|
||||
@Throws(CoroutineException::class, CancellationException::class)
|
||||
fun throwException(exception: Throwable) {
|
||||
throw exception
|
||||
}
|
||||
|
||||
interface SuspendFun {
|
||||
@Throws(CoroutineException::class, CancellationException::class)
|
||||
suspend fun suspendFun(doYield: Boolean, doThrow: Boolean): Int
|
||||
}
|
||||
|
||||
class ResultHolder<T> {
|
||||
var completed: Int = 0
|
||||
var result: T? = null
|
||||
var exception: Throwable? = null
|
||||
|
||||
internal fun complete(result: Result<T>) {
|
||||
this.result = result.getOrNull()
|
||||
this.exception = result.exceptionOrNull()
|
||||
this.completed += 1
|
||||
}
|
||||
}
|
||||
|
||||
private class ResultHolderCompletion<T>(val resultHolder: ResultHolder<T>) : Continuation<T> {
|
||||
override val context: CoroutineContext
|
||||
get() = EmptyCoroutineContext
|
||||
|
||||
override fun resumeWith(result: Result<T>) {
|
||||
resultHolder.complete(result)
|
||||
}
|
||||
}
|
||||
|
||||
fun callSuspendFun(suspendFun: SuspendFun, doYield: Boolean, doThrow: Boolean, resultHolder: ResultHolder<Int>) {
|
||||
suspend { suspendFun.suspendFun(doYield = doYield, doThrow = doThrow) }
|
||||
.startCoroutine(ResultHolderCompletion(resultHolder))
|
||||
}
|
||||
|
||||
@Throws(CoroutineException::class, CancellationException::class)
|
||||
suspend fun callSuspendFun2(suspendFun: SuspendFun, doYield: Boolean, doThrow: Boolean): Int {
|
||||
return suspendFun.suspendFun(doYield = doYield, doThrow = doThrow)
|
||||
}
|
||||
|
||||
interface SuspendBridge<T> {
|
||||
suspend fun int(value: T): Int
|
||||
suspend fun intAsAny(value: T): Any?
|
||||
|
||||
suspend fun unit(value: T): Unit
|
||||
suspend fun unitAsAny(value: T): Any?
|
||||
|
||||
@Throws(Throwable::class) suspend fun nothing(value: T): Nothing
|
||||
@Throws(Throwable::class) suspend fun nothingAsInt(value: T): Int
|
||||
@Throws(Throwable::class) suspend fun nothingAsAny(value: T): Any?
|
||||
@Throws(Throwable::class) suspend fun nothingAsUnit(value: T): Unit
|
||||
}
|
||||
|
||||
abstract class AbstractSuspendBridge : SuspendBridge<Int> {
|
||||
override suspend fun intAsAny(value: Int): Int = TODO()
|
||||
|
||||
override suspend fun unitAsAny(value: Int): Unit = TODO()
|
||||
|
||||
override suspend fun nothingAsInt(value: Int): Nothing = TODO()
|
||||
override suspend fun nothingAsAny(value: Int): Nothing = TODO()
|
||||
override suspend fun nothingAsUnit(value: Int): Nothing = TODO()
|
||||
}
|
||||
|
||||
private suspend fun callSuspendBridgeImpl(bridge: SuspendBridge<Int>) {
|
||||
assertEquals(1, bridge.intAsAny(1))
|
||||
|
||||
assertSame(Unit, bridge.unitAsAny(2))
|
||||
|
||||
assertFailsWith<ObjCErrorException> { bridge.nothingAsInt(3) }
|
||||
assertFailsWith<ObjCErrorException> { bridge.nothingAsAny(4) }
|
||||
assertFailsWith<ObjCErrorException> { bridge.nothingAsUnit(5) }
|
||||
}
|
||||
|
||||
private suspend fun callAbstractSuspendBridgeImpl(bridge: AbstractSuspendBridge) {
|
||||
assertEquals(6, bridge.intAsAny(6))
|
||||
|
||||
assertSame(Unit, bridge.unitAsAny(7))
|
||||
|
||||
assertFailsWith<ObjCErrorException> { bridge.nothingAsInt(8) }
|
||||
assertFailsWith<ObjCErrorException> { bridge.nothingAsAny(9) }
|
||||
assertFailsWith<ObjCErrorException> { bridge.nothingAsUnit(10) }
|
||||
}
|
||||
|
||||
@Throws(Throwable::class)
|
||||
fun callSuspendBridge(bridge: AbstractSuspendBridge, resultHolder: ResultHolder<Unit>) {
|
||||
suspend {
|
||||
callSuspendBridgeImpl(bridge)
|
||||
callAbstractSuspendBridgeImpl(bridge)
|
||||
}.startCoroutine(ResultHolderCompletion(resultHolder))
|
||||
}
|
||||
|
||||
suspend fun throwCancellationException(): Unit {
|
||||
val exception = CancellationException("coroutine is cancelled")
|
||||
|
||||
// Note: frontend checker hardcodes fq names of CancellationException super classes (see NativeThrowsChecker).
|
||||
// This is our best effort to keep that list in sync with actual stdlib code:
|
||||
assertTrue(exception is kotlin.Throwable)
|
||||
assertTrue(exception is kotlin.Exception)
|
||||
assertTrue(exception is kotlin.RuntimeException)
|
||||
assertTrue(exception is kotlin.IllegalStateException)
|
||||
assertTrue(exception is kotlin.coroutines.cancellation.CancellationException)
|
||||
|
||||
throw exception
|
||||
}
|
||||
|
||||
abstract class ThrowCancellationException {
|
||||
internal abstract suspend fun throwCancellationException()
|
||||
}
|
||||
|
||||
class ThrowCancellationExceptionImpl : ThrowCancellationException() {
|
||||
public override suspend fun throwCancellationException() {
|
||||
throw CancellationException()
|
||||
}
|
||||
}
|
||||
|
||||
fun getSuspendLambda0(): suspend () -> String = { "lambda 0" }
|
||||
|
||||
private suspend fun suspendCallableReference0Target(): String = "callable reference 0"
|
||||
fun getSuspendCallableReference0(): suspend () -> String = ::suspendCallableReference0Target
|
||||
|
||||
fun getSuspendLambda1(): suspend (String) -> String = { "$it 1" }
|
||||
|
||||
private suspend fun suspendCallableReference1Target(str: String): String = "$str 1"
|
||||
fun getSuspendCallableReference1(): suspend (String) -> String = ::suspendCallableReference1Target
|
||||
|
||||
suspend fun invoke1(block: suspend (Any?) -> Any?, argument: Any?): Any? = block(argument)
|
||||
@@ -0,0 +1,334 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
import Kt
|
||||
|
||||
private func testCallSimple() throws {
|
||||
var result: KotlinInt? = nil
|
||||
var error: Error? = nil
|
||||
var completionCalled = 0
|
||||
|
||||
CoroutinesKt.suspendFun { _result, _error in
|
||||
completionCalled += 1
|
||||
result = _result
|
||||
error = _error
|
||||
}
|
||||
|
||||
try assertEquals(actual: completionCalled, expected: 1)
|
||||
try assertEquals(actual: result, expected: 42)
|
||||
try assertNil(error)
|
||||
}
|
||||
|
||||
private func testCallSuspendFun(doSuspend: Bool, doThrow: Bool) throws {
|
||||
class C {}
|
||||
let expectedResult = C()
|
||||
|
||||
var completionCalled = 0
|
||||
var result: AnyObject? = nil
|
||||
var error: Error? = nil
|
||||
|
||||
CoroutinesKt.suspendFun(result: expectedResult, doSuspend: doSuspend, doThrow: doThrow) { _result, _error in
|
||||
completionCalled += 1
|
||||
result = _result as AnyObject?
|
||||
error = _error
|
||||
}
|
||||
|
||||
try assertEquals(actual: completionCalled, expected: 1)
|
||||
|
||||
if doThrow {
|
||||
try assertNil(result)
|
||||
try assertTrue(error?.kotlinException is CoroutineException)
|
||||
} else {
|
||||
try assertSame(actual: result, expected: expectedResult)
|
||||
try assertNil(error)
|
||||
}
|
||||
}
|
||||
|
||||
private func testSuspendFuncAsync(doThrow: Bool) throws {
|
||||
var completionCalled = 0
|
||||
var result: AnyObject? = nil
|
||||
var error: Error? = nil
|
||||
|
||||
let continuationHolder = ContinuationHolder<AnyObject>()
|
||||
|
||||
CoroutinesKt.suspendFunAsync(result: nil, continuationHolder: continuationHolder) { _result, _error in
|
||||
completionCalled += 1
|
||||
result = _result as AnyObject?
|
||||
error = _error
|
||||
}
|
||||
|
||||
try assertEquals(actual: completionCalled, expected: 0)
|
||||
|
||||
if doThrow {
|
||||
let exception = CoroutineException()
|
||||
continuationHolder.resumeWithException(exception: exception)
|
||||
|
||||
try assertEquals(actual: completionCalled, expected: 1)
|
||||
|
||||
try assertNil(result)
|
||||
try assertSame(actual: error?.kotlinException as AnyObject?, expected: exception)
|
||||
} else {
|
||||
class C {}
|
||||
let expectedResult = C()
|
||||
continuationHolder.resume(value: expectedResult)
|
||||
|
||||
try assertEquals(actual: completionCalled, expected: 1)
|
||||
|
||||
try assertSame(actual: result, expected: expectedResult)
|
||||
try assertNil(error)
|
||||
}
|
||||
}
|
||||
|
||||
private func testCall() throws {
|
||||
try testCallSuspendFun(doSuspend: true, doThrow: false)
|
||||
try testCallSuspendFun(doSuspend: false, doThrow: false)
|
||||
try testCallSuspendFun(doSuspend: true, doThrow: true)
|
||||
try testCallSuspendFun(doSuspend: false, doThrow: true)
|
||||
|
||||
try testSuspendFuncAsync(doThrow: false)
|
||||
try testSuspendFuncAsync(doThrow: true)
|
||||
}
|
||||
|
||||
private class SuspendFunImpl : SuspendFun {
|
||||
class E : Error {}
|
||||
|
||||
var completion: (() -> Void)? = nil
|
||||
|
||||
func suspendFun(doYield: Bool, doThrow: Bool, completionHandler: @escaping (KotlinInt?, Error?) -> Void) {
|
||||
func callCompletion() {
|
||||
if doThrow {
|
||||
completionHandler(nil, E())
|
||||
} else {
|
||||
completionHandler(17, nil)
|
||||
}
|
||||
}
|
||||
|
||||
if doYield {
|
||||
self.completion = callCompletion
|
||||
} else {
|
||||
callCompletion()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func testSuspendFunImpl(doYield: Bool, doThrow: Bool) throws {
|
||||
let resultHolder = ResultHolder<KotlinInt>()
|
||||
|
||||
let impl = SuspendFunImpl()
|
||||
|
||||
CoroutinesKt.callSuspendFun(
|
||||
suspendFun: impl,
|
||||
doYield: doYield,
|
||||
doThrow: doThrow,
|
||||
resultHolder: resultHolder
|
||||
)
|
||||
|
||||
if doYield {
|
||||
try assertEquals(actual: resultHolder.completed, expected: 0)
|
||||
guard let completion = impl.completion else { try fail() }
|
||||
completion()
|
||||
}
|
||||
|
||||
try assertEquals(actual: resultHolder.completed, expected: 1)
|
||||
|
||||
if doThrow {
|
||||
try assertNil(resultHolder.result)
|
||||
if let e = resultHolder.exception {
|
||||
try assertFailsWith(SuspendFunImpl.E.self) { try CoroutinesKt.throwException(exception: e) }
|
||||
} else {
|
||||
try fail()
|
||||
}
|
||||
} else {
|
||||
try assertEquals(actual: resultHolder.result, expected: 17)
|
||||
try assertNil(resultHolder.exception)
|
||||
}
|
||||
}
|
||||
|
||||
private func testSuspendFunImpl2(doYield: Bool, doThrow: Bool) throws {
|
||||
let impl = SuspendFunImpl()
|
||||
|
||||
var completionCalled = 0
|
||||
var result: KotlinInt? = nil
|
||||
var error: Error? = nil
|
||||
|
||||
CoroutinesKt.callSuspendFun2(suspendFun: impl, doYield: doYield, doThrow: doThrow) { _result, _error in
|
||||
completionCalled += 1
|
||||
result = _result
|
||||
error = _error
|
||||
}
|
||||
|
||||
if doYield {
|
||||
try assertEquals(actual: completionCalled, expected: 0)
|
||||
guard let completion = impl.completion else { try fail() }
|
||||
completion()
|
||||
}
|
||||
|
||||
try assertEquals(actual: completionCalled, expected: 1)
|
||||
|
||||
if doThrow {
|
||||
try assertNil(result)
|
||||
try assertTrue(error is SuspendFunImpl.E)
|
||||
} else {
|
||||
try assertEquals(actual: result, expected: 17)
|
||||
try assertNil(error)
|
||||
}
|
||||
}
|
||||
|
||||
private func testOverride() throws {
|
||||
try testSuspendFunImpl(doYield: false, doThrow: false)
|
||||
try testSuspendFunImpl(doYield: false, doThrow: true)
|
||||
try testSuspendFunImpl(doYield: true, doThrow: false)
|
||||
try testSuspendFunImpl(doYield: true, doThrow: true)
|
||||
|
||||
try testSuspendFunImpl2(doYield: false, doThrow: false)
|
||||
try testSuspendFunImpl2(doYield: false, doThrow: true)
|
||||
try testSuspendFunImpl2(doYield: true, doThrow: false)
|
||||
try testSuspendFunImpl2(doYield: true, doThrow: true)
|
||||
}
|
||||
|
||||
private class SwiftSuspendBridge : AbstractSuspendBridge {
|
||||
class E : Error {}
|
||||
|
||||
override func intAsAny(value: KotlinInt, completionHandler: @escaping (KotlinInt?, Error?) -> Void) {
|
||||
completionHandler(value, nil)
|
||||
}
|
||||
|
||||
override func unitAsAny(value: KotlinInt, completionHandler: @escaping (KotlinUnit?, Error?) -> Void) {
|
||||
completionHandler(KotlinUnit(), nil)
|
||||
}
|
||||
|
||||
override func nothingAsInt(value: KotlinInt, completionHandler: @escaping (KotlinNothing?, Error?) -> Void) {
|
||||
completionHandler(nil, E())
|
||||
}
|
||||
|
||||
override func nothingAsAny(value: KotlinInt, completionHandler: @escaping (KotlinNothing?, Error?) -> Void) {
|
||||
completionHandler(nil, E())
|
||||
}
|
||||
|
||||
override func nothingAsUnit(value: KotlinInt, completionHandler: @escaping (KotlinNothing?, Error?) -> Void) {
|
||||
completionHandler(nil, E())
|
||||
}
|
||||
}
|
||||
|
||||
private func testBridges() throws {
|
||||
let resultHolder = ResultHolder<KotlinUnit>()
|
||||
try CoroutinesKt.callSuspendBridge(bridge: SwiftSuspendBridge(), resultHolder: resultHolder)
|
||||
|
||||
try assertEquals(actual: resultHolder.completed, expected: 1)
|
||||
try assertNil(resultHolder.exception)
|
||||
try assertSame(actual: resultHolder.result, expected: KotlinUnit())
|
||||
}
|
||||
|
||||
private func testImplicitThrows1() throws {
|
||||
var result: KotlinUnit? = nil
|
||||
var error: Error? = nil
|
||||
var completionCalled = 0
|
||||
|
||||
CoroutinesKt.throwCancellationException { _result, _error in
|
||||
completionCalled += 1
|
||||
result = _result
|
||||
error = _error
|
||||
}
|
||||
|
||||
try assertEquals(actual: completionCalled, expected: 1)
|
||||
try assertNil(result)
|
||||
try assertTrue(error?.kotlinException is KotlinCancellationException)
|
||||
}
|
||||
|
||||
private func testImplicitThrows2() throws {
|
||||
var result: KotlinUnit? = nil
|
||||
var error: Error? = nil
|
||||
var completionCalled = 0
|
||||
|
||||
ThrowCancellationExceptionImpl().throwCancellationException { _result, _error in
|
||||
completionCalled += 1
|
||||
result = _result
|
||||
error = _error
|
||||
}
|
||||
|
||||
try assertEquals(actual: completionCalled, expected: 1)
|
||||
try assertNil(result)
|
||||
try assertTrue(error?.kotlinException is KotlinCancellationException)
|
||||
}
|
||||
|
||||
private func testSuspendFunctionType0(f: KotlinSuspendFunction0, expectedResult: String) throws {
|
||||
try assertTrue((f as AnyObject) is KotlinSuspendFunction0)
|
||||
|
||||
var result: String? = nil
|
||||
var error: Error? = nil
|
||||
var completionCalled = 0
|
||||
|
||||
f.invoke { _result, _error in
|
||||
completionCalled += 1
|
||||
result = _result as? String
|
||||
error = _error
|
||||
}
|
||||
|
||||
try assertEquals(actual: completionCalled, expected: 1)
|
||||
try assertEquals(actual: result, expected: expectedResult)
|
||||
try assertNil(error)
|
||||
}
|
||||
|
||||
private func testSuspendFunctionType1(f: KotlinSuspendFunction1) throws {
|
||||
try assertTrue((f as AnyObject) is KotlinSuspendFunction1)
|
||||
|
||||
var result: String? = nil
|
||||
var error: Error? = nil
|
||||
var completionCalled = 0
|
||||
|
||||
f.invoke(p1: "suspend function type") { _result, _error in
|
||||
completionCalled += 1
|
||||
result = _result as? String
|
||||
error = _error
|
||||
}
|
||||
|
||||
try assertEquals(actual: completionCalled, expected: 1)
|
||||
try assertEquals(actual: result, expected: "suspend function type 1")
|
||||
try assertNil(error)
|
||||
}
|
||||
|
||||
private func testSuspendFunctionType() throws {
|
||||
try testSuspendFunctionType0(f: CoroutinesKt.getSuspendLambda0(), expectedResult: "lambda 0")
|
||||
try testSuspendFunctionType0(f: CoroutinesKt.getSuspendCallableReference0(), expectedResult: "callable reference 0")
|
||||
try testSuspendFunctionType1(f: CoroutinesKt.getSuspendLambda1())
|
||||
try testSuspendFunctionType1(f: CoroutinesKt.getSuspendCallableReference1())
|
||||
}
|
||||
|
||||
private func testSuspendFunctionSwiftImpl() throws {
|
||||
var result: String? = nil
|
||||
var error: Error? = nil
|
||||
var completionCalled = 0
|
||||
|
||||
CoroutinesKt.invoke1(block: SuspendFunction1SwiftImpl(), argument: "suspend function") { _result, _error in
|
||||
completionCalled += 1
|
||||
result = _result as? String
|
||||
error = _error
|
||||
}
|
||||
|
||||
try assertEquals(actual: completionCalled, expected: 1)
|
||||
try assertEquals(actual: result, expected: "suspend function Swift")
|
||||
try assertNil(error)
|
||||
}
|
||||
|
||||
private class SuspendFunction1SwiftImpl : KotlinSuspendFunction1 {
|
||||
func invoke(p1: Any?, completionHandler: (Any?, Error?) -> Void) {
|
||||
completionHandler("\(p1 ?? "nil") Swift", nil)
|
||||
}
|
||||
}
|
||||
|
||||
class CoroutinesTests : SimpleTestProvider {
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
test("TestCallSimple", testCallSimple)
|
||||
test("TestCall", testCall)
|
||||
test("TestOverride", testOverride)
|
||||
test("TestBridges", testBridges)
|
||||
test("TestImplicitThrows1", testImplicitThrows1)
|
||||
test("TestImplicitThrows2", testImplicitThrows2)
|
||||
test("TestSuspendFunctionType", testSuspendFunctionType)
|
||||
test("TestSuspendFunctionSwiftImpl", testSuspendFunctionSwiftImpl)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package deallocretain
|
||||
|
||||
open class DeallocRetainBase
|
||||
|
||||
fun garbageCollect() = kotlin.native.internal.GC.collect()
|
||||
|
||||
fun createWeakReference(value: Any) = kotlin.native.ref.WeakReference(value)
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
import Kt
|
||||
|
||||
// Note: these tests rely on GC assertions: without the fix and the assertions it won't actually crash.
|
||||
// GC should fire an assertion if it obtains a reference to Kotlin object that is being (or has been) deallocated.
|
||||
|
||||
private func test1() throws {
|
||||
// Attempt to make the state predictable:
|
||||
DeallocRetainKt.garbageCollect()
|
||||
|
||||
DeallocRetain.deallocated = false
|
||||
try assertFalse(DeallocRetain.deallocated)
|
||||
|
||||
try autoreleasepool {
|
||||
let obj = DeallocRetain()
|
||||
try obj.checkWeak()
|
||||
}
|
||||
|
||||
// Runs DeallocRetain.deinit:
|
||||
DeallocRetainKt.garbageCollect()
|
||||
|
||||
try assertTrue(DeallocRetain.deallocated)
|
||||
|
||||
// Might crash due to double-dispose if the dealloc applied addRef/releaseRef to reclaimed Kotlin object:
|
||||
DeallocRetainKt.garbageCollect()
|
||||
}
|
||||
|
||||
private class DeallocRetain : DeallocRetainBase {
|
||||
static var deallocated = false
|
||||
static var retainObject: DeallocRetain? = nil
|
||||
static weak var weakObject: DeallocRetain? = nil
|
||||
static var kotlinWeakRef: KotlinWeakReference<AnyObject>? = nil
|
||||
|
||||
override init() {
|
||||
super.init()
|
||||
DeallocRetain.weakObject = self
|
||||
DeallocRetain.kotlinWeakRef = DeallocRetainKt.createWeakReference(value: self)
|
||||
}
|
||||
|
||||
func checkWeak() throws {
|
||||
try assertSame(actual: DeallocRetain.weakObject, expected: self)
|
||||
try assertSame(actual: DeallocRetain.kotlinWeakRef!.value, expected: self)
|
||||
}
|
||||
|
||||
deinit {
|
||||
DeallocRetain.retainObject = self
|
||||
DeallocRetain.retainObject = nil
|
||||
|
||||
try! assertNil(DeallocRetain.weakObject)
|
||||
try! assertNil(DeallocRetain.kotlinWeakRef!.value)
|
||||
|
||||
try! assertFalse(DeallocRetain.deallocated)
|
||||
DeallocRetain.deallocated = true
|
||||
}
|
||||
}
|
||||
|
||||
class DeallocRetainTests : SimpleTestProvider {
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
test("Test1", test1)
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
package functionalTypes
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
typealias AN = Any?
|
||||
|
||||
typealias F2 = (AN, AN) -> AN
|
||||
typealias F5 = (AN, AN, AN, AN, AN) -> AN
|
||||
typealias F6 = (AN, AN, AN, AN, AN, AN,) -> AN
|
||||
typealias F32 = (AN, AN, AN, AN, AN, AN, AN, AN, AN, AN, AN, AN,
|
||||
AN, AN, AN, AN, AN, AN, AN, AN, AN, AN, AN, AN,
|
||||
AN, AN, AN, AN, AN, AN, AN, AN) -> AN
|
||||
typealias F33 = (AN, AN, AN, AN, AN, AN, AN, AN, AN, AN, AN, AN,
|
||||
AN, AN, AN, AN, AN, AN, AN, AN, AN, AN, AN, AN,
|
||||
AN, AN, AN, AN, AN, AN, AN, AN, AN) -> AN
|
||||
|
||||
fun callDynType2(list: List<F2>, param: AN) {
|
||||
val fct = list.first()
|
||||
val ret = fct(param, null)
|
||||
assertEquals(param, ret)
|
||||
}
|
||||
|
||||
fun callStaticType2(fct: F2, param: AN) {
|
||||
val ret = fct(param, null)
|
||||
assertEquals(param, ret)
|
||||
}
|
||||
|
||||
fun callDynType32(list: List<F32>, param: AN) {
|
||||
val fct = list.first()
|
||||
val ret = fct(param
|
||||
, null, null, null, null, null, null, null
|
||||
, null, null, null, null, null, null, null, null
|
||||
, null, null, null, null, null, null, null, null
|
||||
, null, null, null, null, null, null, null, null
|
||||
)
|
||||
assertEquals(param, ret)
|
||||
}
|
||||
|
||||
fun callStaticType32(fct: F32, param: AN) {
|
||||
val ret = fct(param
|
||||
, null, null, null, null, null, null, null
|
||||
, null, null, null, null, null, null, null, null
|
||||
, null, null, null, null, null, null, null, null
|
||||
, null, null, null, null, null, null, null, null
|
||||
)
|
||||
assertEquals(param, ret)
|
||||
}
|
||||
|
||||
fun callDynType33(list: List<F33>, param: AN) {
|
||||
val fct = list.first()
|
||||
val ret = fct(param
|
||||
, null, null, null, null, null, null, null
|
||||
, null, null, null, null, null, null, null, null
|
||||
, null, null, null, null, null, null, null, null
|
||||
, null, null, null, null, null, null, null, null, null
|
||||
)
|
||||
assertEquals(param, ret)
|
||||
}
|
||||
|
||||
fun callStaticType33(fct: F33, param: AN) {
|
||||
val ret = fct(param
|
||||
, null, null, null, null, null, null, null
|
||||
, null, null, null, null, null, null, null, null
|
||||
, null, null, null, null, null, null, null, null
|
||||
, null, null, null, null, null, null, null, null, null
|
||||
)
|
||||
assertEquals(param, ret)
|
||||
}
|
||||
|
||||
abstract class FHolder {
|
||||
abstract val value: Any?
|
||||
}
|
||||
|
||||
// Note: can't provoke dynamic function type conversion using list (as above) or generics
|
||||
// due to Swift <-> Obj-C interop bugs/limitations.
|
||||
// Use covariant return type instead:
|
||||
class F2Holder(override val value: F2) : FHolder()
|
||||
|
||||
fun getDynTypeLambda2(): F2Holder = F2Holder({ p1, _ -> p1 })
|
||||
fun getStaticLambda2(): F2 = { p1, _ -> p1 }
|
||||
|
||||
private fun f2(p1: AN, p2: AN): AN = p1
|
||||
|
||||
fun getDynTypeRef2(): F2Holder = F2Holder(::f2)
|
||||
fun getStaticRef2(): F2 = ::f2
|
||||
|
||||
private fun f32(
|
||||
p1: AN, p2: AN, p3: AN, p4: AN, p5: AN, p6: AN, p7: AN, p8: AN,
|
||||
p9: AN, p10: AN, p11: AN, p12: AN, p13: AN, p14: AN, p15: AN, p16: AN,
|
||||
p17: AN, p18: AN, p19: AN, p20: AN, p21: AN, p22: AN, p23: AN, p24: AN,
|
||||
p25: AN, p26: AN, p27: AN, p28: AN, p29: AN, p30: AN, p31: AN, p32: AN
|
||||
): AN = p1
|
||||
|
||||
private fun f33(
|
||||
p1: AN, p2: AN, p3: AN, p4: AN, p5: AN, p6: AN, p7: AN, p8: AN,
|
||||
p9: AN, p10: AN, p11: AN, p12: AN, p13: AN, p14: AN, p15: AN, p16: AN,
|
||||
p17: AN, p18: AN, p19: AN, p20: AN, p21: AN, p22: AN, p23: AN, p24: AN,
|
||||
p25: AN, p26: AN, p27: AN, p28: AN, p29: AN, p30: AN, p31: AN, p32: AN,
|
||||
p33: AN
|
||||
): AN = p1
|
||||
|
||||
class F32Holder(override val value: F32) : FHolder()
|
||||
|
||||
fun getDynType32(): F32Holder = F32Holder(::f32)
|
||||
fun getStaticType32(): F32 = ::f32
|
||||
|
||||
class F33Holder(override val value: F33) : FHolder()
|
||||
|
||||
fun getDynTypeRef33(): F33Holder = F33Holder(::f33)
|
||||
fun getStaticTypeRef33(): F33 = ::f33
|
||||
|
||||
fun getDynTypeLambda33(): F33Holder = F33Holder(getStaticTypeLambda33())
|
||||
fun getStaticTypeLambda33(): F33 = {
|
||||
p,
|
||||
_, _, _, _, _, _, _, _,
|
||||
_, _, _, _, _, _, _, _,
|
||||
_, _, _, _, _, _, _, _,
|
||||
_, _, _, _, _, _, _, _
|
||||
->
|
||||
p
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
import Kt
|
||||
|
||||
private func test1() {
|
||||
FunctionalTypesKt.callStaticType2(fct: foo2, param: "from swift")
|
||||
FunctionalTypesKt.callDynType2(list: [ foo2 ], param: "from swift")
|
||||
|
||||
FunctionalTypesKt.callStaticType2(fct : {a1, _ in return a1 }, param: "from swift block")
|
||||
FunctionalTypesKt.callDynType2(list: [ {a1, _ in return a1 } ], param: "from swift block")
|
||||
|
||||
// 32 params is mapped as regular; block is OK
|
||||
FunctionalTypesKt.callStaticType32(fct : {
|
||||
a1, _, _, _, _, _, _, _,
|
||||
_, _, _, _, _, _, _, _,
|
||||
_, _, _, _, _, _, _, _,
|
||||
_, _, _, _, _, _, _, _
|
||||
in return a1 }, param: "from swift block")
|
||||
|
||||
FunctionalTypesKt.callDynType32(list : [{
|
||||
a1, _, _, _, _, _, _, _,
|
||||
_, _, _, _, _, _, _, _,
|
||||
_, _, _, _, _, _, _, _,
|
||||
_, _, _, _, _, _, _, _
|
||||
in return a1 }], param: "from swift block")
|
||||
|
||||
// 33 params requires explicit implementation of KotlinFunction33
|
||||
FunctionalTypesKt.callStaticType33(fct: foo33, param: "from swift")
|
||||
FunctionalTypesKt.callDynType33(list: [ Foo33() ], param: "from swift")
|
||||
}
|
||||
|
||||
private func test2() throws {
|
||||
try assertEquals(actual: FunctionalTypesKt.getDynTypeLambda2().value("one", nil) as? String, expected: "one")
|
||||
try assertEquals(actual: FunctionalTypesKt.getStaticLambda2()("two", nil) as? String, expected: "two")
|
||||
|
||||
try assertEquals(actual: FunctionalTypesKt.getDynTypeRef2().value("three", nil) as? String, expected: "three")
|
||||
try assertEquals(actual: FunctionalTypesKt.getStaticRef2()("four", nil) as? String, expected: "four")
|
||||
|
||||
// 32 params is mapped as regular; calling result as block is OK
|
||||
try assertEquals(
|
||||
actual: FunctionalTypesKt.getDynType32().value(
|
||||
"five",
|
||||
nil, nil, nil, nil, nil, nil, nil, nil,
|
||||
nil, nil, nil, nil, nil, nil, nil, nil,
|
||||
nil, nil, nil, nil, nil, nil, nil, nil,
|
||||
nil, nil, nil, nil, nil, nil, nil
|
||||
) as? String,
|
||||
expected: "five"
|
||||
)
|
||||
|
||||
try assertEquals(
|
||||
actual: FunctionalTypesKt.getStaticType32()(
|
||||
"six",
|
||||
nil, nil, nil, nil, nil, nil, nil, nil,
|
||||
nil, nil, nil, nil, nil, nil, nil, nil,
|
||||
nil, nil, nil, nil, nil, nil, nil, nil,
|
||||
nil, nil, nil, nil, nil, nil, nil
|
||||
) as? String,
|
||||
expected: "six"
|
||||
)
|
||||
|
||||
// 33 params requires explicit invocation of KotlinFunction33.invoke
|
||||
try assertEquals(
|
||||
actual: FunctionalTypesKt.getDynTypeRef33().value.invoke(
|
||||
p1: "seven",
|
||||
p2: nil, p3: nil, p4: nil, p5: nil, p6: nil, p7: nil, p8: nil, p9: nil,
|
||||
p10: nil, p11: nil, p12: nil, p13: nil, p14: nil, p15: nil, p16: nil, p17: nil,
|
||||
p18: nil, p19: nil, p20: nil, p21: nil, p22: nil, p23: nil, p24: nil, p25: nil,
|
||||
p26: nil, p27: nil, p28: nil, p29: nil, p30: nil, p31: nil, p32: nil, p33: nil
|
||||
) as? String,
|
||||
expected: "seven"
|
||||
)
|
||||
|
||||
// static conversion is ok though.
|
||||
try assertEquals(
|
||||
actual: FunctionalTypesKt.getStaticTypeRef33()(
|
||||
"eight",
|
||||
nil, nil, nil, nil, nil, nil, nil, nil,
|
||||
nil, nil, nil, nil, nil, nil, nil, nil,
|
||||
nil, nil, nil, nil, nil, nil, nil, nil,
|
||||
nil, nil, nil, nil, nil, nil, nil, nil
|
||||
) as? String,
|
||||
expected: "eight"
|
||||
)
|
||||
|
||||
try assertEquals(
|
||||
actual: FunctionalTypesKt.getDynTypeLambda33().value.invoke(
|
||||
p1: "nine",
|
||||
p2: nil, p3: nil, p4: nil, p5: nil, p6: nil, p7: nil, p8: nil, p9: nil,
|
||||
p10: nil, p11: nil, p12: nil, p13: nil, p14: nil, p15: nil, p16: nil, p17: nil,
|
||||
p18: nil, p19: nil, p20: nil, p21: nil, p22: nil, p23: nil, p24: nil, p25: nil,
|
||||
p26: nil, p27: nil, p28: nil, p29: nil, p30: nil, p31: nil, p32: nil, p33: nil
|
||||
) as? String,
|
||||
expected: "nine"
|
||||
)
|
||||
|
||||
try assertEquals(
|
||||
actual: FunctionalTypesKt.getStaticTypeLambda33()(
|
||||
"ten",
|
||||
nil, nil, nil, nil, nil, nil, nil, nil,
|
||||
nil, nil, nil, nil, nil, nil, nil, nil,
|
||||
nil, nil, nil, nil, nil, nil, nil, nil,
|
||||
nil, nil, nil, nil, nil, nil, nil, nil
|
||||
) as? String,
|
||||
expected: "ten"
|
||||
)
|
||||
}
|
||||
|
||||
class FunctionalTypesTests : SimpleTestProvider {
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
test("Test1", test1)
|
||||
test("Test2", test2)
|
||||
}
|
||||
}
|
||||
|
||||
private func foo2(a1: Any?, _: Any?) -> Any? {
|
||||
return a1
|
||||
}
|
||||
|
||||
private func foo33(a1: Any?, _: Any?, _: Any?, _: Any?, _: Any?, _: Any?, _: Any?, _: Any?,
|
||||
_: Any?, _: Any?, _: Any?, _: Any?, _: Any?, _: Any?, _: Any?, _: Any?,
|
||||
_: Any?, _: Any?, _: Any?, _: Any?, _: Any?, _: Any?, _: Any?, _: Any?,
|
||||
_: Any?, _: Any?, _: Any?, _: Any?, _: Any?, _: Any?, _: Any?, _: Any?, _: Any?
|
||||
) -> Any? {
|
||||
return a1
|
||||
}
|
||||
|
||||
private class Foo33 : KotlinFunction33 {
|
||||
func invoke(p1: Any?, p2: Any?, p3: Any?, p4: Any?, p5: Any?, p6: Any?, p7: Any?, p8: Any?, p9: Any?,
|
||||
p10: Any?, p11: Any?, p12: Any?, p13: Any?, p14: Any?, p15: Any?, p16: Any?, p17: Any?, p18: Any?, p19: Any?,
|
||||
p20: Any?, p21: Any?, p22: Any?, p23: Any?, p24: Any?, p25: Any?, p26: Any?, p27: Any?, p28: Any?, p29: Any?,
|
||||
p30: Any?, p31: Any?, p32: Any?, p33: Any?
|
||||
) -> Any? {
|
||||
return foo33(a1: p1
|
||||
, nil, nil, nil, nil, nil, nil, nil, nil
|
||||
, nil, nil, nil, nil, nil, nil, nil, nil
|
||||
, nil, nil, nil, nil, nil, nil, nil, nil
|
||||
, nil, nil, nil, nil, nil, nil, nil, nil)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package gh4002
|
||||
|
||||
open class GH4002ArgumentBase
|
||||
class GH4002Argument : GH4002ArgumentBase()
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
import Kt
|
||||
|
||||
// See https://github.com/JetBrains/kotlin-native/issues/4002
|
||||
|
||||
class GH4002Base0 : NSObject, NSCoding {
|
||||
required init(coder: NSCoder) { fatalError() }
|
||||
|
||||
func encode(with coder: NSCoder) { fatalError() }
|
||||
}
|
||||
|
||||
class GH4002Base1<T : GH4002ArgumentBase> : GH4002Base0 {}
|
||||
|
||||
@objc(ObjCGH4002)
|
||||
class GH4002 : GH4002Base1<GH4002Argument> {}
|
||||
|
||||
private func test1() throws {
|
||||
try assertEquals(actual: String(cString: class_getName(GH4002.self)), expected: "ObjCGH4002")
|
||||
}
|
||||
|
||||
class Gh4002Tests : SimpleTestProvider {
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
test("Test1", test1)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package headerWarnings
|
||||
|
||||
// Note: the test parses the generated header with -Werror to detect warnings.
|
||||
|
||||
class TestIncompatiblePropertyTypeWarning {
|
||||
class Generic<T>(val value: T)
|
||||
|
||||
interface InterfaceWithGenericProperty<T> {
|
||||
val p: Generic<T>
|
||||
}
|
||||
|
||||
class ClassOverridingInterfaceWithGenericProperty(override val p: Generic<String>) : InterfaceWithGenericProperty<String>
|
||||
}
|
||||
|
||||
// https://github.com/JetBrains/kotlin-native/issues/3992
|
||||
class TestGH3992 {
|
||||
abstract class C(open val a: A)
|
||||
|
||||
class D(override val a: B) : C(a)
|
||||
|
||||
abstract class A
|
||||
|
||||
class B : A()
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
import Kt
|
||||
|
||||
// Note: the test parses the generated header with -Werror to detect warnings.
|
||||
// It is enough to have just Kotlin declarations at the moment.
|
||||
// Adding usages for all declarations to avoid any kind of DCE that may appear later.
|
||||
|
||||
private func testIncompatiblePropertyType() throws {
|
||||
let c = TestIncompatiblePropertyTypeWarning.ClassOverridingInterfaceWithGenericProperty(
|
||||
p: TestIncompatiblePropertyTypeWarningGeneric<NSString>(value: "cba")
|
||||
)
|
||||
|
||||
let pc: TestIncompatiblePropertyTypeWarningGeneric<NSString> = c.p
|
||||
try assertEquals(actual: pc.value, expected: "cba")
|
||||
|
||||
let i: TestIncompatiblePropertyTypeWarningInterfaceWithGenericProperty = c
|
||||
let pi: TestIncompatiblePropertyTypeWarningGeneric<AnyObject> = i.p
|
||||
try assertEquals(actual: pi.value as! String, expected: "cba")
|
||||
}
|
||||
|
||||
private func testGH3992() throws {
|
||||
let d = TestGH3992.D(a: TestGH3992.B())
|
||||
let c: TestGH3992.C = d
|
||||
|
||||
let b: TestGH3992.B = d.a
|
||||
let a: TestGH3992.A = b
|
||||
|
||||
try assertTrue(a is TestGH3992.B)
|
||||
}
|
||||
|
||||
class HeaderWarningsTests : SimpleTestProvider {
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
test("TestIncompatiblePropertyType", testIncompatiblePropertyType)
|
||||
test("TestGH3992", testGH3992)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package kt35940
|
||||
|
||||
import kotlin.reflect.*
|
||||
|
||||
@OptIn(ExperimentalAssociatedObjects::class)
|
||||
@AssociatedObjectKey
|
||||
@Retention(AnnotationRetention.BINARY)
|
||||
annotation class Associated(val kClass: KClass<*>)
|
||||
|
||||
private interface I1 {
|
||||
val s: String
|
||||
}
|
||||
|
||||
private class I1Impl : I1 {
|
||||
override val s = "zzz"
|
||||
}
|
||||
|
||||
private class C(var i1: I1?)
|
||||
|
||||
private interface I2 {
|
||||
fun bar(c: C)
|
||||
}
|
||||
|
||||
private object I2Impl : I2 {
|
||||
override fun bar(c: C) {
|
||||
c.i1 = I1Impl()
|
||||
}
|
||||
}
|
||||
|
||||
@Associated(I2Impl::class)
|
||||
private class I2ImplHolder
|
||||
|
||||
@OptIn(ExperimentalAssociatedObjects::class)
|
||||
fun testKt35940(): String {
|
||||
val i2 = I2ImplHolder::class.findAssociatedObject<Associated>()!! as I2
|
||||
val c = C(null)
|
||||
i2.bar(c)
|
||||
return c.i1!!.s
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
import Kt
|
||||
|
||||
private func test1() throws {
|
||||
try assertEquals(actual: Kt35940Kt.testKt35940(), expected: "zzz")
|
||||
}
|
||||
|
||||
class Kt35940Tests : SimpleTestProvider {
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
test("Test1", test1)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package kt38641
|
||||
|
||||
// See https://youtrack.jetbrains.com/issue/KT-38641.
|
||||
class KT38641 {
|
||||
class IntType {
|
||||
var description = 42
|
||||
}
|
||||
|
||||
class Val {
|
||||
val description = "val"
|
||||
}
|
||||
|
||||
class Var {
|
||||
var description = "var"
|
||||
}
|
||||
|
||||
class TwoProperties {
|
||||
val description = "description"
|
||||
val description_ = "description_"
|
||||
}
|
||||
|
||||
abstract class OverrideVal {
|
||||
abstract val description: String
|
||||
}
|
||||
|
||||
interface OverrideVar {
|
||||
var description: String
|
||||
}
|
||||
}
|
||||
|
||||
fun getOverrideValDescription(impl: KT38641.OverrideVal) = impl.description
|
||||
|
||||
fun getOverrideVarDescription(impl: KT38641.OverrideVar) = impl.description
|
||||
fun setOverrideVarDescription(impl: KT38641.OverrideVar, newValue: String) {
|
||||
impl.description = newValue
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
import Kt
|
||||
|
||||
private func testIntType() throws {
|
||||
let i = KT38641.IntType()
|
||||
|
||||
try assertEquals(actual: i.description_, expected: 42)
|
||||
|
||||
i.description_ = 17
|
||||
try assertEquals(actual: i.description_, expected: 17)
|
||||
}
|
||||
|
||||
private func testVal() throws {
|
||||
try assertEquals(actual: KT38641.Val().description_, expected: "val")
|
||||
}
|
||||
|
||||
private func testVar() throws {
|
||||
let v = KT38641.Var()
|
||||
|
||||
try assertEquals(actual: v.description_, expected: "var")
|
||||
|
||||
v.description_ = "newValue"
|
||||
try assertEquals(actual: v.description_, expected: "newValue")
|
||||
}
|
||||
|
||||
private func testTwoProperties() throws {
|
||||
let t = KT38641.TwoProperties()
|
||||
try assertEquals(actual: t.description_, expected: "description")
|
||||
try assertEquals(actual: t.description__, expected: "description_")
|
||||
}
|
||||
|
||||
private func testOverrideVal() throws {
|
||||
try assertEquals(actual: Kt38641Kt.getOverrideValDescription(impl: KT38641OverrideValImpl()), expected: "description_")
|
||||
}
|
||||
|
||||
class KT38641OverrideValImpl : KT38641.OverrideVal {
|
||||
override var description_: String {
|
||||
get {
|
||||
return "description_"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func testOverrideVar() throws {
|
||||
let impl = KT38641OverrideVarImpl()
|
||||
|
||||
try assertEquals(actual: Kt38641Kt.getOverrideVarDescription(impl: impl), expected: "description_")
|
||||
|
||||
Kt38641Kt.setOverrideVarDescription(impl: impl, newValue: "d")
|
||||
try assertEquals(actual: Kt38641Kt.getOverrideVarDescription(impl: impl), expected: "d")
|
||||
}
|
||||
|
||||
class KT38641OverrideVarImpl : KT38641OverrideVar {
|
||||
var description_: String = "description_"
|
||||
}
|
||||
|
||||
class Kt38641Tests : SimpleTestProvider {
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
test("TestIntType", testIntType)
|
||||
test("TestVal", testVal)
|
||||
test("TestVar", testVar)
|
||||
test("TestTwoProperties", testTwoProperties)
|
||||
test("TestOverrideVal", testOverrideVal)
|
||||
test("TestOverrideVar", testOverrideVar)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// See https://youtrack.jetbrains.com/issue/KT-39206.
|
||||
@Deprecated("Don't call this\nPlease")
|
||||
fun myFunc() = 17
|
||||
|
||||
// See https://youtrack.jetbrains.com/issue/KT-41193.
|
||||
@Deprecated(
|
||||
level = DeprecationLevel.ERROR,
|
||||
message = "This class is deprecated for removal during serialization 1.0 API stabilization.\n" +
|
||||
"For configuring Json instances, the corresponding builder function can be used instead, e.g. instead of" +
|
||||
"'Json(JsonConfiguration.Stable.copy(isLenient = true))' 'Json { isLenient = true }' should be used.\n" +
|
||||
"Instead of storing JsonConfiguration instances of the code, Json instances can be used directly:" +
|
||||
"'Json(MyJsonConfiguration.copy(prettyPrint = true))' can be replaced with 'Json(from = MyApplicationJson) { prettyPrint = true }'"
|
||||
)
|
||||
public open class JsonConfiguration
|
||||
|
||||
@Deprecated("'\"\\@\$(){}\r\n")
|
||||
class MoreTrickyChars
|
||||
@@ -0,0 +1,18 @@
|
||||
import Kt
|
||||
|
||||
private func test1() throws {
|
||||
try assertEquals(actual: Kt39206Kt.myFunc(), expected: 17)
|
||||
}
|
||||
|
||||
private func test2() throws {
|
||||
try assertTrue(MoreTrickyChars() as AnyObject is MoreTrickyChars)
|
||||
}
|
||||
|
||||
class Kt39206Tests : SimpleTestProvider {
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
test("Test1", test1)
|
||||
test("Test2", test2)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package kt41907
|
||||
|
||||
class Ckt41907
|
||||
|
||||
interface Ikt41907 {
|
||||
fun foo(c: Ckt41907)
|
||||
}
|
||||
|
||||
private class Bkt41907 {
|
||||
var c: Ckt41907? = null
|
||||
}
|
||||
|
||||
private val b = Bkt41907()
|
||||
|
||||
fun escapeC(c: Ckt41907) {
|
||||
b.c = c
|
||||
}
|
||||
|
||||
fun testKt41907(o: Ikt41907) {
|
||||
val c = Ckt41907()
|
||||
o.foo(c)
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
import Kt
|
||||
|
||||
class Ikt41907Impl : Ikt41907 {
|
||||
func foo(c: Ckt41907) {
|
||||
Kt41907Kt.escapeC(c: c)
|
||||
}
|
||||
}
|
||||
|
||||
private func test1() {
|
||||
Kt41907Kt.testKt41907(o: Ikt41907Impl())
|
||||
}
|
||||
|
||||
class Kt41907Tests : SimpleTestProvider {
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
test("Test1", test1)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package library
|
||||
|
||||
fun readDataFromLibraryClass(input: A): String {
|
||||
return input.data
|
||||
}
|
||||
|
||||
fun readDataFromLibraryInterface(input: I): String {
|
||||
return input.data
|
||||
}
|
||||
|
||||
fun readDataFromLibraryEnum(input: E): String {
|
||||
return input.data
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
import Kt
|
||||
|
||||
func testAccessClassFromLibraryWithShortName() throws {
|
||||
|
||||
let object: MyLibraryA = MyLibraryA(data: "Data from Class")
|
||||
let interface: MyLibraryI = MyLibraryA(data: "Data from Interface")
|
||||
let enumObject: MyLibraryE = MyLibraryE.b
|
||||
|
||||
|
||||
let dataFromClass = LibraryKt.readDataFromLibraryClass(input: object)
|
||||
let dataFromInterface = LibraryKt.readDataFromLibraryInterface(input: interface)
|
||||
let dataFromEnum = LibraryKt.readDataFromLibraryEnum(input: enumObject)
|
||||
|
||||
try assertEquals(actual: dataFromClass, expected: "Data from Class")
|
||||
try assertEquals(actual: dataFromInterface, expected: "Data from Interface")
|
||||
try assertEquals(actual: dataFromEnum, expected: "Enum entry B")
|
||||
}
|
||||
|
||||
class LibraryTests : SimpleTestProvider {
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
test("testAccessClassFromLibraryWithShortName", testAccessClassFromLibraryWithShortName)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package library
|
||||
|
||||
interface I {
|
||||
val data: String
|
||||
}
|
||||
|
||||
class A(override val data: String): I
|
||||
|
||||
enum class E(val data: String) {
|
||||
A("Enum entry A"),
|
||||
B("Enum entry B"),
|
||||
C("Enum entry C")
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
// All classes and methods should be used in tests
|
||||
@file:Suppress("UNUSED")
|
||||
|
||||
package localEA
|
||||
|
||||
class ArraysConstructor {
|
||||
private val memberArray: IntArray
|
||||
constructor(int1: Int, int2: Int) {
|
||||
memberArray = IntArray(2)
|
||||
set(int1, int2)
|
||||
}
|
||||
fun set(int1: Int, int2: Int) {
|
||||
memberArray[0] = int1
|
||||
memberArray[1] = int2
|
||||
}
|
||||
fun log() = "size: ${memberArray.size}, contents: ${memberArray.contentToString()}"
|
||||
}
|
||||
class ArraysDefault {
|
||||
private val memberArray = IntArray(2)
|
||||
constructor(int1: Int, int2: Int) {
|
||||
set(int1, int2)
|
||||
}
|
||||
fun set(int1: Int, int2: Int) {
|
||||
memberArray[0] = int1
|
||||
memberArray[1] = int2
|
||||
}
|
||||
fun log() = "size: ${memberArray.size}, contents: ${memberArray.contentToString()}"
|
||||
}
|
||||
class ArraysInitBlock {
|
||||
private val memberArray : IntArray
|
||||
init {
|
||||
memberArray = IntArray(2)
|
||||
}
|
||||
constructor(int1: Int, int2: Int) {
|
||||
set(int1, int2)
|
||||
}
|
||||
fun set(int1: Int, int2: Int) {
|
||||
memberArray[0] = int1
|
||||
memberArray[1] = int2
|
||||
}
|
||||
fun log() = "size: ${memberArray.size}, contents: ${memberArray.contentToString()}"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
import Kt
|
||||
|
||||
// -------- Tests --------
|
||||
|
||||
func testArraysEscapeAsParameter() throws {
|
||||
let array1 = ArraysConstructor(int1: 1, int2: 2)
|
||||
try assertEquals(actual: array1.log(), expected: "size: 2, contents: [1, 2]", "Wrong array values in class ArraysConstructor.")
|
||||
array1.set(int1: 3, int2: 4)
|
||||
try assertEquals(actual: array1.log(), expected: "size: 2, contents: [3, 4]", "Wrong array values in class ArraysConstructor.")
|
||||
|
||||
let array2 = ArraysDefault(int1: 1, int2: 2)
|
||||
try assertEquals(actual: array2.log(), expected: "size: 2, contents: [1, 2]", "Wrong array values in class ArraysDefault.")
|
||||
array2.set(int1: 3, int2: 4)
|
||||
try assertEquals(actual: array2.log(), expected: "size: 2, contents: [3, 4]", "Wrong array values in class ArraysDefault.")
|
||||
|
||||
let array3 = ArraysInitBlock(int1: 1, int2: 2)
|
||||
try assertEquals(actual: array3.log(), expected: "size: 2, contents: [1, 2]", "Wrong array values in class ArraysInitBlock.")
|
||||
array3.set(int1: 3, int2: 4)
|
||||
try assertEquals(actual: array3.log(), expected: "size: 2, contents: [3, 4]", "Wrong array values in class ArraysInitBlock.")
|
||||
}
|
||||
|
||||
// -------- Execution of the test --------
|
||||
|
||||
class LocalEATests : SimpleTestProvider {
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
test("TestArraysEscapeAsParameter", testArraysEscapeAsParameter)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package throwsEmpty
|
||||
|
||||
// Suppressing compilation error.
|
||||
// Only the generated comment is checked.
|
||||
@Suppress("THROWS_LIST_EMPTY")
|
||||
@Throws fun throwsEmpty() {}
|
||||
@@ -0,0 +1,26 @@
|
||||
import Kt
|
||||
|
||||
private func testFunctionsInDifferentFilesAreNotMangled() throws {
|
||||
try assertEquals(actual: TopLevelManglingAKt.foo(), expected: "a1")
|
||||
try assertEquals(actual: TopLevelManglingBKt.foo(), expected: "b1")
|
||||
}
|
||||
|
||||
private func testPropertiesInDifferentFilesAreNotMangled() throws {
|
||||
try assertEquals(actual: TopLevelManglingAKt.bar, expected: "a2")
|
||||
try assertEquals(actual: TopLevelManglingBKt.bar, expected: "b2")
|
||||
}
|
||||
|
||||
private func testFunctionsInSameFileAreMangled() throws {
|
||||
try assertEquals(actual: TopLevelManglingAKt.sameNumber(value: Int32(1)), expected: 1)
|
||||
try assertEquals(actual: TopLevelManglingAKt.sameNumber(value_: Int64(2)), expected: 2)
|
||||
}
|
||||
|
||||
class TopLevelManglingTests : SimpleTestProvider {
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
test("TestFunctionsInDifferentFilesAreNotMangled", testFunctionsInDifferentFilesAreNotMangled)
|
||||
test("TestPropertiesInDifferentFilesAreNotMangled", testPropertiesInDifferentFilesAreNotMangled)
|
||||
test("TestFunctionsInSameFileAreMangled", testFunctionsInSameFileAreMangled)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package topLevelManglingA
|
||||
|
||||
fun foo() = "a1"
|
||||
val bar = "a2"
|
||||
|
||||
fun sameNumber(value: Int) = value
|
||||
fun sameNumber(value: Long) = value
|
||||
@@ -0,0 +1,4 @@
|
||||
package topLevelManglingB
|
||||
|
||||
fun foo() = "b1"
|
||||
val bar = "b2"
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user