Skip to content

Commit e125949

Browse files
CaelmBleiddLipen
authored andcommitted
Fixes with arrays
1 parent 42e0308 commit e125949

4 files changed

Lines changed: 30 additions & 2 deletions

File tree

usvm-ts/src/main/kotlin/org/usvm/machine/interpreter/TsInterpreter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ class TsInterpreter(
738738
state.pathConstraints += mkNot(mkHeapRefEq(ref, mkUndefinedValue()))
739739

740740
if (parameterType is EtsArrayType) {
741-
state.pathConstraints += state.memory.types.evalTypeEquals(ref, parameterType)
741+
state.pathConstraints += state.memory.types.evalIsSubtype(ref, parameterType)
742742
return@run
743743
}
744744

usvm-ts/src/test/kotlin/org/usvm/samples/arrays/ArrayMethods.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,24 @@ class ArrayMethods : TsMethodTestRunner() {
2525
)
2626
}
2727

28+
@Test
29+
fun testArrayPushIntoNumber() {
30+
val method = getMethod("arrayPushIntoNumber")
31+
discoverProperties<TsTestValue.TsArray<*>, TsTestValue.TsArray<*>>(
32+
method = method,
33+
{ x, r -> x.values.size == r.values.size - 1 && (r.values.last() as TsTestValue.TsNumber).number == 123.0 }
34+
)
35+
}
36+
37+
@Test
38+
fun testArrayPushIntoUnknown() {
39+
val method = getMethod("arrayPushIntoUnknown")
40+
discoverProperties<TsTestValue.TsArray<*>, TsTestValue.TsArray<*>>(
41+
method = method,
42+
{ x, r -> x.values.size == r.values.size - 1 && (r.values.last() as TsTestValue.TsNumber).number == 123.0 }
43+
)
44+
}
45+
2846
@Test
2947
fun testArrayPop() {
3048
val method = getMethod("arrayPop")

usvm-ts/src/test/kotlin/org/usvm/util/TsTestResolver.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ open class TsTestStateResolver(
308308
"Other sorts must be resolved above, but got: $sort"
309309
}
310310

311-
val lValue = mkArrayIndexLValue(sort, concreteRef, index, type)
311+
val lValue = mkArrayIndexLValue(sort, heapRef, index, type)
312312
val value = memory.read(lValue)
313313

314314
if (value.sort is UAddressSort) {

usvm-ts/src/test/resources/samples/arrays/ArrayMethods.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ class ArrayMethods {
1212
}
1313
}
1414

15+
arrayPushIntoNumber(x: number[]) {
16+
x.push(123);
17+
return x;
18+
}
19+
20+
arrayPushIntoUnknown(x: any[]) {
21+
x.push(123);
22+
return x;
23+
}
24+
1525
arrayPop(x: boolean) {
1626
const arr = [10, 20, 30];
1727
const lastElement = arr.pop();

0 commit comments

Comments
 (0)