Skip to content

fix(compiler-plugin): fix K2 story discovery and update test harness for Kotlin 2.3 - #116

Merged
JSMonk merged 1 commit into
Kotlin:mainfrom
aryapreetam:fix/k2-compiler-lowering
Oct 12, 2026
Merged

JSMonk merged 1 commit into
Kotlin:mainfrom
aryapreetam:fix/k2-compiler-lowering

Conversation

@aryapreetam

@aryapreetam aryapreetam commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Problem

  1. Empty story discovery in K2: In K2 compiler pipelines, delegated property backing fields do not consistently carry IrDeclarationOrigin.PROPERTY_DELEGATE. As a result, isStory returned false, and the compiler plugin discovered 0 stories.
  2. Unsafe metadata cast: file.metadata as FirMetadataSource caused a ClassCastException when processing files where metadata is not represented as FirMetadataSource.
  3. Test harness failure on Kotlin 2.3: Running ./gradlew :modules:compiler-plugin:test failed with AbstractMethodError in MainComponentRegistrar because kotlinCompileTesting 0.11.0 does not implement
    CompilerPluginRegistrar.getPluginId(), introduced in Kotlin 2.3.0.

Solution

  • Matched story property delegates by checking backingField?.type == factoryType directly in MentionAllStoriesGettersInsideMainFunctionLowering.
  • Changed file.metadata as FirMetadataSource to a safe cast as?.
  • Bumped kotlinCompileTesting from 0.11.0 to 0.12.1 in gradle/libs.versions.toml.

Verification

  • ./gradlew :modules:compiler-plugin:test (3/3 tests pass)
  • ./gradlew spotlessCheck (passes)
  • ./gradlew :examples:compileStoriesKotlinDesktop (builds successfully)
  • ./gradlew :examples:compileStoriesKotlinWasmJs (builds successfully)
Visual Verification (Desktop & Wasm)

Desktop (./gradlew :examples:desktopStoriesRun)

desktop-stories-run

Web / Wasm (./gradlew :examples:wasmJsBrowserStoriesDevelopmentRun)

wasm-stories-run

…for Kotlin 2.3

- Update kotlinCompileTesting to 0.12.1 in libs.versions.toml to support  CompilerPluginRegistrar.pluginId in Kotlin 2.3+.
- Use safe cast for FirMetadataSource in AddCodeSnippetToStoriesLowering to prevent ClassCastException.
- Match story property delegate by factory type directly instead of relying  on IrDeclarationOrigin.PROPERTY_DELEGATE, which is not consistently present in K2.
@JSMonk
JSMonk requested review from JSMonk and eymar October 12, 2026 15:43
@JSMonk
JSMonk merged commit 2447771 into Kotlin:main Oct 12, 2026
2 checks passed
@aryapreetam
aryapreetam deleted the fix/k2-compiler-lowering branch October 12, 2026 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants