Commit Graph

7980 Commits

Author SHA1 Message Date
Mikhail Glukhikh 4d49bdb8ca K2: add a black box test to confirm KT-53718 now works properly (JVM IR only)
Related to: KT-57584, KT-58110
2023-11-15 09:33:05 +00:00
Mikhail Glukhikh 4b1368409d K2: add a black box test to confirm KT-55705 now works properly 2023-11-15 09:33:05 +00:00
Mikhail Glukhikh f2ef41dbbd K2: add a black box test for KT-58874 to confirm work also in runtime 2023-11-15 09:33:03 +00:00
Mikhail Glukhikh cf9bd44cf7 K2: add test to confirm KT-54139 now works properly 2023-11-14 13:33:18 +00:00
Alexander Udalov 39fda3535a IR: fix internal visibility check in override builder
In case there are Java sources in the module, K2 creates two instances
of `FirModuleDescriptor` with the same name: one for Kotlin sources, one
for Java sources. When building fake overrides in IR, it's important to
understand that those are the same module. Currently it's done by
comparing the names, but in the future it may be improved in KT-62534.

The changed test was in fact unrelated to KT-61805, and the problem
there was rather that no fake override was created for internal property
`schemeState` in `InspectionProfileModifiableModel`.
2023-11-14 09:45:06 +00:00
Alexander Udalov 54705e5afc IR: copy context receiver parameters count in FakeOverrideCopier
#KT-63430 Fixed
2023-11-13 21:36:22 +00:00
Mikhail Glukhikh 4913c38e98 FIR2IR: insert spread for named argument against primitive vararg
#KT-60312 Fixed
2023-11-13 16:23:26 +00:00
Dmitriy Novozhilov 8578a0bf6a [FIR2IR] Properly insert casts for smartcasts in argument position
Previously cast inserter didn't consider expected type for arguments
  of function calls

^KT-63257 Fixed
2023-11-10 07:50:01 +00:00
Dmitriy Novozhilov c70a6425f5 [FIR2IR] Don't insert not-needed upcasts for smartcasted expressions
Related to KT-63257
2023-11-10 07:50:00 +00:00
Alexander Udalov 953f6ba6b6 K2: keep FlexibleNullability on enhanced type parameter types
Types based on type parameters which have both hasEnhancedNullability
and hasFlexibleNullability were incorrectly converted to IR: only
`@EnhancedNullability` annotation was added to the IR type. This means
that the nullability of the type started to matter, which is incorrect
because the type is supposed to be flexible.

This backfired in the IR fake override builder mode, where nullability
of methods inherited from both Kotlin maps and Java maps clashed, which
resulted in the exception from FakeOverrideRebuilder.

If the type is both flexible and enhanced, we're now adding
`@FlexibleNullability` to the IR type. Note that `@EnhancedNullability`
is not needed because it only affects primitive types which need to be
handled as wrapper types on JVM, but `@FlexibleNullability` already has
that effect.

IR still slightly differs from K1 for collection subclasses, which can
be seen for example in the changed IR text tests. This is to be
investigated later.

The change in tests is needed because the `kt48495*.kt` tests are now
passing on K2 in the IR fake override builder mode, while failing on the
vanilla K2.

This is related to KT-61370 but does not entirely fix it, although
curiously it fixes all remaining tests which were muted because of it.
2023-11-09 09:13:28 +00:00
Kirill Rakhman 7da271bab8 [FIR] Serialize context receivers using the correct local serializer
This leads to type ref referring to generic type variables being
serialized correctly.
When the type variable is declared on the member itself, it's written to
typeParameterName,
otherwise it's written to typeParameter. This is required for
deserialization to work correctly.

#KT-63227 Fixed
2023-11-08 10:26:34 +00:00
Dmitriy Novozhilov d08567c2c7 [FIR2IR] Approximate extension receiver type after type argument substitution
Frontend may leak captured types into type arguments, so they should be
  approximated before using them in fir2ir cast inserter to determine
 a specific type from smartcast

^KT-62863 Fixed
2023-11-07 12:37:19 +00:00
Alexander Udalov d2ebaf4e6c Minor, add regression test for K2 delegation issue
#KT-62120
2023-11-07 12:30:45 +00:00
Nikita Bobko 0fc7ea6004 [IR] Workaround expectActualOverloads test failure
Under the hood this test was broken before my KT-62590 changes. KT-62926
demonstrates it
2023-11-06 14:41:27 +00:00
Ilya Chernikov 31f9e9e7a8 K2 Scripting: implement basic metadata serialization support
#KT-62305 fixed
NB: kotlin reflection do not see script class constructor after
this change, and it's ok, since the fact that the script is compiled
into a class is an implementation detail.
If needed, java reflection could be used to access the constructor.
2023-11-03 21:54:23 +00:00
Alexander Udalov 968dfddbc9 Tests: adjust test data for bytecode listing tests
- remove obsolete `IGNORE_BACKEND: JVM` directives
- move contents of .ir.txt files to the corresponding .txt
2023-11-02 10:59:29 +00:00
Alexander Udalov 9ae16fd66e Tests: unmute bytecode listing tests for JVM_IR
Mute them for the old JVM backend instead. JVM IR behavior is fine in
all cases except maybe `destructured.kt`, for which there's now an issue
KT-63075.
2023-11-02 10:59:28 +00:00
Mikhail Glukhikh 290adda8fc Calculate empty array literal types in FIR2IR instead of deserializer
This commit handles situations when some annotation in deserialized code
has an empty array literal argument [] or even non-empty [something].
Before this commit, we tried to guess a type of this array by "resolving"
the relevant annotation class and looking into the corresponding
parameter. Sometimes it can work, but also it can provoke recursive
resolve e.g. when the annotation class is a nested class in the same scope.
In this commit we changed the behavior in the following way:
- first, for non-empty array literals in deserialized code we just
take the array type from the corresponding array literal element
- second, for empty array literals we no more try to "guess" anything.
Instead we approximate array type as Array<Any>, and later at FIR2IR
stage we use the corresponding parameter type instead. At FIR2IR stage,
everything is already resolved and problems with recursions are no more
possible.

#KT-62598 Fixed
2023-10-31 12:30:29 +00:00
Mikhail Glukhikh 19a95f2fb4 K2: swap heuristics in AnnotationLoader (related to KT-62598)
Before this commit, we first tried to guess a type of array literal
in deserialized annotation (it's a strange heuristics which can
lead to SOE and maybe not needed at all, see KT-62598, KT-62929),
and then, if unsuccessful, took the type from the first literal element,
if any. Since the second heuristic is much more clear, safe, and
understandable, in this commit they were swapped.

This commit does not fix KT-62598 in general case,
but decreases a set of cases when it can occur to
empty array literals only.
See the commented line at the end of the added test.
2023-10-31 12:30:29 +00:00
Vladimir Sukharev 604c8edd1c [K/N] Fix kt53261_* tests to be dummy in debug mode
^KT-62157 Fixed


Merge-request: KT-MR-12720
Merged-by: Vladimir Sukharev <Vladimir.Sukharev@jetbrains.com>
2023-10-25 16:07:01 +00:00
Dmitrii Gridin ec3cfdefcb [LL FIR] add missing file node to control flow graph
The file

^KT-62834 Fixed
2023-10-24 10:30:55 +00:00
Dmitrii Gridin 2eb761adae [LL FIR] generate resolution tests over codegen/box testData
Such testData can contain contract violations and other resolution
problems, so we should check them as well

^KT-62776
^KT-62832
^KT-62834
^KT-62836
2023-10-24 10:30:55 +00:00
Dmitrii Gridin 5a786e25c2 [codegen] testData: move WITH_STDLIB to global scope 2023-10-24 10:30:55 +00:00
Dmitrii Gridin 09a1df9ee5 [codegen] testData: add missing directory structure for Java classes 2023-10-24 10:30:55 +00:00
Vladimir Sukharev e43b634122 [K/N] Migrate most simple filecheck tests to new infra
^KT-62157


Merge-request: KT-MR-12376
Merged-by: Vladimir Sukharev <Vladimir.Sukharev@jetbrains.com>
2023-10-23 10:07:28 +00:00
Ivan Kylchik 4334ae9da9 [FIR] Add JvmName to the list of REQUIRED_ANNOTATIONS
We need to resolve `JvmName` as soon as possible because
it can be analyzed in `FirJavaElementFinder` to create
the correct class stub.

#KT-57802
2023-10-20 16:33:20 +00:00
Ivan Kylchik a45bb8d92b [FIR] Find the correct FIR file in Java finder for file with JvmName
#KT-57802
2023-10-20 16:33:20 +00:00
Ivan Kylchik 8c7c44f9f5 [FIR] Fix evaluation of Java properties for Char and String types
#KT-57802
2023-10-20 16:33:20 +00:00
Ivan Kylchik 7935b2bdb1 [FIR] Allow to evaluate top level const properties in Java world
#KT-57802
2023-10-20 16:33:20 +00:00
Ivan Kylchik 886ef1a4b4 [FIR] Support the simple case of java field interpretation
#KT-57802
2023-10-20 16:33:20 +00:00
Nikita Bobko 0f82baf841 [FE 1.0] 2/2 Drop AllowDifferentMembersInActual from compiler and testData
The annotation was dropped in the previous commit
2023-10-20 14:37:09 +00:00
Alexander Udalov 931c2ce47a Reflection: fix calling suspend fun returning value class over primitive
#KT-47973 Fixed
2023-10-20 08:50:26 +00:00
Ilya Chernikov 268d058bbb Implement missing invoke resolution branch with context receivers
#KT-61937 fixed
Note: the current implementation only resolves for a single receiver
in each group. See KT-62712 and KT-62709 for the followup.
2023-10-19 19:39:31 +00:00
Evgeniy.Zhelenskiy b89d8a65a1 [Reflection] Fix parsing JVM function descriptors
#KT-60708
2023-10-19 19:09:31 +00:00
Dmitriy Novozhilov 940567978d [FIR2IR] Treat delegated functions as fake-overrides
Delegated callables in FIR are session-dependant (as fake-overrides),
  so it's incorrect to use their FIR as a key for declaration storage.
  Pair of original function and owner lookup tag should be used instead

^KT-62671 Fixed
2023-10-19 13:15:48 +00:00
Pavel Kunyavskiy da488f513f [IR] Fix file modules after actualization
When files from different IrModules are merged in IrActualizer
their IrModule link was not updated. This led to assuming them
as different modules, and incorrect internal visibility handling.

^KT-62623
2023-10-19 10:16:45 +00:00
Vladimir Sukharev 9b9ddb760a [FIR2IR] Coerce last operator in a loop to Unit
One of many fixes for https://youtrack.jetbrains.com/issue/KT-59781/K2-investigate-implicit-cast-generation-in-fir2ir-vs-psi2ir

Merge-request: KT-MR-12629
Merged-by: Vladimir Sukharev <Vladimir.Sukharev@jetbrains.com>
2023-10-19 09:53:46 +00:00
Dmitriy Novozhilov 847442d547 [Test] Add regression test for KT-60876 2023-10-19 06:58:14 +00:00
vladislav.grechko 897eab6b50 Do not add nullability annotations to the methods of local classes
Nullability annotations are useless for the methods of local classes
due to their restricted scope.

^KT-62513: Fixed
2023-10-18 19:48:38 +00:00
Dmitriy Novozhilov 9366847e96 [FIR2IR] Properly approximate intersection types during fir2ir conversion
^KT-62544 Fixed
2023-10-18 13:02:11 +00:00
Mikhail Glukhikh 4ed7504d87 FIR deserializer: apply attributes on type parameter-based types
#KT-62578 Fixed
2023-10-18 10:30:31 +00:00
Dmitriy Novozhilov 3f89f03b54 [IR Actualizer] Set overridden symbols for property accessors 2023-10-17 12:46:28 +00:00
Dmitriy Novozhilov 3b6ad36af1 [Test] Update/unmute tests after previous fixes
It's hard to tell which exact commit fixed each test
2023-10-17 12:46:28 +00:00
Dmitriy Novozhilov 84f41b7d68 [FIR] Use lower bound of supertype in findClassRepresentation for intersection types 2023-10-17 12:46:28 +00:00
Dmitriy Novozhilov c3f3a4192c [FIR] Check supertypes hierarchy for java classes during creation of synhtetic properies
^KT-62394 Fixed
2023-10-17 12:46:28 +00:00
Dmitriy Novozhilov 61ec143b74 [FIR] Don't generate delegated members for java methods with default implementation
^KT-62334 Fixed
2023-10-17 12:46:27 +00:00
Dmitriy Novozhilov 5857e6cc5d [Test] Mute some tests because of KT-62393 and KT-62394 2023-10-17 12:46:27 +00:00
Dmitriy Novozhilov 8bf4d3cbf7 [Test] Mute some tests because of KT-62334 2023-10-17 12:46:27 +00:00
Dmitriy Novozhilov 3d6ec0ec75 [FIR2IR] Automatically store IR declaration in its parent upon creation
Previously, creating a declaration with Fir2IrCallableDeclarationsGenerator/
  Fir2IrClassifiersGenerator didn't guarantee that this declaration will
  be actually added to the list of parent class/file declarations, which
  lead to situations when FIR2IR created some declarations in the air
  (mostly fake-overrides)
2023-10-17 12:46:27 +00:00
Dmitriy Novozhilov 34d0f3dbc2 [FIR2IR] Correctly calculate ir origin for f/o callables in declarations generator
This change uncovers one problem, which causes some MPP tests to fail
This problem will be fixed in further commits

Uncovers KT-62535
2023-10-17 12:46:27 +00:00