Skip to content

Render Pair and Triple in the trace #712

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ object ObjectLabelFactory {
if (any.javaClass.isEnum) {
return (any as Enum<*>).name
}
if (any is Pair<*, *>) {
return "(${adornedStringRepresentation(any.first)}, ${adornedStringRepresentation(any.second)})"
}
if (any is Triple<*, *, *>) {
return "(${adornedStringRepresentation(any.first)}, ${adornedStringRepresentation(any.second)}, ${adornedStringRepresentation(any.third)})"
}
// Instead of java.util.HashMap$Node@3e2a56 show Node@1.
// It is better not to use `toString` in general since
// we usually care about references to certain objects,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Lincheck
*
* Copyright (C) 2019 - 2025 JetBrains s.r.o.
*
* This Source Code Form is subject to the terms of the
* Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed
* with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

package org.jetbrains.kotlinx.lincheck_test.representation

class PairTripleRenderingTest : BaseTraceRepresentationTest("pair_triple_rendering") {
var pair = 1 to 2

override fun operation() {
foo(Triple("a", 3, 4.0))
}

fun foo(triple: Triple<String, Int, Double>) = pair to triple
}
23 changes: 23 additions & 0 deletions src/jvm/test/resources/expected_logs/pair_triple_rendering.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
= Invalid execution results =
| ----------------- |
| Thread 1 |
| ----------------- |
| operation(): void |
| ----------------- |

The following interleaving leads to the error:
| ----------- |
| Thread 1 |
| ----------- |
| operation() |
| ----------- |

Detailed trace:
| ----------------------------------------------------------------------------------------------------------------- |
| Thread 1 |
| ----------------------------------------------------------------------------------------------------------------- |
| operation() |
| foo(("a", 3, 4.0)): ((1, 2), ("a", 3, 4.0)) at PairTripleRenderingTest.operation(PairTripleRenderingTest.kt:17) |
| pair ➜ (1, 2) at PairTripleRenderingTest.foo(PairTripleRenderingTest.kt:20) |
| result: void |
| ----------------------------------------------------------------------------------------------------------------- |