Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Not recognized dependency from "when-is" statement since kotlin 2.4.20-Beta2/RC

Open
#1,699 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@Boulea7 is already working on this.

Since Oct 15, 2026.

  • #1762 by @Boulea7 — open

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
java, kotlin
Domain
testing

Research direction

Start from the reproducing project (github.com/seregamorph/kotlin-arch-unit-issue, mvn clean test) and dump the compiled SampleFilter bytecode with javap -c at Kotlin 2.4.20 vs 2.4.10 to see how the is SampleData -> branch is now emitted. In ArchUnit, trace ClassFileImporter dependency resolution from the bytecode instruction used for type checks (the path behind getDirectDependenciesToSelf) and compare it with what the new bytecode contains. Done = the ArchUnit test in the repro reports SampleData as a dependency again, with existing ArchUnit tests still passing; note the linked KT-88509 has no confirmed root cause yet.

Written by the indexing model from the issue text.

Description

Please note, that this issue has related https://youtrack.jetbrains.com/issue/KT-88509/archunit-does-not-recognize-when-if-usage-since-2.4.20-Beta2 as the root cause is not clear so far.

We have arch-unit tests that inspect usages of classes (like exceptions, data classes, etc.) and fail in case if it locates classes which are not actually used. Since 2.4.20-Beta2 (and latest 2.4.20-RC) these tests fail for scenarios when the checked class is only used within when-is statement. Note: this is probably an issue of arch-unit, but I cannot say for sure. Also confusing here is that this behaviour changes within a minor update 2.4.10-2.4.20(now RC). I can only guess there, the when-is semantics is changed, which originally expected to match instaceof expression.

Reproducing snippet:

data class SampleData(private val id: Int)

object SampleFilter {
    fun isSampleData(obj: Any): Boolean {
        val result = when (obj) {
            // please pay attention: we need this first check (otherwise the problem is not reproduced)
            is String -> false
            // then - check Kotlin type - expected that archunit "sees" it
            is SampleData -> true
            else -> false
        }
        return result
    }
}

and arch-unit test

    @Test
    public void shouldHaveUsages() {
        JavaClasses classes = new ClassFileImporter()
                .withImportOption(ImportOption.Predefined.DO_NOT_INCLUDE_TESTS)
                .importPackages("com.example");
        JavaClass sampleData = classes.get(SampleData.class);

        Set<Dependency> dependenciesToSelf = sampleData.getDirectDependenciesToSelf();

        Set<String> originClassNames = dependenciesToSelf.stream()
                .map(dependency -> dependency.getOriginClass().getName())
                .filter(name -> !name.equals(SampleData.class.getName()))
                .collect(Collectors.toSet());

        assertFalse(
                originClassNames.isEmpty(),
                "Expected " + SampleData.class.getName() + " to have usages, but found none."
        );
    }

The library is com.tngtech.archunit:archunit:1.5.0

Reproducing project: https://github.com/seregamorph/kotlin-arch-unit-issue :

  • run mvn clean test to ensure it's reproduced
  • downgrade kotlin to 2.4.10 and see there is no problem
Dominant language
Java
Stars
3.9k
Forks
350
Avg merge
1d 20h
Merged PRs (30d)
22

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from TNG/ArchUnit

All issues in TNG/ArchUnit

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.