Local EA. Fix for objects which can escape as parameter value [KT-40367]
This commit is contained in:
committed by
LepilkinaElena
parent
7cef940747
commit
5ed5bb75a7
+3
@@ -139,6 +139,9 @@ internal object LocalEscapeAnalysis {
|
||||
connectObjects(node, node.array.node)
|
||||
}
|
||||
}
|
||||
is DataFlowIR.Node.Parameter -> {
|
||||
node.escapeState = EscapeState.ARG_ESCAPE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -450,6 +450,30 @@ __attribute__((swift_name("LibraryKt")))
|
||||
+ (NSString *)readDataFromLibraryEnumInput:(KtE *)input __attribute__((swift_name("readDataFromLibraryEnum(input:)")));
|
||||
@end;
|
||||
|
||||
__attribute__((objc_subclassing_restricted))
|
||||
__attribute__((swift_name("ArraysConstructor")))
|
||||
@interface KtArraysConstructor : KtBase
|
||||
- (instancetype)initWithInt1:(int32_t)int1 int2:(int32_t)int2 __attribute__((swift_name("init(int1:int2:)"))) __attribute__((objc_designated_initializer));
|
||||
- (void)setInt1:(int32_t)int1 int2:(int32_t)int2 __attribute__((swift_name("set(int1:int2:)")));
|
||||
- (NSString *)log __attribute__((swift_name("log()")));
|
||||
@end;
|
||||
|
||||
__attribute__((objc_subclassing_restricted))
|
||||
__attribute__((swift_name("ArraysDefault")))
|
||||
@interface KtArraysDefault : KtBase
|
||||
- (instancetype)initWithInt1:(int32_t)int1 int2:(int32_t)int2 __attribute__((swift_name("init(int1:int2:)"))) __attribute__((objc_designated_initializer));
|
||||
- (void)setInt1:(int32_t)int1 int2:(int32_t)int2 __attribute__((swift_name("set(int1:int2:)")));
|
||||
- (NSString *)log __attribute__((swift_name("log()")));
|
||||
@end;
|
||||
|
||||
__attribute__((objc_subclassing_restricted))
|
||||
__attribute__((swift_name("ArraysInitBlock")))
|
||||
@interface KtArraysInitBlock : KtBase
|
||||
- (instancetype)initWithInt1:(int32_t)int1 int2:(int32_t)int2 __attribute__((swift_name("init(int1:int2:)"))) __attribute__((objc_designated_initializer));
|
||||
- (void)setInt1:(int32_t)int1 int2:(int32_t)int2 __attribute__((swift_name("set(int1:int2:)")));
|
||||
- (NSString *)log __attribute__((swift_name("log()")));
|
||||
@end;
|
||||
|
||||
__attribute__((objc_subclassing_restricted))
|
||||
__attribute__((swift_name("ThrowsEmptyKt")))
|
||||
@interface KtThrowsEmptyKt : KtBase
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user