Commit Graph

7745 Commits

Author SHA1 Message Date
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
Artem Kobzar 8d1a90c23c [K/JS] Support essential Kotlin collections (List, MutableList, Set, MutableSet, Map, MutableMap) for exporting into JS
^KT-34995 Fixed
^KT-44871 Fixed
2024-01-24 11:14:46 +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
Alexander Korepanov 0d06efb488 [JS FIR] Fix REIFIED_TYPE_FORBIDDEN_SUBSTITUTION for dynamic types
^KT-59987 Fixed
2024-01-23 17:52:03 +00:00
Alexander Korepanov 3dd4a0d868 [JS FIR] Add JS_NAME_CLASH tests for constructors
^KT-64867 Related
2024-01-23 10:30:10 +00:00
Alexander Korepanov 5da4d31d37 [JS FIR] Rework JS_NAME_CLASH diagnostic for constructors
- Fix a false positive JS_NAME_CLASH report on constructors
   from different classes but with the same JsName.
 - Allow the same JsName for class constructors and other top-level
   declarations. This behavior differs from K1, but it is correct
   since there is no real name clash in the generated JS code.

^KT-64867 Fixed
2024-01-23 10:30:10 +00:00
Alexander Korepanov fc584b7c33 [JS FIR] Add non-ASCII JsName tests
^KT-64463 Related
2024-01-23 10:00:18 +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
Ilya Kirillov 3a90cb00c7 [LL FIR] reuse the same function for registering K/N FIR session components as in the compiler
So, if a new component is registered in the compiler, it's not forgotten for the LL FIR

This registers `FirDelegatedMembersFilter` for K/N modules and fixes KT-64528

^KT-64528 fixed
2024-01-18 15:43: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
Kirill Rakhman e91e9d8ca8 [FIR] Don't lose error level enhancements in warning-level-enhanced arguments
The error-level enhancement is kept as warning-level and a new
LanguageFeature is introduced to turn the warning into an error.

#KT-63208 Fixed
#KT-63209

(cherry picked from commit 371b1eb3d5)
2024-01-18 08:27:10 +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
Mikhail Glukhikh 581cac3d45 K2: report EXPLICIT_TYPE_ARGUMENTS_... also on resolved qualifiers
#KT-64982 Fixed
2024-01-17 16:51:48 +00:00
Mikhail Glukhikh caa850e470 FIR: render resolved qualifier type arguments in dumps 2024-01-17 16:51:48 +00:00
Mikhail Glukhikh 0a21669fb9 K2: reproduce KT-64982 2024-01-17 16:51:48 +00:00
Brian Norman 8f9bb75e60 [FIR] Allow identity equality to be used in contract implications
^KT-63256 Fixed
2024-01-17 14:59:59 +00:00
Roman Efremov ee1ee965a1 [FIR] Fix incorrect work of K2 expect-actual matcher when actual is Java
...field, which is fake override.
This was failing in Stdlib with `expect HashMap` + actual typealias to
`java.util.HashMap`.

^KT-63624 Fixed
2024-01-17 14:47:41 +00:00
Roman Efremov 3d2a37ee41 [Test] Write reproducer test for expect-actual matching to Java field
..., which comes from super class, which incorrectly works in K2.

^KT-63624
2024-01-17 14:47:41 +00:00
Nikita Bobko 0dc8629312 [FIR] Don't report MUST_BE_INITIALIZED on private open properites
^KT-59074 Fixed

This solution is not ideal. Ideally, the allopen compiler plugin
shouldn't report `private` properites as `open` KT-64980, but it will
unpredictably break other things.
2024-01-17 14:18:06 +00:00
Nikolay Lunyak 96db6eb94f [FIR] Support tailrec safe-calls
^KT-63529 Fixed
2024-01-17 11:31:26 +00:00
Nikolay Lunyak a4b7697714 [FIR] Reproduce KT-63529
^KT-63529
2024-01-17 11:31:26 +00:00
Kirill Rakhman ec78747f2b [Tests] Add test for #KT-62956 2024-01-17 08:20:06 +00:00
Kirill Rakhman 9d91eb2510 [FIR] Fix inference based on recursive upper bound
#KT-59012 Fixed
2024-01-17 08:20:06 +00:00
Kirill Rakhman 251827c9aa [FIR] Don't approximate captured types
This fixes some type argument mismatch errors caused by a captured type
being approximated and then captured again.
Some places need to be adapted to work with captured types that
previously only worked with approximated types.

#KT-62959 Fixed
2024-01-17 08:20:05 +00:00
Mikhail Glukhikh 3c20a7b82a K1/K2: add test for KT-62959 2024-01-17 08:20:04 +00:00
Anastasia.Nekrasova 7429dd4b94 K2: Support for inter-module interaction for @SubclassOptInRequired
The inter-module interaction was partially supported, but the
DiagnosticCompilerTestFE10TestdataTestGenerated and
LFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated were
failing. This is because the arguments of annotations were not fully
resolved in loadExperimentalitiesFromAnnotationTo function.

^KT-60262 Fixed
2024-01-16 16:53:04 +00:00
Ivan Kylchik 672c945895 [K2] Add test to check deprecation reporting from java static method
#KT-57785 Can't Reproduce
2024-01-16 10:56:31 +00:00