Skip to content
This repository was archived by the owner on Jul 2, 2026. It is now read-only.
This repository was archived by the owner on Jul 2, 2026. It is now read-only.

enclosingSource parameter on visit* methods is always declaration.source #142

Description

@rvandermeulen

After #123, every visit* definition method takes enclosingSource: KtSourceElement? = null, and every caller in AnalyzerCheckers.kt passes the same value: declaration.source.

val source = declaration.source ?: return
visitor?.visitClassOrObject(declaration, ..., context, enclosingSource = source)
visitor?.visitPrimaryConstructor(declaration, ..., context, enclosingSource = source)
// ... 6 more, all identical

The optional/nullable parameter buys nothing: no caller omits it, no caller passes a different value. And because it's optional, forgetting it silently drops enclosing_range from the output. We hit this in mozsearch/semanticdb-kotlinc#23 when a fork-specific SemanticEnumEntryChecker quietly missed the field.

What if we instead dropped the parameter and derived it inside the visitor from the FirX argument it already accepts?

fun visitClassOrObject(firClass: FirClassLikeDeclaration, element: KtSourceElement, context: CheckerContext) {
    val enclosing = firClass.source ?: element
    cache[firClass.symbol].with(firClass.symbol).emitAll(element, Role.DEFINITION, context, enclosing)
}

Benefits:

  • New visit* methods or new checker implementations can't silently miss enclosing_range; the visitor owns the derivation.
  • Removes eight redundant enclosingSource = source arguments from AnalyzerCheckers.kt.
  • Single source of truth for how enclosing_range maps to each FirX type.

Happy to send a patch if that suggestion works for you!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions