Custom property accessor has this property set and hence it make sense
for the default accessor to have it too. Also, FE1.0's counterpart
has this bit set and it's returned through the analysis API.
Note that the current FE1.0 implementation still has some limitations
1. only references used as receiver are being considered for smartcast.
2. Somehow the smartcast information is not retained if the for generic
typed receivers. See multiSmartcastAsReceiver_stable.descriptors.txt
Currently the shortener ignores the created FirProperty, as a result,
any annotations declared on the getter or setter are ignored. The test
is added in Intellij repo.
Since many labels are not present in the FIR tree, this checker is
implemented as a syntax checker. Comparing with FE1.0, this change
reports some REDUNDANT_LABEL_WARNING that FE1.0 has missed, especially
LHS of assignments.
Introduce a new checkPsiOrLightTree so the structure is more symmetric.
In addition, now implementation of `checkLightTree` has access to
`FirLightSourceElement` rather tha a generic `FirSourceElement`
1. Nullable function type is not rendered correctly.
2. Bounds of type parameters are not considered during comparison, this
would incorrectly treat different declarations as the same, for
example
```
fun <C: List<String>> C.foo() {}
fun <C: Set<String>> C.foo() {}
```
For invalid code like the following,
```
when {
true, false -> {}
}
```
`false` does not have a corresponding elements on the FIR side and hence
the containing `FirWhenBranch` is returned by `getOrBuildFir`. This
change makes the analysis API bail out for such cases.
The following error code path only runs in depended mode.
Test succeeded in normal analysis mode but failed in depended analysis mode.
java.lang.Exception: Test succeeded in normal analysis mode but failed in depended analysis mode.
at org.jetbrains.kotlin.analysis.low.level.api.fir.test.base.AbstractLowLevelApiTest.runTest(AbstractLowLevelApiTest.kt:126)
at org.jetbrains.kotlin.analysis.api.fir.components.OverriddenDeclarationProviderTestGenerated.testOnEnumEntry(OverriddenDeclarationProviderTestGenerated.java:72)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:688)
at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:149)
at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:140)
at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:84)
at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115)
at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104)
at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:98)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$6(TestMethodTestDescriptor.java:210)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:206)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:131)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:65)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:129)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:127)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:126)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:84)
at org.junit.platform.engine.support.hierarchical.ForkJoinPoolHierarchicalTestExecutorService$ExclusiveTask.compute(ForkJoinPoolHierarchicalTestExecutorService.java:185)
at java.util.concurrent.RecursiveAction.exec(RecursiveAction.java:189)
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:175)
Caused by: java.util.concurrent.ExecutionException: java.lang.IllegalStateException: No designation of local declaration public final static enum entry MyEntry: R|MyEnum|
at java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.util.concurrent.FutureTask.get(FutureTask.java:192)
at org.jetbrains.kotlin.analysis.api.fir.components.AbstractOverriddenDeclarationProviderTest.doTestByFileStructure(AbstractOverriddenDeclarationProviderTest.kt:79)
at org.jetbrains.kotlin.analysis.api.fir.test.framework.AbstractHLApiSingleModuleTest.doTestByFileStructure(AbstractHLApiSingleModuleTest.kt:16)
at org.jetbrains.kotlin.analysis.low.level.api.fir.test.base.AbstractLowLevelApiTest.runTest(AbstractLowLevelApiTest.kt:117)
... 38 more
Caused by: java.lang.IllegalStateException: No designation of local declaration public final static enum entry MyEntry: R|MyEnum|
at org.jetbrains.kotlin.analysis.low.level.api.fir.api.FirDeclarationDesignationKt.collectDesignation(FirDeclarationDesignation.kt:90)
at org.jetbrains.kotlin.analysis.low.level.api.fir.api.LowLevelFirApiFacadeForResolveOnAir.runBodyResolveOnAir(LowLevelFirApiFacadeForResolveOnAir.kt:239)
at org.jetbrains.kotlin.analysis.low.level.api.fir.api.LowLevelFirApiFacadeForResolveOnAir.getResolveStateForDependentCopy(LowLevelFirApiFacadeForResolveOnAir.kt:175)
at org.jetbrains.kotlin.analysis.api.fir.KtFirAnalysisSession.createContextDependentCopy(KtFirAnalysisSession.kt:102)
at org.jetbrains.kotlin.analysis.low.level.api.fir.test.base.AbstractLowLevelApiTest.analyse(AbstractLowLevelApiTest.kt:203)
at org.jetbrains.kotlin.analysis.api.fir.components.AbstractOverriddenDeclarationProviderTest.access$analyse(AbstractOverriddenDeclarationProviderTest.kt:22)
at org.jetbrains.kotlin.analysis.api.fir.components.AbstractOverriddenDeclarationProviderTest$doTestByFileStructure$$inlined$executeOnPooledThreadInReadAction$1$1.compute(AbstractLowLevelApiTest.kt:183)
at com.intellij.mock.MockApplication.runReadAction(MockApplication.java:183)
at org.jetbrains.kotlin.analysis.api.fir.components.AbstractOverriddenDeclarationProviderTest$doTestByFileStructure$$inlined$executeOnPooledThreadInReadAction$1.call(AbstractLowLevelApiTest.kt:183)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:652)
at java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:649)
at java.security.AccessController.doPrivileged(Native Method)
at java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:649)
at java.lang.Thread.run(Thread.java:748)
Also changed tests to do the analysis on the KtElement of
interest instead of the KtFile where possible because currently depended
mode does not support analysing the entire file. Maybe we should support
analysing the whole file at some point.
In depended mode, a fake file is created and hence some generated FIR
elements are based on this fake file. However, FIR cares about the
identity of FIR elements: for example, loading overridden symbol does
not work with fake FIR elements. This change makes LL API to always
create FIR elements from the underlying real PSI so that HL API
implementation to always use the real FIR element to answer queries.
It seems the original function type gets lost during resolution. Hence
thie change added a custom attribute to recover the original function
type on an anonymous function
Consider the code below
```
fun test() {
a@ b@ {
{}
}
}
```
Currently when the code is converted to FIR, label `b` is bound to the
outer lambda and `a` gets bound to the inner lambda because it's not
consumed. This is wrong and also leads transfromation to fail with
exceptions because of the unexpected consumption of `a`.
This change fixes the above issue by designating a specific node in the
AST as the allowed user of a label when the label is added.
This way caller don't need to first check if the symbol is allowed to
override. The current API throws for cases like Java field, or enum
entry, which is not very user-friendly.
These two fields references the parent of the import rather than the
classes that are imported. For example
```
import java.util.Map // resolvedClassId -> null
import java.util.Map.Entry // resolvedClassId -> java.util.Map
import java.util.Map.* // resolvedClassId -> java.util.Map
import java.util.Map.someStaticMethod // resolvedClassId -> java.util.Map
import kotlin.package.someTopLevelFuntion // resolvedClassId -> null
import kotlin.package.MyObject.someObjectFuntion // resolvedClassId -> kotlin.package.MyObject
```
ImplicitReceiverValue is mutable and FIR body resolve could alter it
while analysing code with smartcast. Hence, previously the IDE may see
inconsistent receiver values for a local scope. For example
```
open class A
interface Foo {
fun foo()
}
fun A.bar() {
if (this is Foo) {
// scope here has implicit receiver type to be `A` rather than `it<A, Foo>`
}
}
```
This change creates snapshots for local statements so later changes
during body resolve won't affect the collected context.
Assuming Java class `Super` has a protected `getName` method and a
public `setName` method.
Then, in a subclass of `Super`, FE1.0 allows calls to `setName` via the
property syntax if the property is protected and invisible due to
dispatch receiver is not `this` or `super`.
Consider the following code:
```
fun test(a: List<String>) {
a.first()
}
```
The dispatch receiver type of `first` in this case is `List<T>` before
this change. After this change, it's `List<String>`.
In addition, this change also replace the dispatch receiver type with
the more specific type if available. For example, consider the following
```
class MyList: ArrayList<String>()
fun test(a: MyList) {
a.get(0)
}
```
The dispatch receiver type of `get` is `MyList`, instead of
`ArrayList<String>`. That is, a fake override is created in this case.
Various HL API needs to create fake override for symbols in libraries.
Without module data it may fail. Following exception is an example:
java.lang.IllegalStateException: Module data is not registered in Libraries session
at org.jetbrains.kotlin.fir.FirModuleDataKt.getModuleData(FirModuleData.kt:80)
at org.jetbrains.kotlin.fir.scopes.impl.FirFakeOverrideGenerator.createCopyForFirProperty(FirFakeOverrideGenerator.kt:297)
at org.jetbrains.kotlin.fir.scopes.impl.FirFakeOverrideGenerator.createCopyForFirProperty$default(FirFakeOverrideGenerator.kt:281)
at org.jetbrains.kotlin.fir.scopes.impl.FirFakeOverrideGenerator.createSubstitutionOverrideProperty(FirFakeOverrideGenerator.kt:271)
at org.jetbrains.kotlin.fir.scopes.impl.FirFakeOverrideGenerator.createSubstitutionOverrideProperty$default(FirFakeOverrideGenerator.kt:254)
at org.jetbrains.kotlin.fir.scopes.impl.FirClassSubstitutionScope.createSubstitutionOverrideProperty(FirClassSubstitutionScope.kt:211)
at org.jetbrains.kotlin.fir.scopes.impl.FirClassSubstitutionScope.access$createSubstitutionOverrideProperty(FirClassSubstitutionScope.kt:30)
at org.jetbrains.kotlin.fir.scopes.impl.FirClassSubstitutionScope$processPropertiesByName$1.invoke(FirClassSubstitutionScope.kt:84)
at org.jetbrains.kotlin.fir.scopes.impl.FirClassSubstitutionScope$processPropertiesByName$1.invoke(FirClassSubstitutionScope.kt:81)
at org.jetbrains.kotlin.fir.scopes.impl.FirClassUseSiteMemberScope$processPropertiesByName$1.invoke(FirClassUseSiteMemberScope.kt:32)
at org.jetbrains.kotlin.fir.scopes.impl.FirClassUseSiteMemberScope$processPropertiesByName$1.invoke(FirClassUseSiteMemberScope.kt:25)
at org.jetbrains.kotlin.fir.scopes.impl.FirClassDeclaredMemberScope.processPropertiesByName(FirClassDeclaredMemberScope.kt:115)
at org.jetbrains.kotlin.fir.scopes.impl.FirClassUseSiteMemberScope.processPropertiesByName(FirClassUseSiteMemberScope.kt:25)
at org.jetbrains.kotlin.fir.scopes.impl.FirClassSubstitutionScope.processPropertiesByName(FirClassSubstitutionScope.kt:81)
at org.jetbrains.kotlin.fir.scopes.impl.FirClassUseSiteMemberScope.computeDirectOverridden(FirClassUseSiteMemberScope.kt:45)
at org.jetbrains.kotlin.fir.scopes.impl.FirClassUseSiteMemberScope.access$computeDirectOverridden(FirClassUseSiteMemberScope.kt:17)
at org.jetbrains.kotlin.fir.scopes.impl.FirClassUseSiteMemberScope$processPropertiesByName$1.invoke(FirClassUseSiteMemberScope.kt:28)
at org.jetbrains.kotlin.fir.scopes.impl.FirClassUseSiteMemberScope$processPropertiesByName$1.invoke(FirClassUseSiteMemberScope.kt:25)
at org.jetbrains.kotlin.fir.scopes.impl.FirClassDeclaredMemberScope.processPropertiesByName(FirClassDeclaredMemberScope.kt:115)
at org.jetbrains.kotlin.fir.scopes.impl.FirClassUseSiteMemberScope.processPropertiesByName(FirClassUseSiteMemberScope.kt:25)
at org.jetbrains.kotlin.idea.frontend.api.fir.components.KtFirSymbolDeclarationOverridesProvider.processCallableByName(KtFirSymbolDeclarationOverridesProvider.kt:58)
at org.jetbrains.kotlin.idea.frontend.api.fir.components.KtFirSymbolDeclarationOverridesProvider.access$processCallableByName(KtFirSymbolDeclarationOverridesProvider.kt:29)
at org.jetbrains.kotlin.idea.frontend.api.fir.components.KtFirSymbolDeclarationOverridesProvider$getDirectlyOverriddenSymbols$$inlined$processOverrides$1.invoke(FirRefWithValidityCheck.kt:105)
at org.jetbrains.kotlin.idea.frontend.api.fir.components.KtFirSymbolDeclarationOverridesProvider$getDirectlyOverriddenSymbols$$inlined$processOverrides$1.invoke(FirRefWithValidityCheck.kt:33)
at org.jetbrains.kotlin.idea.fir.low.level.api.api.LowLevelFirApiFacadeKt.withFirDeclaration(LowLevelFirApiFacade.kt:129)
at org.jetbrains.kotlin.idea.frontend.api.fir.components.KtFirSymbolDeclarationOverridesProvider.getDirectlyOverriddenSymbols(KtFirSymbolDeclarationOverridesProvider.kt:253)
at org.jetbrains.kotlin.idea.frontend.api.components.KtSymbolDeclarationOverridesProviderMixIn$DefaultImpls.getDirectlyOverriddenSymbols(KtSymbolDeclarationOverridesProvider.kt:45)
at org.jetbrains.kotlin.idea.frontend.api.KtAnalysisSession.getDirectlyOverriddenSymbols(KtAnalysisSession.kt:29)
at org.jetbrains.kotlin.idea.completion.weighers.CallableWeigher.addWeight(CallableWeigher.kt:28)
at org.jetbrains.kotlin.idea.completion.weighers.Weighers.applyWeighsToLookupElement(Weighers.kt:61)
at org.jetbrains.kotlin.idea.completion.contributors.FirCompletionContributorBase.applyWeighers(FirCompletionContributorBase.kt:115)
at org.jetbrains.kotlin.idea.completion.contributors.FirCompletionContributorBase.addCallableSymbolToCompletion(FirCompletionContributorBase.kt:101)
at org.jetbrains.kotlin.idea.completion.contributors.FirCallableCompletionContributor.collectDotCompletionForCallableReceiver(FirCallableCompletionContributor.kt:189)
at org.jetbrains.kotlin.idea.completion.contributors.FirCallableCompletionContributor.collectDotCompletion(FirCallableCompletionContributor.kt:145)
at org.jetbrains.kotlin.idea.completion.contributors.FirCallableCompletionContributor.complete(FirCallableCompletionContributor.kt:79)
at org.jetbrains.kotlin.idea.completion.contributors.FirCallableCompletionContributor.complete(FirCallableCompletionContributor.kt:31)
at org.jetbrains.kotlin.idea.completion.contributors.FirCompletionContributorBaseKt.complete(FirCompletionContributorBase.kt:124)
at org.jetbrains.kotlin.idea.completion.Completions.complete(Completions.kt:18)
at org.jetbrains.kotlin.idea.completion.KotlinFirCompletionProvider.complete(KotlinFirCompletionContributor.kt:81)
at org.jetbrains.kotlin.idea.completion.KotlinFirCompletionProvider.addCompletions(KotlinFirCompletionContributor.kt:70)
at com.intellij.codeInsight.completion.CompletionProvider.addCompletionVariants(CompletionProvider.java:34)
at com.intellij.codeInsight.completion.CompletionContributor.fillCompletionVariants(CompletionContributor.java:156)
at com.intellij.codeInsight.completion.CompletionService.getVariantsFromContributors(CompletionService.java:77)
at com.intellij.codeInsight.completion.CompletionService.getVariantsFromContributors(CompletionService.java:60)
at com.intellij.codeInsight.completion.CompletionService.performCompletion(CompletionService.java:133)
at com.intellij.codeInsight.completion.BaseCompletionService.performCompletion(BaseCompletionService.java:41)
at com.intellij.codeInsight.completion.CompletionProgressIndicator.lambda$calculateItems$12(CompletionProgressIndicator.java:863)
at com.intellij.util.indexing.FileBasedIndex.lambda$ignoreDumbMode$0(FileBasedIndex.java:163)
at com.intellij.openapi.util.RecursionManager$1.computePreventingRecursion(RecursionManager.java:111)
at com.intellij.util.indexing.FileBasedIndexEx.ignoreDumbMode(FileBasedIndexEx.java:588)
at com.intellij.util.indexing.FileBasedIndex.ignoreDumbMode(FileBasedIndex.java:162)
at com.intellij.util.indexing.DumbModeAccessType.ignoreDumbMode(DumbModeAccessType.java:43)
at com.intellij.codeInsight.completion.CompletionProgressIndicator.calculateItems(CompletionProgressIndicator.java:859)
at com.intellij.codeInsight.completion.CompletionProgressIndicator.runContributors(CompletionProgressIndicator.java:847)
at com.intellij.codeInsight.completion.CodeCompletionHandlerBase.lambda$startContributorThread$6(CodeCompletionHandlerBase.java:353)
at com.intellij.codeInsight.completion.AsyncCompletion.lambda$tryReadOrCancel$5(CompletionThreading.java:172)
at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1078)
at com.intellij.codeInsight.completion.AsyncCompletion.tryReadOrCancel(CompletionThreading.java:170)
at com.intellij.codeInsight.completion.CodeCompletionHandlerBase.lambda$startContributorThread$7(CodeCompletionHandlerBase.java:345)
at com.intellij.codeInsight.completion.AsyncCompletion.lambda$startThread$0(CompletionThreading.java:95)
at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$2(CoreProgressManager.java:183)
at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:705)
at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:647)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:63)
at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:170)
at com.intellij.codeInsight.completion.AsyncCompletion.lambda$startThread$1(CompletionThreading.java:91)
at com.intellij.openapi.application.impl.ApplicationImpl$1.run(ApplicationImpl.java:265)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:264)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java)
This is useful for quickfixes offering casts. We don't want to offer
user to cast incompatible types.
Also, explicitly allow compare to `Nothing` and handle `Nothing` from intersection
Also change
org.jetbrains.kotlin.fir.types.TypeUtilsKt#hideLocalTypeIfNeeded to skip
approximating anonymous objects if there are multiple super type refs so
that resolution behaves the same (for uncompilable code).
Note that this change does not implement check for
ApproximateAnonymousReturnTypesInPrivateInlineFunctions as the check is
already turned on in 1.5 and will likely not needed when FIR becomes
stable.
ProhibitAssigningSingleElementsToVarargsInNamedForm is enabled from 1.3
so there is no need to make FIR accepting single element passed through
named arguments.
In addition, we may want to report only
ASSIGNING_SINGLE_ELEMENT_TO_VARARG_IN_NAMED_FORM_FUNCTION and not arg
type mismatch. But FE1.0 is reporting both so I am following it. If we
want to remove the redundant report, we will probably want to remove
FirNamedVarargChecker and report during resolution as a cone diagnostic.
Difference from FE1.0
* KT-4285: calls to virtual method with default argument should be
reported as not tailrec. FE1.0 is missing such cases.
* KT-48600: calls inside lambda should be reported as not tailrec. FE1.0
also misses such cases.
Changes from FE1.0:
1. As discussed previously, no expression evaluation happens during this
check.
2. FE1.0 doesn't check redundant object comparisons.