Skip to content

TypeTable round-trip drops method type info for Kotlin top-level extension functions #7434

@steve-aom-elliott

Description

@steve-aom-elliott

When a Kotlin source file invokes a top-level extension function from a library on the classpath (e.g. com.fasterxml.jackson.module.kotlin.jacksonObjectMapper()), the resulting J.MethodInvocation has getMethodType() == null whenever KotlinParser resolves the classpath via a TypeTable-synthesized directory rather than the original jar. As a result, MethodMatcher and UsesMethod cannot match the call, even though the import is present.

This affects any recipe that needs to recognize Kotlin top-level functions, including the mod CLI flow that ships LSTs with TypeTable-derived classpaths.

Workaround

Recipes that need to detect such calls have to fall back to looser preconditions (e.g. UsesType on a return type, or scanning the compilation unit for the import) until the underlying TypeTable round-trip is fixed. The precondition list in MigrateMapperSettersToBuilder.java is a concrete example.

Fix

  1. Stopping the TypeTable writer from filtering out ACC_SYNTHETIC methods (Kotlin extension functions compile to public static final synthetic on a *Kt facade).
  2. Capturing the InnerClasses attribute on round-tripped classes so Kotlin FIR can resolve methods whose `@kotlin.Metadata.d1` protobuf references inner classes.
  3. Persisting META-INF/*.kotlin_module resources alongside synthesized .class files so the resolver can find each top-level function's facade owner.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions