Commit Graph

55 Commits

Author SHA1 Message Date
Marco Pennekamp fb43e53ca3 [LL FIR] KTIJ-24574 Fix containing declaration finder for init blocks
- KTIJ-24574 occurred because a local destructuring declaration was
  erroneously returned as the non-local containing declaration of an
  element by `getNonLocalContainingOrThisDeclaration`. This occurred in
  `init` blocks.

KTIJ-24574 fixed
2023-02-13 10:38:26 +00:00
Jaebaek Seo 860dee2cb1 Fix reference resolver bug for companion object whose name is the same as class
FirReferenceResolveHelper internally checks whether the referenced class
id matches the qualifed access or not. If they do not match, it reports
an error. When the companion object has the same name as the class,
resolving a qualified expression access to a member of the companion
object causes an error because of the mismatch e.g.,

```
package my.sample

class Test {
    fun a() {
        my.sample.<caret>Test.say()
    }

    companion object Test {
        fun say() {}
    }
}
```

This commit fixes the issue.

TODO: When the companion object has a name difference from class, it
does not report an error but the resolution result is wrong in FIR. See
KT-56167.

---

Commentary from rebaser: the issue mentioned in this code is
fixed in 71a368e06e, so the actual
fix is omitted, and only test data is preserved
2023-02-08 18:39:11 +00:00
Roman Golyshev 71a368e06e [Analysis API] KTIJ-24107 Fix resolution of qualified invoke calls on objects
^KTIJ-24107 Fixed
^KTIJ-24344 Fixed
2023-01-27 16:49:30 +00:00
Marco Pennekamp 2922f85a98 [AA] KTIJ-23563 Add reference resolve tests for working cases
- Type arguments in invalid calls/property accesses are resolved
  correctly in many cases, for which this commit adds test cases.
2023-01-25 16:40:46 +00:00
Anna Kozlova 86cc57ac39 [AA] allow navigation from '==' to the equals method of lhs 2023-01-13 20:14:30 +00:00
Dmitriy Novozhilov bd26c29229 [FIR] Resolve arguments of error types during type resolution 2023-01-12 17:45:06 +00:00
Marco Pennekamp 5f554d0065 [FIR] KT-54980 Fix resolvability of too few/too many type arguments
- If too few or too many type arguments were provided, they were all
  thrown away in `TypeArgumentMapping`,
  `FirCallCompletionResultsWriterTransformer`, and `KtFirCallResolver`.
  The fix handles type arguments of the wrong arity more gracefully.
  - Note for `TypeArgumentMapping`: Excess type arguments are not needed
    for candidate resolution. Excess type arguments are still resolved
    due to the handling in `FirCallCompletionResultsWriterTransformer`.
- Post-processing in `AllCandidatesResolver`: When all candidates are
  resolved in `AllCandidatesResolver.getAllCandidates`, the function
  builds a FIR file. During that resolution, the
  `generic<String, String>` call (in example
  `functionCallWithTooFewTypeArguments.kt`) is correctly marked as
  inapplicable, but the missing type argument is inferred as an error
  type. `firFile` then contains a function call
  `generic<String, String, ERROR>` instead of `generic<String, String>`.
  This call is still marked as inapplicable. Despite that, the
  *subsequent* resolution by
  `bodyResolveComponents.callResolve.collectAllCandidates` disregards
  the call's inapplicability and resolves successfully into an
  applicable candidate. This is because `CandidateFactory` doesn't make
  any guarantees for already inapplicable calls. The fix adds
  post-processing to `AllCandidatesResolver` to preserve candidate
  inapplicability.
- Most tests that this commit changes had slightly different results due
  to type arguments becoming resolvable.
- `wrongNumberOfTypeArguments.kt` and
  `wrongNumberOfArgumentsInTypeAliasConstructor.kt`:
  `ConeDiagnostic.toFirDiagnostics` prefers specific errors. Because
  `ARGUMENT_TYPE_MISMATCH` is specific and `INAPPLICABLE_CANDIDATE` is
  not, only the former is reported. I see no reason to pass an illegally
  typed argument in either test, so the change reduces the errors to
  `INAPPLICABLE_CANDIDATE`.
- `typeAliasSamAdapterConstructors2.fir.kt`: See KT-55007.
- Disable `mismatchTypeParameters` JS backend test due to its handling
  of excess type arguments. See KT-55250.

^KT-54980 fixed
2023-01-02 16:36:02 +00:00
Anna Kozlova 15b1e429d7 [compiler] introduce dedicated Fir declaration for dangling modifier lists (KTIJ-23008)
ensure fir annotations are included in FirDanglingModifierList and resolved,
dedicated DanglingTopLevelModifierListStructureElement exists for top
level lists only, class level lists are processed by containing structure
element
2022-12-21 20:58:46 +00:00
Anna Kozlova b81c210535 [AA] resolve array access expression to corresponding set operator
k1 would suggest `get` as well
 but with current fir structure with fake desugaring
 get is moved to the separate fake psi which doesn't exist
 thus the problem is ignored for now
 ^ KTIJ-24025
2022-12-21 10:45:40 +00:00
Anna Kozlova a529f8510d [LL] ensure FirConstExpression's annotations are not lost (KTIJ-23968) 2022-12-15 14:31:48 +00:00
Anna Kozlova cdf6ffa167 [AA] do not try to build KtSymbol for FirErrorFunction
^KTIJ-23669
FirErrorFunctions are created for unknown labels
when the code in return statements is not complete yet.
Such labels cannot be resolved, and no symbols should be created for them
2022-11-24 13:09:29 +00:00
Ilya Kirillov 26ec7ec296 [Analysis API] update testdata after renderer rework
The new testdata seems to be more correct or just different

^KTIJ-23268
2022-11-11 11:59:59 +01:00
Simon Ogorodnik 513af2dfbc FIR. Refactor smart-cast representation in FIR tree
Make smart-casts non-transparent expression without delegation
to underlying FirQualifiedAccessExpression, as children delegation in
fir tree has unclear semantics
Remove two different kinds of tree nodes for smart-casts
2022-08-15 21:46:11 +00:00
Roman Golyshev bcd6a54ffb [Analysis API FIR] Fix small mistake in KDocReferenceResolver
`owner` is a PSI element, it can never be an instance of
`KtConstructorSymbol`

Also, make `MutableCollection` an extension receiver instead of context
receiver for the consistency
2022-07-29 17:13:52 +02:00
Ilya Kirillov 556add72ff [Analysis API FIR] fix KDoc reference resolve for aliased imports 2022-07-28 01:37:54 +02:00
Ilya Kirillov d9c4fda521 [Analysis API FIR] implement reference resolve inside KDoc
^KTIJ-22324 fixed
2022-07-28 01:37:53 +02:00
Ilya Kirillov d5113892df [Analysis API FE10] fix CallableId for synthetic java property descriptors 2022-06-22 09:31:48 +02:00
Mikhail Glukhikh 0ee04d0825 FE10 analysis API: revert resolving 'this' references to receivers
FE10 IDE plugin relies on resolving 'this' references to class or callable
2022-06-03 16:25:44 +00:00
Mikhail Glukhikh c3b5d83f31 FE10 Analysis API: create 17 separate test data files for resolve 2022-05-31 11:34:59 +00:00
Mikhail Glukhikh f4510773d0 FIR analysis API: add workaround for java.io.Serializable type 2022-05-31 11:34:54 +00:00
Mikhail Glukhikh 446ee943e2 FIR analysis API: fix rendering of Java-based types 2022-05-31 11:34:53 +00:00
Denis.Zharkov d7f87e0182 FIR: Adjust analysis test data to changes in loading Java types 2022-05-19 16:54:02 +00:00
Jinseong Jeon a74a51b2d9 AA: add tests about resolution of implicit lambda parameter 2022-04-21 19:18:24 +02:00
Ilya Kirillov 6831bde751 [analysis api fir, tests] update parameter names in testdata 2022-04-13 12:53:18 +02:00
Ilya Kirillov 443ee4c860 [analysis api] allow generating test with for with more possible parameters 2022-04-13 12:52:59 +02:00
Roman Golyshev 32fa2fc476 [FIR] Resolve receiver in qualified expressions with no selector
In qualified expression like `foo().`, selector expression is null.
Because of that the whole expression was marked as an error FIR
expression, and `foo()` part was not resolved at all (including
arguments and everything else).

This commit fixes the problem by providing receiver's FIR expression
as an underlying expression for error FIR expression. That way
it will be seen by all resolve transformers and will be successfully
resolved.

^KTIJ-21484 Fixed
2022-04-12 10:55:12 +00:00
Jinseong Jeon 881a6bed35 AA: add tests about resolution to Java static method 2022-03-22 15:44:50 +01:00
Roman Golyshev 22830cf159 [FIR IDE] Fix resolving sugared compound operators (like +=, -=)
^KTIJ-21374 Fixed
2022-03-22 13:14:54 +00:00
Roman Golyshev 7bcd67068c [FIR IDE] Resolve explicit invoke calls more correctly
Also, enable some muted tests

^KTIJ-21343 Fixed
2022-03-15 21:29:36 +03:00
Jinseong Jeon 89725941df AA: showcase an error in resolution to stdlib in standalone mode 2022-03-15 19:50:16 +03:00
Jinseong Jeon a68fd25982 AA: relax the assertion about referenced ClassId and qualified access
If an import alias is involved, they could be not identical.
Since an import alias ends with a simple identifer, we can simply drop
the first segment of qualified access and try the assertion again.
2022-03-02 20:30:31 +01:00
Ilya Kirillov b8c36b7998 Analysis API FIR: remove compilation errors from new testdata 2022-02-01 16:31:29 +01:00
Ilya Kirillov 441de5cd75 Analysis API FIR: resolve Java synthetic properties KtSyntheticJavaPropertySymbol 2022-02-01 16:31:28 +01:00
Mads Ager d13e117a58 Change FIR analysis API resolution for super type calls.
The IDE expects the super type calls to resolve to the constructor
invoked and not the class. The frontend itself resolves to the
class, so an extra layer is needed to adjust that to the constructor.
2022-02-01 16:31:26 +01:00
Ilya Kirillov 4530041cbb Analysis API: move reference resolve testsdata with errors to dedicated folders 2022-01-31 21:12:30 +01:00
Ilya Kirillov 96e1f1e7d4 Analysis API: fix some compilation errors in reference resolve testdata 2022-01-31 21:11:54 +01:00
Roman Golyshev f0f2f67024 KT-50862 Unwrap use-site substitution overrides
Use-site substitution override happens in situations like this:

```
interface List<A> { fun get(i: Int): A }

fun take(list: List<String>) {
  list.get(10) // this call
}
```

We want to have those overrides unwrapped, because we don't want
to deal with a different KtSymbol for each possible use-site

^KT-50862 Fixed
2022-01-29 07:42:18 +00:00
Ilya Kirillov e1fece6402 Analysis API: fix testdata of reference resolve tests which started to pass 2022-01-21 16:46:28 +01:00
Ilya Kirillov 5e42be9849 Analysis API: fix redundant caret symbol in testdata 2022-01-02 21:56:54 +03:00
Mads Ager 61265a6501 Return error candidates from KtFirArrayAccessReference.resolveToSymbols 2021-12-21 13:22:15 +03:00
Simon Ogorodnik d084cfb65b FIR HL API: Unwrap substitution overrides if it contains stub types 2021-12-15 22:23:15 +03:00
Ilya Kirillov bad91915a6 Analysis API: adapt reference resolve tests to changes in renderer 2021-12-02 20:09:19 +01:00
Roman Golyshev fa8bb47bdf [FIR IDE] Add unwrapping substitution overrides which doesn't affect function's signature
Also, do not use PSI to restore SUBSTITUTION_OVERRIDE function/property
symbols
2021-11-25 21:19:56 +03:00
Dmitriy Novozhilov 01c0cf80d0 [FIR] Support @kotlin.jvm.PurelyImplements annotation 2021-11-22 17:01:17 +03:00
Jinseong Jeon d91170ed2c FIR IDE: add more tests about resolving reference to type parameters 2021-11-18 17:33:17 +01:00
Tianyu Geng e195f0426e FIR IDE: add KtExtensionReceiverSymbol
This symbol represents the extension receiver of a callable and
currently is used as the resolution target of `this` in a callable with
extension.
2021-10-26 08:50:38 +00:00
Tianyu Geng d3c91ee9be FIR IDE: align resolution behavior of super with FE1.0
That is, for a labeled `super`, the keyword should resolve to the super
type and the label should be resolved to the current type.
2021-10-26 08:50:37 +00:00
Tianyu Geng 0d966ec65a FIR IDE: resolve implicit invoke to callable property 2021-10-26 08:50:37 +00:00
Jinseong Jeon 8023e7fb02 FIR IDE: add a test for resolution of @Retention value 2021-10-15 19:45:04 +00:00
Tianyu Geng e6d9098bec FIR IDE: Disable some tests in depended mode due to failures
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)
2021-10-14 06:05:32 +03:00