Fix Kotlin parser handling of unresolved callable references#7469
Merged
knutwannheden merged 1 commit intomainfrom Apr 24, 2026
Merged
Fix Kotlin parser handling of unresolved callable references#7469knutwannheden merged 1 commit intomainfrom
knutwannheden merged 1 commit intomainfrom
Conversation
`visitCallableReferenceExpression` looked up the FIR for the callable reference's right-hand side (`expression.getCallableReference()`) to decide whether to accept the reference. When the type is unresolved (e.g. `JavaLanguageVersion::of` in a `.gradle.kts` parsed without the full Gradle classpath), the RHS maps to `FirErrorNamedReferenceImpl` even though the whole expression still maps cleanly to `FirCallableReferenceAccess`. The visitor then threw, the declaration bubbled up into `J.Unknown`, and its PSI text range (which includes the trailing newline) got duplicated against the file's EOF space, causing a print idempotency failure. Check the FIR mapping of the whole expression for validity instead, and use the reference-level FIR only for optional type resolution. Types simply remain `null` when the reference cannot be resolved, which matches how other unresolved-type scenarios are handled. Re-enables the previously `@Disabled` `firCallableReferenceAccess` regression test.
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.
Motivation
Parsing the
buildSrc/build.gradle.ktsfile from thegoogle/daggerrepo fails with a print idempotency error:The root cause is
KotlinTreeParserVisitor#visitCallableReferenceExpression. It was checking the FIR mapping of the callable reference's right-hand-side name (expression.getCallableReference()). When the receiver type is unresolved — e.g.JavaLanguageVersion::ofin a.gradle.ktsparsed without the full Gradle classpath — the RHS maps toFirErrorNamedReferenceImpl, even though the whole expression still maps cleanly toFirCallableReferenceAccess. The visitor threw, the wholeKtScriptdeclaration bubbled up intoJ.Unknown, and theJ.UnknownPSI text range (which included the trailing\n) then got duplicated against the file-level EOF space — producing the extra blank line on print.Summary
KotlinTreeParserVisitor#visitCallableReferenceExpressionnow validates the expression-level FIR (FirCallableReferenceAccess) rather than the RHS-name FIR, and uses the RHS FIR only for optional type resolution; types remainnullwhen the reference is unresolved, consistent with other unresolved-type paths.@DisabledMemberReferenceTest#firCallableReferenceAccessregression test.CompilationUnitTest#unresolvedCallableReference(.ktspath) andGradleParserTest#kotlinDslWithUnresolvedCallableReference(Gradle entry point) covering the reproduction.Test plan
MemberReferenceTest#firCallableReferenceAccess(re-enabled) passesCompilationUnitTest#unresolvedCallableReferencepassesGradleParserTest#kotlinDslWithUnresolvedCallableReferencepassesrewrite-kotlintest suite passesrewrite-gradletest suite passes