1071 Commits

Author SHA1 Message Date
Denis.Zharkov 276f5b26d8 K2: Implement partially constrained lambda analysis (PCLA)
It's expected to partially mimic the behavior of what
previously was called builder inference, but with more clear contracts
(documentation is in progress, though)

See a lot of fixed issues in the later commits with test data,
especially [red-to-green]

^KT-59791 In Progress
2024-01-10 14:56:30 +00:00
Alexander.Likhachev 21b438f55d Replace the trove4j collections usages with the fastutil ones
The trove4j library is licensed under LGPL, and that causes some troubles while working with it. The fastutil library provides the same functionality in the context of our needs, and is licensed under the Apache license.
^KTI-1135 In Progress
2024-01-10 11:29:25 +00:00
Mikhail Glukhikh 25c0bd278e CallableReferencesCandidateFactory.kt: minor cleanup for better reading 2023-12-12 13:52:29 +00:00
Mikhail Glukhikh 526bc1744a K2: implement BUILDER_INFERENCE_MULTI_LAMBDA_RESTRICTION
#KT-59390 Fixed
2023-12-01 10:54:29 +00:00
Pavel Kunyavskiy b38ebbb853 [IR] Avoid ir.actualization depending on frontend module
^KT-62292
2023-11-20 08:31:41 +00:00
Ivan Kochurkin 64db96eda3 [K1, K2] Use safe names when accessing to type parameters
^KT-57529 Fixed
2023-11-09 12:21:43 +01:00
Nikita Bobko fa89b8b0f1 [FE 1.0] 2/2 Don't report a warning when new members are added to open expect actualization
^KT-62655 Fixed
2023-10-20 14:37:10 +00:00
Nikita Bobko a537ab898e [FE 1.0] Refactoring: replace defensive NonPrivateCallableAdded with Unknown
Motivation: I'm going to drop NonPrivateCallableAdded (KT-62655) in the
next commits. But I don't want to change the existing logic when I drop
it. That's why I have to introduce the "Unknown" case
2023-10-20 14:37:10 +00:00
Nikita Bobko 12f932a63a [FE 1.0] Report a more precise diagnostic when parameter modifiers (vararg) are changed in actualization
^KT-62747 Fixed
2023-10-20 14:37:10 +00:00
Roman Efremov 423f4ca5f0 [FE, IR] Check compatibility of annotations set on type usages in expect and actual declarations
This includes checking of annotatins set on:

- value parameter types
- type parameter bound types
- extension functions receiver types
- function return types
- class super types

Fix in `defaultParams_inheritanceByDelegation_positive.kt`
is needed because of problem in resolution of implicit return types
(KT-62064), which leads to crash in annotation checker, because it
expects resolved return type.

MR: KT-MR-12245

^KT-60671 Fixed
2023-10-16 10:48:08 +00:00
Nikita Bobko 43c97077eb 2/2 Extract K1 KMP matcher in its own subsystem. Fix compilation errors 2023-10-06 11:41:22 +00:00
Nikita Bobko cc70f78027 1/2 Extract K1 KMP matcher in its own subsystem. Copy files
This commit is literally this shell command:
```
cp compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/mpp/AbstractExpectActualAnnotationMatchChecker.kt compiler/resolution/src/org/jetbrains/kotlin/resolve/multiplatform/K1AbstractExpectActualAnnotationMatchChecker.kt
cp compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/mpp/AbstractExpectActualCompatibilityChecker.kt compiler/resolution/src/org/jetbrains/kotlin/resolve/multiplatform/K1AbstractExpectActualCompatibilityChecker.kt
cp compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/mpp/ExpectActualCollectionArgumentsCompatibilityCheckStrategy.kt compiler/resolution/src/org/jetbrains/kotlin/resolve/multiplatform/K1ExpectActualCollectionArgumentsCompatibilityCheckStrategy.kt
cp core/compiler.common/src/org/jetbrains/kotlin/resolve/multiplatform/ExpectActualCompatibility.kt compiler/resolution/src/org/jetbrains/kotlin/resolve/multiplatform/K1ExpectActualCompatibility.kt
cp compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/mpp/ExpectActualMatchingContext.kt compiler/resolution/src/org/jetbrains/kotlin/resolve/multiplatform/K1ExpectActualMatchingContext.kt
cp core/compiler.common/src/org/jetbrains/kotlin/resolve/multiplatform/ExpectActualMemberDiff.kt compiler/resolution/src/org/jetbrains/kotlin/resolve/multiplatform/K1ExpectActualMemberDiff.kt
```

Motivation: KMP is going to evolve in K2 a lot. But we don't want to
touch K1 version of KMP. That's why it's easeir to just copy-paste
expect-actual matcher into K1 flavor
2023-10-06 11:41:22 +00:00
Roman Efremov 04c1bf749c [K1] Correctly handle case when expect annotation is unresolved
Before change NPE was thrown.

Review: KT-MR-12250

^KT-62026
2023-09-19 10:19:08 +00:00
Roman Efremov e79851910e [FE, IR] Check annotations compatibility on expect and actual getters and setters
^KT-60671
2023-09-15 14:41:38 +00:00
Roman Efremov 420dceb7d8 [FE, IR] Store PsiElement for mismatched annotation's actual target
There is IDE quick fix which suggests to copy mismatched annotation
from `expect` to `actual` (see KTIJ-26633). It needs to find
`actual` PsiElement where to add annotation. Before previous commit, it
was easy - just get source of `Incompatibility.actualSymbol`.
After previous commit, the problem might be in value parameter, while
`actualSymbol` would contain function symbol. This is solved by adding
new field `Incompatibility.actualAnnotationTargetElement`.

`SourceElementMarker` introduced, because it's needed to be used in
abstract checker. Existing `DeclarationSymbolMarker` doesn't fit
because in next PR for this issue annotations set on types will be reported,
and types are not declarations.

^KT-60671
2023-09-15 14:41:37 +00:00
Roman Efremov 6b217369a8 [FE1.0] Fix false reporting of non-matching annotations in IDE...
...when typealiased expect class used in class literal.

^KTIJ-26700 Fixed
2023-08-23 13:15:20 +00:00
Roman Efremov 3124cbcbad [FE, IR] Refactor: rename areAnnotationArgumentsEqual parameters
Rename to "expect" and "actual" annotation.
This will be needed in next commit to make it clear that
only expect annotation value needs special handling.

^KTIJ-26700
2023-08-23 13:15:20 +00:00
Roman Efremov 77ab13400e [FE1.0] Fix false reporting of non-matching actual annotations in IDE
It was reported because in composite module analysis we have both expect
and actual annotation descriptors, which may differ.
This may lead to bugs in the checker of ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT
diagnostic.

`fqName` comparison can be safely removed, because we already check
types in `areCompatibleExpectActualTypes`.

Tests:
- typealiasedAnnotation.kt - for annotation use (so it has different
ClassId)
- typealiasedAnnotationAsArgument.kt - when typealiased annotation
used in another annotation as argument
- sourceRetentionAnnotationsWhenTypealias.kt - tests same as
compiler/testData/diagnostics/tests/multiplatform/annotationMatching/sourceRetentionAnnotationsWhenTypealias.kt

No special test added for opt-in, because it's prohibited to have
expect/actual opt-ins by EXPECT_ACTUAL_OPT_IN_ANNOTATION checker.

^KTIJ-26700
2023-08-23 13:15:20 +00:00
Roman Efremov def4388c19 [FE, IR] Check annotations on expect and actual enum entries
^KT-60668
^KT-60936
2023-08-22 12:14:43 +00:00
Roman Efremov b57940a59b [FE1.0] Optimize search of expect class member in annotation checker
In the following scenario, when we search corresponding expect member
for actual `A.B`, we can skip checking compatibility of `B` scope.
```
class A {
  class B {
    fun foo() {}
  }
}
actual typealias AImpl = A
```

This is because:

1. Annotation checker runs no matter if found expect class is compatible
or not.
2. Class always has at most one corresponding `expect` class (unlike for
functions, which may have several overrides), so we are sure that we
found the right member.

^KT-60668
^KT-60936
2023-08-22 12:14:43 +00:00
Roman Efremov ab1c0e3c48 [FE] Check annotations on actual class members including fake overrides
^KT-60668
^KT-60936
2023-08-22 12:14:42 +00:00
Roman Efremov d614f06259 [FE 1.0] Refactor: extract logic of matching actual against potential expects
Will be needed in subsequent commits for the annotation checker.
`findExpectForActual` is not suitable for the checker because
`findExpectForActual` searches expect class with same `ClassId` for
actual class containing current member (see method
`findClassifiersFromModule`), which is:
1. Unnecessary, since we already have expect class in annotation checker
2. Incorrect when class actualized via typealias and `ClassId` is
   different.

So, it is needed to extract logic of searching potential expects
for actual member and already known expect class.

^KT-60668
^KT-60936
2023-08-22 12:14:42 +00:00
Nikita Bobko 830084a678 Revert "Force recompile all call-sites of ExpectedActualResolver.{findActualForExpected, findExpectedForActual}"
This reverts commit 529a1dd720.

This commit was needed to workaround broken incremental compilation in
JPS in Kotlin plugin. The incremental compilation bug is reported
KT-60759

As promised in 529a1dd720, after a few
days in `master` I revert it

Review: https://jetbrains.team/p/kt/reviews/11724/timeline
2023-08-21 15:11:33 +00:00
Nikita Bobko 577d0db3f1 [FE] Skip delegation descriptors during default params matching
^KT-61163 Fixed
Review: https://jetbrains.team/p/kt/reviews/11599/timeline

They can be safely skiped because we check overridden descriptors
anyway.

IMO, it's a bug that delegated descriptors are copied with default
params. But it's much harder problem, and my IMO can easily be wrong for
some weird reason.
2023-08-15 16:34:23 +00:00
Nikita Bobko 52f0f75175 [FE] Cleanup: rename areXyzCompatible -> getXyzCompatibility
Review: https://jetbrains.team/p/kt/reviews/11039/timeline

Motivation:
- Functions with prefix "are" must return Boolean. And
  AbstractExpectActualCompatibilityChecker even already contains some
  functions with prefix "are" that return Boolean (e.g.
  `areCompatibleCallableVisibilities`,
  `areCompatibleSupertypesOneByOne`, etc)
- Unification with functions that are prefixed with "are" and return
  Boolean
2023-08-10 15:46:48 +00:00
Nikita Bobko 529a1dd720 Force recompile all call-sites of ExpectedActualResolver.{findActualForExpected, findExpectedForActual}
This is needed to workaround broken incremental compilation in JPS in
Kotlin plugin. The incremental compilation bug is reported KT-60759

In Kotlin plugin I created the same commit which changes the name of the
function on the call-site.

Review: https://jetbrains.team/p/kt/reviews/11039/timeline

After a few days in master branch, I will revert this commit
2023-08-10 15:46:46 +00:00
Nikita Bobko d39755b578 [FE] Convert specific diagnostic for actual function with default arguments into a common incompatibility
^KT-59665 Fixed
Review: https://jetbrains.team/p/kt/reviews/11039/timeline

It's better to have this logic in common place
(AbstractExpectActualCompatibilityChecker) to avoid missing compilation
errors in the future

This commit fixes:
1. Missing compilation error for actual function with default arguments
   for 'actual typealias' KT-59665
2. Missing compilation error for actual function with default arguments
   for actual fake-override KT-59665

Alternative solution for KT-59665 is to create a special checker.

"incompatibility" vs "special checker":

Arguments for common incompatibility:
- What if we had a rule that expect and actual default params must
  match? If so then it certainly would be an incompatibility.
- Technically, we do the matching of expect and actual params (because
  we allow default params in common ancestors of expect and actual
  declarations).
- It's hard to check that the actual definition doesn't use default
  params because `ExpectedActualResolver.findActualForExpected` filters
  out fake-overrides and doesn't return them. It's not clear logic for
  me, that I'm afraid to touch.
  implicitActualFakeOverride_AbstractMap.kt test breaks if you drop this
  weird logic
- WEAK incompatibilities can be considered as "checkers". So it doesn't
  matter how it's implemented, as a "incompatibility" or a "checker"

Arguments against common incompatibility:
- Although we match expect and actual declarations to allow default
  params in common ancestors of expect and actual declarations, it's
  still can be considered that we check that the actual declaration
  doesn't have default params. And it doesn't feel right that we check
  correctness of the actual declaration in expect-actual matcher.
- ~~It may change the rules of expect actual matching~~ (It's not true,
  because ActualFunctionWithDefaultParameters is declared as WEAK
  incompatibility)
2023-08-10 15:46:46 +00:00
Roman Efremov 05cead2ab5 Fix implementation doesn't match name of property
Currently, property `hasSourceAnnotationsErased` returns the opposite
to what is stated in name. Invert it both in implementation and on
call site.

^KT-58551
2023-08-03 17:07:08 +00:00
Roman Efremov 11ccad7e40 [FE, IR] Add expect actual annotations incompatibility info into diagnostic
This is needed for more beautiful reporting and easier
implementation of quick fix in IDE.

^KT-58551
2023-08-02 13:12:31 +00:00
Roman Efremov 6611a55a60 [FE] Relax rules of matching @Target annotation on expect and actual
Allow `expect` targets to be subset of `actual`.

