Commit Graph

6428 Commits

Author SHA1 Message Date
Dmitry Savvinov 6661a66fc3 [Tests] Add tests on smartcasts on static Java fields
Current behavior for different modules is undesired, will be fixed in
the next commit

^KT-58279
2024-01-31 09:53:45 +00:00
Nikolay Lunyak 811e8d7c3b [FIR] Add more corner cases for KT-65058
^KT-65058
2024-01-31 08:27:34 +00:00
Nikolay Lunyak 4ee03a3a0c [FIR] Allow accessing protected members via local inheritors
^KT-65058 Fixed
2024-01-31 08:27:34 +00:00
Nikolay Lunyak b6e913cde7 [FIR] Reproduce KT-65058
^KT-65058
2024-01-31 08:27:33 +00:00
vladislav.grechko d27adf6677 [FIR] Forbid multiple labels per statement
^KT-53629: Fixed
2024-01-30 19:58:53 +00:00
vladislav.grechko cd5b38b958 [FIR] Unwrap error expressions when detecting USAGE_IS_NOT_INLINABLE
Otherwise, false positive USAGE_IS_NOT_INLINABLE may be detected

^KT-65316: Fixed
2024-01-30 19:58:53 +00:00
Mikhail Glukhikh ed246d372b K2: introduce platform-dependent filtering for non-JVM platforms
This commit fixes a false negative in testData/cli/metadata/getOrDefault
Related to KT-57268
2024-01-30 19:44:00 +00:00
Mikhail Glukhikh 672b5ba0d7 K2/Java: implement platform-dependent function filtering in JvmMappedScope
We drop Kotlin function 'remove' or 'getOrDefault' from JvmMappedScope,
if it has platform-dependent annotation, and the bound Java class scope
does not contain a function with the same signature.

#KT-57268 Fixed
2024-01-30 19:44:00 +00:00
Brian Norman 76b9ba05fd [FIR] Lambda reassigned arguments should not have contracts applied
When applying function contracts to arguments, make sure the argument
variable hasn't been reassigned within a lambda. Contracts can only be
applied to unchanged variables, otherwise outdated type statements could
be added to the variable.

^KT-63151 Fixed
2024-01-30 17:23:56 +00:00
Brian Norman a2c9e5b36a [FIR] Copy implications from previous data flows when there is only one
Postponed lambdas introduce a host of challenges in data-flow analysis.
While inheriting type statements was disabled while these challenges are
being considered, we must still copy type statements from non-postponed
lambda edges. It seems the same is true for implications.

Implications are copied from previous flows when there is only a single
previous flow. That is because it never seemed to be required based on
test results. However, a recent test case revealed that copying is
required when there are multiple previous flows, but only one flow is
from a non-postponed-lambda node.

Combining implications from multiple non-postponed-lambda nodes did not
have an impact on test results, so until such a test case can be
created, the overhead of calculating common implications from multiple
flows will be avoided.

^KT-63351 Fixed
2024-01-30 17:22:31 +00:00
vladislav.grechko 9aa8fb80e7 Set correct IR origins for inc/dec operations
NB: in order to produce correct IR origins, the source element kinds for
some FIR elements has been changed. As a side effect, mapping PSI to FIR
slightly changed: namely, for `a[b]++`, `a[b]` used to be mapped on
`set` call or callable reference, but now it is mapped on `get` call.

^KT-61891: Fixed
^KT-64387: Fixed
2024-01-30 14:26:10 +00:00
Brian Norman 7f9774819c Revert "[FIR] Do not smartcast class delegation implemented properties"
This reverts commit bb6f466162.

Reverting the fix for KT-57417 as it causes failures in IntelliJ and
Space projects. May reintroduce fix after failures are investigated and
resolved.
2024-01-29 19:24:03 +00:00
Nikita Bobko 19c46662c6 [FIR] Fix missing ACTUAL_WITHOUT_EXPECT when expect is fake-override
^KT-65270 Fixed
KT review: https://jetbrains.team/p/kt/reviews/14064/timeline
IJ review: https://jetbrains.team/p/ij/reviews/124657/timeline
2024-01-29 14:56:49 +00:00
Nikita Bobko c214c5445a [FIR] Implement EXPECT_AND_ACTUAL_IN_THE_SAME_MODULE
^KT-60367 Fixed
KT review: https://jetbrains.team/p/kt/reviews/14064/timeline
IJ review: https://jetbrains.team/p/ij/reviews/124657/timeline
2024-01-29 14:56:48 +00:00
Brian Norman bb6f466162 [FIR] Do not smartcast class delegation implemented properties
When a property is implemented via class delegation, it should be
considered unstable for smart-casting. This is because it is unknown
what kind of stability the underlying class delegate property has. It
could be a stable property, or it could be implemented via a custom
getter and unstable.

^KT-57417 Fixed
2024-01-29 14:20:11 +00:00
Anastasia.Nekrasova 1d817e2ace [K2]: Missing error and miscompilation in destructuring declaration delegation
In convertDestructingDeclaration, property delegates are mistakenly
treated as valid expressions for destructuring, but they should be
ignored.

#KT-65021 Fixed
2024-01-29 07:56:43 +00:00
Denis.Zharkov df2a1d4d02 K2: Refine handling of Delegate resolution mode
- Move it out of the ContextDependent hierarchy
- Get rid of many controversial checks that were necessary because
Delegate was a ContextDependent inheritor
- Actually fix semantics for lambda processing

Previously, lambdas as delegate expression were not being analyzed
thus leading to an exception (see KT-64635), and this change
forces analyzing them in the same mode as ContextIndependent
(thus `{}` made by default `() -> Unit` leaving to DELEGATE_SPECIAL_FUNCTION_MISSING)

Before this change, new test was failing with an exception.

I've analyzed all `is ContextDependent` and it seems that none of them
is relevant to delegates.

^KT-64635 Fixed
2024-01-26 16:56:07 +00:00
Nikolay Lunyak 47a51f6499 [FIR] Fix failing Space build
Build failure was introduced by `9b786d35`,
where I forgot that typealiases exist.

^KT-64891
^KT-65336 Fixed

Merge-request: KT-MR-14087
Merged-by: Nikolay Lunyak <Nikolay.Lunyak@jetbrains.com>
2024-01-26 16:32:18 +00:00
Evgeniy.Zhelenskiy 55adeba011 [FIR] Include anonymous objects in containingDeclarations in FirDeclarationsResolveTransformer.kt
K1 and K2 still differ because of KT-58203

#KT-63434
2024-01-26 16:08:45 +00:00
Kirill Rakhman 213967e25c [Tests] Fix incorrect code in tests 2024-01-25 15:55:19 +00:00
Denis.Zharkov 5db1bb921b Temporary comment out some parts of a slow diagnostic test
K2 version runs like for 15s.

It became slow after PCLA (KT-59791) was implemented,
and the reasons for that is the presence of a lot of interconnected TV
which leads to O(NUMBER_OF_CONSTRAINTS*NUMBER_OF_VARIABLES)
asymptotic during constraint incorporation.

The test itself in any way doesn't represent some common BI use case,
so it seems reasonable to mute it temporary.

^KT-65005 Related
2024-01-25 11:11:36 +00:00
Evgeniy.Zhelenskiy dc578b1c5f [FIR] Exclude class type arguments checks for type parameters from outer functions
#KT-63577
2024-01-25 11:04:25 +00:00
Denis.Zharkov 7b82ca8b6f K2: Fix false-positive on delegated constructor call of outer class
See callingOuterGenericClassConstructorWithSelfTypes.kt
Previously, for A<B>(""), we used substituted constructor
where `X` was substituted with `B` (or `A<X>.B`).

But when resolving the call for constructor, we use `X`
as a type variable of the call, thus in some positions
we used `X` as TV (Xv in the comments) and somewhere `X` as a type
parameter, thus leading to contradictions (see clarifying comment).

The idea of the fix is simply repeating of the regular (not delegated)
constructor call resolution:
- We substitute only type parameters of outer class
- All the declared parameters of the callee are being checked
through regular resolution & inference mechanisms.

NB: Diagnostic only being reported on arguments because there
when we add `String <: Any` constraint it fails due to existing
contradiction in the CS.

Without the argument/parameter the error is just being lost, but that's
a different story (seeKT-65224).

^KT-64841 Fixed
2024-01-24 12:51:22 +00:00
Denis.Zharkov 81d559ad7f K2: Add test data for KT-64841 showing its current state 2024-01-24 12:51:22 +00:00
Nikolay Lunyak 3024ec3da3 [FIR] Add // FIR_DUMP to some implicit invoke tests
Although these dumps don't really show if
something is a `FirFunctionCall` or a
`FirImplicitInvokeCall`, they do show what
goes into the receiver, and what are value
arguments.
2024-01-24 12:49:57 +00:00
Nikolay Lunyak 9b786d35f8 [FIR] Fix NO_RECEIVER_ALLOWED
If we do create an implicit invoke call, and
then put the receiver into the argument list,
we should mark it.
2024-01-24 12:49:56 +00:00
Nikolay Lunyak eb11901d43 [FIR] Add some corner case tests for KT-64891
Note that there are some that K2
correctly supports, while K1 fails.

^KT-64891
2024-01-24 12:49:56 +00:00
Nikolay Lunyak 3a36a786d4 [FIR] Properly generate implicit invoke calls for a.(b)()
^KT-64891 Fixed
2024-01-24 12:49:55 +00:00
Nikolay Lunyak 8e6e447d6d [FIR] Reproduce KT-64891
^KT-64891
2024-01-24 12:49:55 +00:00
Dmitriy Novozhilov e8f5e35a86 [FIR] Consider expect declarations in defaults arguments inheritance checker
Actual functions cannot declare default values for parameters
Corresponding expect function should be checked instead
2024-01-24 10:45:00 +02:00
Dmitriy Novozhilov 2982f548d4 [Test] Update testdata of MPP diagnostic tests after previous changes
Related issues: KT-58845, KT-58881, KT-64187
2024-01-24 10:45:00 +02:00
Dmitriy Novozhilov 77547c0312 [Test] Add more diagnostic tests for cases with expect class in supertypes
Related issues: KT-58845, KT-58881, KT-64187
2024-01-24 10:44:59 +02:00
Dmitriy Novozhilov ed04cca62b [Test] Move some MPP diagnostic tests into a dedicated folder
All those tests check different diagnostics on class scopes
2024-01-24 10:44:59 +02:00
Mikhail Glukhikh e42c1be354 K2: use intersection scope override checker also in intersection scope
In more details, we use either platform override checker (if we came
from platform) or the combined intersection scope override checker
at this place. Also this commit fixes various places around
JavaOverrideChecker, allowing to apply it in intersection override
checker properly:
- don't consider return types in this place
- apply JavaOverrideChecker if at least one candidate is from Java
- compare type primitivity closer to K1 logic

#KT-62554 Fixed
Partially fixes KT-63242
2024-01-24 08:39:18 +00:00
Mikhail Glukhikh 54d978ba86 K2: add various tests describing current KT-62554 / KT-63242 behavior 2024-01-24 08:39:18 +00:00
Brian Norman 17a1871b83 [FIR] Make sure the primary constructor is first in class CFG
The primary constructor of a class needs to be the first subgraph of the
class control-flow graph. Based on the Kotlin specification, class
initialization order goes first primary constructor, in-place
declarations (properties and init blocks), and then secondary
constructors. If the class doesn't have a primary constructor, then it
is just skipped in the order.

Unfortunately, the class control-flow graph had in-place declarations
first and then all constructors. Instead, we should treat the primary
constructor as the first in-place declaration, and then continue with
the existing processing as secondary constructors. This will guarantee
that super constructor calls have the correct property initialization
information.

^KT-65093 Fixed
2024-01-23 23:16:00 +00:00
Brian Norman c628172235 [FIR] Disallow qualified access to uninitialized fields in delegate
When using a field as the delegate for a super-interface of an object,
make sure uninitialized fields are not allowed. Specifically, disallow
access to these fields when referenced via object qualifier.

^KT-56489 Fixed
2024-01-23 23:16:00 +00:00
Nikolay Lunyak c55a7dd038 [FIR] Add SAFE_CALLABLE_REFERENCE_CALL
^KT-59835
2024-01-23 08:46:29 +00:00
Nikolay Lunyak 4fed4b6640 [FIR] Add more tests for RESERVED_SYNTAX_IN_CALLABLE_REFERENCE_LHS
It's a bit hard to reason about how different
diagnostics correspond to one another from
the existing tests.

^KT-59835
2024-01-23 08:46:29 +00:00
Ilya Chernikov a5c2eb66a2 K2 Scripting: add missing contracts resolving in scripts
#KT-64074 fixed
2024-01-19 15:54:53 +00:00
Ivan Kylchik 6c3aa6568e [FIR] Properly check constructor call in FirConstCheckVisitor 2024-01-19 11:40:39 +00:00
Pavel Kirpichenkov ce3c05500e [LL] Sort modules from the same KMP project in symbol providers
Sort dependency modules topologically if they belong to the same KMP
project, preserving their relative positions. Sorting all modules and
changing positions of unrelated modules can be harmful: in the case of
a classpath hell, IDE results can become different from runtime
behavior. Sorting in place can help to avoid this problem, because
conflicting declarations shouldn't be allowed in different source sets
of the same multiplatform project.

KTIJ-27569
2024-01-19 10:20:52 +00:00
Ivan Kochurkin e3ddc843bc [FIR] Fix and simplify FirUnsupportedArrayLiteralChecker 2024-01-18 14:39:54 +00:00
Ivan Kochurkin 2be9a341ca [FIR] Report ARGUMENT_TYPE_MISMATCH for nested array literals
^KT-61843 Fixed
2024-01-18 14:39:54 +00:00
Ivan Kylchik aecf05c4ac [FIR] Use ConeKotlinType to represent vararg's element type
We are using `ConeKotlinType` instead of `FirTypeRef` to represent
that element type of vararg doesn't have any source. It has a type
that was inferred. If we try to specify a source, then we could
end up with the incorrect place for diagnostic.

#KT-59682 Fixed
2024-01-18 13:33:48 +00:00
Kirill Rakhman 582dd1d3c0 [FIR] Only don't approximate nested captured arguments if they have recursive supertypes
This fixes a compiler crash
IllegalStateException: Captured type for incorporation shouldn't escape
from incorporation

The crash occurs when a captured type with status FOR_INCORPORATION
is two layers deep inside a captured type with status FROM_EXPRESSION.
We first check if approximation is required for the most outer captured
type in AbstractTypeApproximator.approximateCapturedType.
Then we encounter the second captured type with status FROM_EXPRESSION
in AbstractTypeApproximator.approximateParametrizedType.
At this point, we stop checking and miss the third captured type with
status FOR_INCORPORATION.

Unfortunately, we can't check recursively if nested captured types
need to be approximated because of types with recursive super types
(the original reason why the extra check was introduced).
That's why we restrict the second check to types with recursive
super types, effectively restoring the previous behavior for all other
types.

#KT-65050 Fixed
2024-01-18 09:22:15 +00:00
anzhela.sukhanova 7587f73846 [Test] KT-61937: add tests with context functions and naming clash
Update tests for ^KT-61937


Merge-request: KT-MR-13678
Merged-by: Anzhela Sukhanova <anzhela.sukhanova@jetbrains.com>
2024-01-18 08:27:31 +00:00
Evgeniy.Zhelenskiy 70d1a2ea8c [FIR] Report package usages as a LHS
#KT-59972
2024-01-17 17:28:46 +00:00
Mikhail Glukhikh e999e289ee K2: split EXPLICIT_TYPE_ARGUMENTS_IN_PROPERTY_ACCESS to property/objects
Related to KT-64982
2024-01-17 16:51:48 +00:00
Mikhail Glukhikh 4fd73b06e2 FIR: render FirErrorResolvedQualifier properly 2024-01-17 16:51:48 +00:00