# Kotlin: S3923 when branches code duplication should not be an issue

**URL:** <https://community.sonarsource.com/t/kotlin-s3923-when-branches-code-duplication-should-not-be-an-issue/183577>\
**Category:** Report False-positive / False-negative...\
**Tags:** kotlin\
**Created:** [June 16, 2026, 9:03am UTC](https://community.sonarsource.com/t/kotlin-s3923-when-branches-code-duplication-should-not-be-an-issue/183577 "2026-06-16T09:03:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![matthieu](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@matthieu](https://community.sonarsource.com/u/matthieu)\
**Post date:** [June 16, 2026, 9:03am UTC](https://community.sonarsource.com/t/kotlin-s3923-when-branches-code-duplication-should-not-be-an-issue/183577/1 "2026-06-16T09:03:16Z")

</div>

**Language**

Kotlin 2.3.21

**Rule**

S3923 : All branches in a conditional structure should not have exactly the same implementation

**Why it is a false-positive**

In Kotlin, when several types in a sealed hierarchy have a common field, we can’t extract it in a single branch. It forces to duplicate the content of branches.

Kotlin should not issue an issue in this case.

**Using**

SonarQube Server v2026.3 (123014)

**Example**

```auto
sealed interface X
data object A: X
data class B(val s: String): X 
data class C(val s: String): X

fun foo(s: String) = s + "foo"

fun main() {
    val b: X = B("bar")
	when (b) {
        A -> ""
        is B -> foo(b.s)
        is C -> foo(b.s)
    }
}

```

---

<div class="post-metadata">

**Author:** ![peter.trifanov](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/peter.trifanov/32/53693_2.png) [@peter.trifanov](https://community.sonarsource.com/u/peter.trifanov)\
**Post date:** [August 12, 2026, 10:00am UTC](https://community.sonarsource.com/t/kotlin-s3923-when-branches-code-duplication-should-not-be-an-issue/183577/6 "2026-08-12T10:00:32Z")

</div>

Hello @matthieu !

Sorry for the late answer. You are right, Kotlin doesn’t have structural typing, so the example you provided can be made compliant only by introducing an interface `interface S { val s: String }` and making both `B` and `C` implement it. However, this can be an overkill sometimes.

I created a ticket to track improvement for this rule, though I can’t say when exactly it will be implemented.

Hope that helps,

Peter