^KT-58551
2023-07-24 09:48:49 +00:00
Roman Efremov ad84c83ee9 [FE] Skip more special annotations in KMP annotation matching
Many errors are reported in stdlib with these annotations
(SinceKotlin, Deprecated, so on).
But having them only on expect is a valid case. E.g. SinceKotlin added
if some old platform-specific API becomes commonized.

^KT-58551
2023-07-24 09:48:49 +00:00
Roman Efremov 234f453173 [FE, IR] Don't check SOURCE annotations if actual declaration has no source
^KT-58551
2023-07-24 09:48:49 +00:00
Roman Efremov 1a4ab9bb4b [FE] Implement FE logic of expect actual annotations matching
This implementation only checks annotations set on expect/actual
declarations and requires further refinement (e.g. checking of other
annotation targets, class scopes within typealiases).

^KT-58551
2023-07-24 09:48:48 +00:00
Dmitriy Novozhilov 1b24b95cde [FIR] Check for subtyping during actualization of supertypes of expect class
^KT-59356 Fixed
2023-06-22 07:05:31 +00:00
Dmitriy Novozhilov 623019cff1 [FE] Move substitutor related methods to TypeSystemContext
Also use TypeSystemContext instead of TypeSystemInferenceExtensionContext
  in AbstractExpectActualCompatibilityChecker

This is needed to have an ability to implement ExpectActualMatchingContext
  for IR backend. IrTypeSystemContext may operate with type substitutors,
  but there is no sense to implement all methods from TypeSystemInferenceExtensionContext
  in it
2023-06-10 07:33:29 +00:00
Dmitriy Novozhilov 8338370fbd [FE 1.0] Provide implementation of ExpectActualMatchingContext for FE 1.0
^KT-58578
2023-05-19 10:19:17 +00:00
Mikhail Glukhikh d4f81cf67f K1: remove unused resolution diagnostic
Related to KT-55079
2023-04-19 07:24:05 +00:00
Roman Efremov c718c77c43 [FE] Check visibilities of expected and actual property setters are compatible
^KT-30905 Fixed
2023-04-06 13:10:30 +00:00
Roman Efremov 456d3e0f42 [FE] Prohibit expect fun interface to have non-fun actual counterpart
In K1 .isFun is always false for Java classes, so extra check
is added for that. This is not needed for K2, because .isFun is
true for all Java classes. Here it is not necessary to check
that interface has only one method, because such check will be
done in the place where interface implementation is created.

^KT-39362 Fixed
2023-04-05 07:31:58 +00:00
Mikhail Glukhikh d76b32daf2 K1: rename 'kotlinCall' -> 'selectorCall' in relevant places 2023-04-03 16:35:55 +00:00
Mikhail Glukhikh bd27ec840c K1: report swallowed diagnostic about receiver type mismatch
#KT-55056 Fixed
2023-04-03 16:35:55 +00:00
Mikhail Glukhikh 930237b60e K1: report swallowed diagnostic about upper bound violation
#KT-55055 Fixed
2023-03-24 14:27:03 +00:00
Mikhail Glukhikh 7a58c2e99f DiagnosticReporterByTrackingStrategy: refactor positioning 2023-03-22 15:42:26 +00:00
Mikhail Glukhikh 97bec59bc9 K1: add forgotten INFERRED_INTO_DECLARED_UPPER_BOUNDS for incorporation case
#KT-56169 Fixed
2023-03-17 12:08:36 +00:00
Ilya Muradyan 6ddf32d013 Scripts: synchronize calculation of parent in LexicalScopeWrapper to fix #EA-803423 2023-03-01 09:05:25 +00:00
Dmitriy Novozhilov 89c42e20c9 [FIR] Consistently use _function_ instead of _functional_ in names of classes and functions 2023-02-02 08:24:52 +00:00
Mikhail Glukhikh 565adf3075 K1: don't filter Enum.entries in tower to report error later
After this commit we:
- preserve Enum.entries synthetic property in tower even in case the bound feature is OFF
- report an error on Enum.entries call in specific checker if the feature is OFF
- give this synthetic property lower priority, no matter feature ON or OFF

#KT-55251 Fixed
2023-01-24 12:45:59 +00:00
Dmitriy Novozhilov 32f6b71525 [FE] Add ability to configure PublicDeclaration type approximation configuration
This configuration allows to choose what to do with local and anonymous types
2022-11-22 15:46:18 +00:00
Mikhail Glukhikh d41c1e7e99 Code cleanup: ExpectedActualResolver 2022-11-17 22:28:04 +00:00
Mikhail Glukhikh 82f1535007 K1: fix IIOBE in expect-actual checker with different type parameter number
#KT-54827 Fixed
2022-11-17 22:28:04 +00:00