KTIJ-25232 [FIR IDE] Do not shorten properties with non-trivial receiver
If property call receiver is something real (like another property or a function call), then it should not be shortened because the semantics might change ^KTIJ-25232 Fixed
This commit is contained in:
+4
@@ -874,6 +874,10 @@ private class ElementsToShortenCollector(
|
|||||||
val availableCallables = shorteningContext.findPropertiesInScopes(scopes, callableSymbol.name)
|
val availableCallables = shorteningContext.findPropertiesInScopes(scopes, callableSymbol.name)
|
||||||
|
|
||||||
val firPropertyAccess = qualifiedProperty.getOrBuildFir(firResolveSession) as? FirQualifiedAccessExpression ?: return
|
val firPropertyAccess = qualifiedProperty.getOrBuildFir(firResolveSession) as? FirQualifiedAccessExpression ?: return
|
||||||
|
|
||||||
|
// if explicit receiver is a property access or a function call, we cannot shorten it
|
||||||
|
if (firPropertyAccess.explicitReceiver !is FirResolvedQualifier) return
|
||||||
|
|
||||||
if (availableCallables.isNotEmpty() && shortenIfAlreadyImported(firPropertyAccess, callableSymbol, referenceExpression)) {
|
if (availableCallables.isNotEmpty() && shortenIfAlreadyImported(firPropertyAccess, callableSymbol, referenceExpression)) {
|
||||||
addElementToShorten(ShortenQualifier(qualifiedProperty))
|
addElementToShorten(ShortenQualifier(qualifiedProperty))
|
||||||
return
|
return
|
||||||
|
|||||||
+12
@@ -298,6 +298,18 @@ public class FirIdeNormalAnalysisSourceModuleReferenceShortenerTestGenerated ext
|
|||||||
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/sameTypeNamesWithinSameScopes.kt");
|
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/sameTypeNamesWithinSameScopes.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("selfPropertyChain.kt")
|
||||||
|
public void testSelfPropertyChain() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/selfPropertyChain.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("selfPropertyChain1.kt")
|
||||||
|
public void testSelfPropertyChain1() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/selfPropertyChain1.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("shortenAlreadyImportedClass.kt")
|
@TestMetadata("shortenAlreadyImportedClass.kt")
|
||||||
public void testShortenAlreadyImportedClass() throws Exception {
|
public void testShortenAlreadyImportedClass() throws Exception {
|
||||||
|
|||||||
+12
@@ -298,6 +298,18 @@ public class FirStandaloneNormalAnalysisSourceModuleReferenceShortenerTestGenera
|
|||||||
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/sameTypeNamesWithinSameScopes.kt");
|
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/sameTypeNamesWithinSameScopes.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("selfPropertyChain.kt")
|
||||||
|
public void testSelfPropertyChain() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/selfPropertyChain.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("selfPropertyChain1.kt")
|
||||||
|
public void testSelfPropertyChain1() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/selfPropertyChain1.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("shortenAlreadyImportedClass.kt")
|
@TestMetadata("shortenAlreadyImportedClass.kt")
|
||||||
public void testShortenAlreadyImportedClass() throws Exception {
|
public void testShortenAlreadyImportedClass() throws Exception {
|
||||||
|
|||||||
analysis/analysis-api/testData/components/referenceShortener/referenceShortener/selfPropertyChain.kt
Vendored
+15
@@ -0,0 +1,15 @@
|
|||||||
|
// FILE: main.kt
|
||||||
|
package foo
|
||||||
|
|
||||||
|
class Foo {
|
||||||
|
val self = this
|
||||||
|
|
||||||
|
fun selfFun(): Foo = this
|
||||||
|
|
||||||
|
<expr>
|
||||||
|
fun check() {
|
||||||
|
self.self
|
||||||
|
selfFun().self
|
||||||
|
}
|
||||||
|
</expr>
|
||||||
|
}
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
Before shortening: fun check() {
|
||||||
|
self.self
|
||||||
|
selfFun().self
|
||||||
|
}
|
||||||
|
with DO_NOT_SHORTEN:
|
||||||
|
with SHORTEN_IF_ALREADY_IMPORTED:
|
||||||
|
with SHORTEN_AND_IMPORT:
|
||||||
|
with SHORTEN_AND_STAR_IMPORT:
|
||||||
+15
@@ -0,0 +1,15 @@
|
|||||||
|
// FILE: main.kt
|
||||||
|
package foo
|
||||||
|
|
||||||
|
object Foo {
|
||||||
|
val self = this
|
||||||
|
|
||||||
|
fun selfFun(): Foo = this
|
||||||
|
|
||||||
|
<expr>
|
||||||
|
fun check() {
|
||||||
|
self.self
|
||||||
|
selfFun().self
|
||||||
|
}
|
||||||
|
</expr>
|
||||||
|
}
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
Before shortening: fun check() {
|
||||||
|
self.self
|
||||||
|
selfFun().self
|
||||||
|
}
|
||||||
|
with DO_NOT_SHORTEN:
|
||||||
|
with SHORTEN_IF_ALREADY_IMPORTED:
|
||||||
|
with SHORTEN_AND_IMPORT:
|
||||||
|
with SHORTEN_AND_STAR_IMPORT:
|
||||||
Reference in New Issue
Block a user