Skip to content

Commit 4af6494

Browse files
authored
Render Pair and Triple (#712)
1 parent 120aa83 commit 4af6494

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

src/jvm/main/org/jetbrains/kotlinx/lincheck/strategy/managed/ObjectLabelFactory.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ object ObjectLabelFactory {
3838
if (any.javaClass.isEnum) {
3939
return (any as Enum<*>).name
4040
}
41+
if (any is Pair<*, *>) {
42+
return "(${adornedStringRepresentation(any.first)}, ${adornedStringRepresentation(any.second)})"
43+
}
44+
if (any is Triple<*, *, *>) {
45+
return "(${adornedStringRepresentation(any.first)}, ${adornedStringRepresentation(any.second)}, ${adornedStringRepresentation(any.third)})"
46+
}
4147
// Instead of java.util.HashMap$Node@3e2a56 show Node@1.
4248
// It is better not to use `toString` in general since
4349
// we usually care about references to certain objects,
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Lincheck
3+
*
4+
* Copyright (C) 2019 - 2025 JetBrains s.r.o.
5+
*
6+
* This Source Code Form is subject to the terms of the
7+
* Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed
8+
* with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
*/
10+
11+
package org.jetbrains.kotlinx.lincheck_test.representation
12+
13+
class PairTripleRenderingTest : BaseTraceRepresentationTest("pair_triple_rendering") {
14+
var pair = 1 to 2
15+
16+
override fun operation() {
17+
foo(Triple("a", 3, 4.0))
18+
}
19+
20+
fun foo(triple: Triple<String, Int, Double>) = pair to triple
21+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
= Invalid execution results =
2+
| ----------------- |
3+
| Thread 1 |
4+
| ----------------- |
5+
| operation(): void |
6+
| ----------------- |
7+
8+
The following interleaving leads to the error:
9+
| ----------- |
10+
| Thread 1 |
11+
| ----------- |
12+
| operation() |
13+
| ----------- |
14+
15+
Detailed trace:
16+
| ----------------------------------------------------------------------------------------------------------------- |
17+
| Thread 1 |
18+
| ----------------------------------------------------------------------------------------------------------------- |
19+
| operation() |
20+
| foo(("a", 3, 4.0)): ((1, 2), ("a", 3, 4.0)) at PairTripleRenderingTest.operation(PairTripleRenderingTest.kt:17) |
21+
| pair ➜ (1, 2) at PairTripleRenderingTest.foo(PairTripleRenderingTest.kt:20) |
22+
| result: void |
23+
| ----------------------------------------------------------------------------------------------------------------- |

0 commit comments

Comments
 (0)