Repository navigation
ADFA-6564: Analyse completion's file copy in a dangling module - #2196
Merged
Merged
Conversation
Typing any non-newline character triggers completion, which analyses a placeholder copy of the file. getModuleImpl mapped that copy into its original's source module through originalKtFile.backingFilePath, so when completion was the first analysis after an edit minted a new KtFile, FIR saw the class declared twice and diagnostics reported the whole class as a redeclaration of itself. Copies now go through computeSpecialModule, which gives them a dangling module whose context is the original's. Live files are unaffected: the check is on copyOrigin, not isDangling, because the live in-memory files report isDangling too.
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.
Tip: disable this comment in your organization's Code Review settings.
Contributor
Daniel-ADFA
approved these changes
Oct 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ADFA-6564
Fixes #2152: typing a space inside a function body marked the whole class as
Redeclaration: class LocalC : Any.Root cause
Not the ADFA-4165 / ADFA-5231 bug (two live
KtFileinstances for one path); the pin from ADR 0015 still holds. Here the secondLocalCis completion's placeholder copy of the file.Any non-newline keystroke triggers completion, which analyses that copy through
analyzingVariant.ProjectStructureProvider.getModuleImplresolved the copy's module throughoriginalKtFile.backingFilePath, so the copy became an ordinary member of the original's source module. When completion was the first analysis after an edit minted a newKtFile, FIR sawLocalCdeclared twice: once in the live file, once in the copy. The error then stayed until the next edit.A newline does not trigger completion, which is why the report says "any non-newline character".
Fix
Copies (
copyOrigin != null) now go through the base class'scomputeSpecialModule, which gives them a dangling-file module whose context is the original's module. The check is oncopyOrigin, notisDangling, because our live in-memory files also reportisDangling, and they must stay in their source module.Commits
ProjectStructureProvider.kt, no functional change. Touching the file pulled it under the ratchet.Verification
InBodyEditRedeclarationTest: open, diagnose, type a space in the body, run completion's analysis step, diagnose again. Fails without the fix withCLASSIFIER_REDECLARATION: Redeclaration: class LocalC : Any, passes with it.:lsp:kotlin:testV7DebugUnitTest: 589 tests, 0 failures.Found 0 diagnostics(26.44:Found 1), and completion still offers both library (print) and same-file (ori) members.analyzingVariantis the only place in:lsp:kotlinthat creates a file copy.No UI change, so no font-scale check.