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!
After #123, every
visit*definition method takesenclosingSource: KtSourceElement? = null, and every caller inAnalyzerCheckers.ktpasses the same value:declaration.source.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_rangefrom the output. We hit this in mozsearch/semanticdb-kotlinc#23 when a fork-specificSemanticEnumEntryCheckerquietly missed the field.What if we instead dropped the parameter and derived it inside the visitor from the
FirXargument it already accepts?Benefits:
visit*methods or new checker implementations can't silently missenclosing_range; the visitor owns the derivation.enclosingSource = sourcearguments fromAnalyzerCheckers.kt.enclosing_rangemaps to each FirX type.Happy to send a patch if that suggestion works for you!