KT-59801 [FIR] scripting: explicit import breaks reference shortening

FIR-tree for scripts is built either for KtScript or KtFile depending on
the file structure. The presence of import statements results in KtFile.
There are lazy trees (some nodes are stubs) that are not yet supported
for scripts. We build such ones for KtFile case.

This commit prevents lazy tree construction for scripts at references
shortening.

^KT-59801 fixed
This commit is contained in:
Andrei Klunnyi
2023-07-10 15:36:19 +02:00
parent 0c6e2f135e
commit 0bc3fc9203
@@ -94,14 +94,15 @@ internal class KtFirReferenceShortener(
kDocQualifiersToShorten = emptyList(),
)
val towerContext = when (declarationToVisit) {
is KtFile -> {
LowLevelFirApiFacadeForResolveOnAir.getOnAirTowerDataContextProviderForTheWholeFile(firResolveSession, declarationToVisit)
}
else -> {
val towerContext =
if (declarationToVisit !is KtFile || declarationToVisit.isScript()) {
LowLevelFirApiFacadeForResolveOnAir.getOnAirGetTowerContextProvider(firResolveSession, declarationToVisit)
} else {
LowLevelFirApiFacadeForResolveOnAir.getOnAirTowerDataContextProviderForTheWholeFile(
firResolveSession,
declarationToVisit
)
}
}
//TODO: collect all usages of available symbols in the file and prevent importing symbols that could introduce name clashes, which
// may alter the meaning of existing code.
val collector = ElementsToShortenCollector(