Commit Graph

189 Commits

Author SHA1 Message Date
Pavel Mikhailovskii d75463a7d5 [KAPT] KT-65399 Fix rendering of types with names starting with $.
Solves a specific issue with Kotlin serialization, and most likely,
similar issues with synthetic classes.

Types with `$` in other positions will be still rendered incorrectly
due to imprecise conversion of such types from Kotlin to Java
in the analysis API.


Merge-request: KT-MR-14235
Merged-by: Pavel Mikhailovskii <Pavel.Mikhailovskii@jetbrains.com>
2024-02-12 11:15:36 +00:00
strangepleasures 9688c3e761 [KAPT] Improve stub formatting; check raw stubs in tests
Merge-request: KT-MR-14244
Merged-by: Pavel Mikhailovskii <Pavel.Mikhailovskii@jetbrains.com>
2024-02-09 15:41:37 +00:00
Pavel Mikhailovskii f81b1150b2 [KAPT] KT-65453 Disable generation of type annotations in Java stubs
A workaround for KT-65608


Merge-request: KT-MR-14236
Merged-by: Pavel Mikhailovskii <Pavel.Mikhailovskii@jetbrains.com>
2024-02-08 18:05:49 +00:00
strangepleasures 0dd3abba2a [KAPT] Support type annotations in K2 KAPT. Fixes KT-64479 2024-01-15 10:24:38 +00:00
Alexander Udalov c251eb19a6 Kapt: remove old JVM backend test data (2/2)
In this commit, .ir.txt expectation test data files for the JVM IR
backend are renamed to .txt. This is done as two separate commits so
that Git would recognize that these files were logically moved, not that
the contents of the original .txt files were changed.

 #KT-64680
2024-01-03 19:37:40 +00:00
Alexander Udalov 9c67616b25 Kapt: remove old JVM backend test data (1/2)
In this commit, .txt expectation test data files for the old JVM backend
are deleted.

 #KT-64680
2024-01-03 19:37:40 +00:00
Sonya Valchuk 588549d1d0 JVM_IR: add offsets to JvmStatic and JvmOverloads proxies
KAPT3 needs them to correct error types in arguments.

 #KT-64639 Fixed
2024-01-02 17:43:09 +00:00
strangepleasures b32f408767 [KAPT] KT-64389 Fix stub generation with generic type constraints 2023-12-19 13:33:38 +00:00
strangepleasures 1015ae858e [KAPT] KT-64301 Report invalid enum value names
Merge-request: KT-MR-13520
Merged-by: Pavel Mikhailovskii <Pavel.Mikhailovskii@jetbrains.com>
2023-12-13 17:53:52 +00:00
strangepleasures b84aa190d7 [KAPT] KT-64297 Mark deprecated members with @java.lang.Deprecated
Merge-request: KT-MR-13521
Merged-by: Pavel Mikhailovskii <Pavel.Mikhailovskii@jetbrains.com>
2023-12-13 17:18:54 +00:00
strangepleasures 03ed1d1d31 KT-62560 [SLC] Fix handling of empty varargs in annotations 2023-11-20 20:57:21 +00:00
strangepleasures 9c2ce475e2 KT-60821 [KAPT] Generate stubs without KaptTreeMaker
Merge-request: KT-MR-12979
Merged-by: Pavel Mikhailovskii <Pavel.Mikhailovskii@jetbrains.com>
2023-11-16 21:14:36 +00:00
strangepleasures 6a2cea8a8e [KAPT4] KT-62097 Keep import statements for unresolved annotation classes 2023-10-20 08:33:17 +00:00
strangepleasures cf01d2970f [SLC] [KAPT] KT-61916 Fix generation of annotations in annotation arguments 2023-09-14 13:21:07 +00:00
strangepleasures 6475942ced [KAPT4] A temporary workaround for KT-60482 2023-09-12 16:58:13 +00:00
strangepleasures 9d43945b19 [KAPT4] KT-61729 Resolve annotation arguments during generation of @Metadata annotations 2023-09-06 19:47:28 +00:00
Alexander Udalov d50d36f16c Kapt+JVM_IR: add regression test for KT-61212
#KT-61212
2023-08-31 17:58:04 +00:00
Alexander Udalov b3e4099703 Kapt tests: minor, remove STRIP_METADATA from properties.kt 2023-08-17 21:43:54 +00:00
Alexander Udalov e700a38a87 Kapt tests: minor, add some cases to properties.kt
To check that boolean "is" prefix is treated correctly, and Unit return
type is not translated to void. `@Deprecated` annotations are added just
so that the `$annotations` methods would also be generated.
2023-08-17 21:43:54 +00:00
Alexander Udalov 28e232f54f Kapt tests: minor, add case with optimized delegated property
In normal circumstances, it leads to the field `c$delegate` NOT being
generated (see KT-39054). However, it's not the case in kapt in any
mode:
- In the old JVM backend, this optimization is not supported.
- In JVM IR, property initializers are missing in light analysis, so
  backend cannot figure out that this property is optimizable.
- In kapt4, backend is not being run, and symbol light classes do not
  have information about this optimization.

Overall it doesn't matter much which stub is generated here because the
field is private, the test is added just in case.
2023-08-17 21:43:54 +00:00
strangepleasures 2423b7b62f [KAPT4] KT-51982 Implement generation of @Metadata annotations in Java stubs
Also adds rendering of @Metadata annotations in Kapt3 and Kapt4 tests
(currently disabled for a few tests).

Co-authored-by: Alexander Udalov <alexander.udalov@jetbrains.com>
2023-08-17 21:43:54 +00:00
Pavel Mikhailovskii 2002542ad2 Stub generation infrastructure (except for metadata generation) for KAPT+K2
This commit includes the basic Java stubs generation infrastructure and
the corresponding tests. The main entry point is called
Kapt4StubGenerator. Calls to it from production code will be added in a
separate commit.

 #KT-51982
2023-08-09 01:17:21 +00:00
Pavel Mikhailovskii 6e6a4d6411 KT-59836 [SLC] Copy type parameters from the parent interface to DefaultImpls methods 2023-07-10 13:11:21 +00:00
Alexander Udalov 04998cff8a Kapt+JVM_IR: fix error on delegation to anonymous object
In kapt stub generation mode, psi2ir does not generate bodies of
declarations. This means that the delegate type was translated into an
IrType which is based on a class which is not generated by psi2ir, thus
leading to an unbound symbol error. The fix is to avoid using anonymous
types for delegate fields in this mode.

 #KT-59211 Fixed
2023-06-16 23:03:39 +00:00
Alexander Udalov fd4e59f279 Kapt+JVM_IR: do not generate bodies of enum entries
#KT-59247 Fixed
2023-06-16 22:48:11 +00:00
Alexander Udalov d32268c5cb JVM: do not assume that methods have body in BridgeLowering
They don't have bodies in the kapt stub generation mode.

 #KT-58787 Fixed
2023-05-25 12:07:58 +00:00
Alexander Udalov c06ec84bb1 JVM: fix type mapping of big arity suspend function types
The code in IrTypeMapper was incorrectly translated from
KotlinTypeMapper during the development of JVM IR. The
`classDescriptor.hasBigArity` condition in KotlinTypeMapper was checking
if the class represents a function or a suspend function with big arity,
and the suspend function part was lost during conversion.

This resulted in incorrect generic signature being generated, which led
to malformed type exceptions from reflection, and compilation errors
from kapt stub generation.

Also, change a comment in irCodegenUtils to avoid confusion of numbered
function types (kotlin.jvm.functions.Function1, ...) with the big-arity
type kotlin.jvm.functions.FunctionN.

 #KT-58375 Fixed
2023-05-09 12:57:07 +00:00
Alexander Udalov 530725c6bf Kapt+JVM_IR: do not generate secondary constructor bodies
In addition to ceedad40f3, do not generate bodies of constructors which
delegate to super.

 #KT-58226 Fixed
2023-05-08 09:08:07 +00:00
Alexander Udalov 3120a35a88 JvmDefault: remove most tests on @JvmDefault
The tests are removed because JvmDefault is going to be deprecated with
error in KT-54746 and removed later in KT-57696.

Many of the removed tests already had existing counterparts with the new
modes `all` and `all-compatibility`. In this change, I've added such
tests where they were missing, and removed tests which were testing
behavior specific to the JvmDefault annotation, such as some
diagnostics.

 #KT-54746
2023-04-25 14:33:00 +00:00
Alexander Udalov bc7aea1426 Kapt+JVM_IR: generate delegated members correctly
Generate a declaration for each delegated member without body. If we
don't generate delegated declarations, subclasses will have incorrect IR
with unbound symbols in fake overrides.

 #KT-58027 Fixed
2023-04-19 23:04:45 +00:00
Mads Ager 699ad87be2 [KAPT+IR] Use ErrorType for unresolved delegate class.
^KT-57946
2023-04-17 16:49:11 +02:00
Alexander Udalov 287e0909cc Kapt+JVM_IR: do not generate super constructor call
#KT-57699 Fixed
 #KT-57939 Fixed
2023-04-17 10:40:15 +00:00
Pavel Mikhailovskii 85b5a4521e KT-56843 [SLC] Support unsafe property initializers 2023-03-28 08:17:37 +00:00
Alexander Udalov 17e4ed8ffc Kapt+JVM_IR: add stub converter test for KT-57388 2023-03-21 22:12:58 +01:00
Nikolay Lunyak bcfafc601e Add EnumEntries to minimal-stdlib-for-tests
This change allows to revert adding `WITH_STDLIB` directive
to tests which happened at `a9343aeb`.

Co-authored-by: Alexander Udalov <Alexander.Udalov@jetbrains.com>
2023-03-02 10:23:38 +00:00
Nikolay Lunyak a9343aeb7d [FIR] KT-55840: Ensure everything actually works
This inconsistency is present due to not using the `// WITH_STDLIB`
in the above tests. When K1 creates the enum, it tries to generate
`entries()`, and for that it tries to load `kotlin.enums.EnumEntries`,
but this is actually an unresolved reference. K1 silently swallows it,
and proceeds.

The reason K2 doesn't fail is that in order to generate `entries()` it
simply creates the necessary `ConeClassLikeType` with the desired
`classId` instead of loading the whole `ClassDescriptor`.

The reason we can still observe `$ENTRIES` and `$entries` in K1
is because they are generated during the JVM codegen, and it
only checks if the `EnumEntries` language feature is supported. It
doesn't check if the `entries` property has really existed in IR
(by this time it's expected to have already been lowered to the
`get-entries` function - that's why "has ... existed").

The reason why the codegen doesn't fail when working with
`kotlin.enums.EnumEntries` is because it creates its
own `IrClassSymbol`.

^KT-55840 Fixed

Merge-request: KT-MR-8727
Merged-by: Nikolay Lunyak <Nikolay.Lunyak@jetbrains.com>
2023-02-10 16:57:51 +00:00
Pavel Mikhailovskii 4c7f8ba196 KT-56457 Annotate Enum.entries with @NotNull 2023-02-09 20:13:56 +00:00
Alexander Udalov 1844869e8a Kapt+JVM_IR: fix ordering of properties in generated stubs
Apparently it depended on the ordering of the synthetic `$annotations`
methods generated for properties. And those methods were always
generated at the end of a Java stub by kapt because they lacked PSI
element, and thus `ClassFileToSourceStubConverter.convertClass` could
not compute their source position, and it placed them at the end as all
other synthetic methods.

The solution is to provide PSI element for `$annotations` methods in
JvmDeclarationOrigin. This origin is then collected in kapt in
`OriginCollectingClassBuilderFactory` and used for sorting, as in the
case of the old JVM backend.

 #KT-56360 Fixed
2023-02-06 21:34:10 +00:00
Alexander Udalov 94f1c579df Kapt+JVM_IR: do not generate SuspendFunction supertypes
#KT-54380 Fixed
2023-02-02 15:01:43 +00:00
Alexander Udalov 2849e45111 Kapt tests: change _ir.txt to .ir.txt
To be consistent with test data of other compiler tests.
2023-01-31 13:49:44 +00:00
Dmitriy Novozhilov 88efa6bfb6 Update tests after switching to LV 1.9 2023-01-30 09:29:57 +00:00
Nicklas Ansman Giertz 115bc6ac89 KAPT: Fix an ISE when processing unresolved generic types
Error types that are generic could sometimes throw an ISE when
generating the stub.

This fixes KT-43786
2023-01-17 11:40:13 +01:00
Alexander Udalov d85b23ebb9 Kapt+JVM_IR: do not attempt to transform error types in InsertImplicitCasts 2023-01-13 02:38:40 +01:00
Alexander Udalov 690fe7ac9a Kapt+JVM_IR: support error types in suspend functions
JVM IR generates the continuation parameter with the name `$completion`
instead of `continuation`.
2023-01-13 02:38:40 +01:00
Alexander Udalov 4f2551497d Kapt+JVM_IR: do not require KtFile for each generated class
In particular, JVM IR doesn't provide KtFile for a multifile facade in
JvmDeclarationOrigin (JVM backend provides KtFile of a random multifile
part). This led to multifile classes being completely ignored in the
JVM_IR version of kapt. Now they are generated correctly and the changed
test passes, but there's a _ir.txt expectation file because the order of
'foo' and 'bar' is different (which is not a problem).
2023-01-13 02:38:40 +01:00
Alexander Udalov 6d0628900e Kapt+JVM_IR: support annotations with error types
This is a hack to implement KT-32596 in the JVM IR version of kapt.
Basically we allow psi2ir to generate annotations whose classifier is
error class, which happens when it's unresolved. Because there's no
physical IR for an error class, we create stub IR for it via
SyntheticDeclarationsGenerator in case we'll need it.

With this hack, annotations with unresolved classifiers magically
survive all the way until the codegen (with a minor change in
IrBasedDescriptors) where they are generated as
`@error.NonExistentClass`, which then gets corrected by the kapt's
"correct error types" mode as in all other cases of error types.
2023-01-13 02:38:40 +01:00
Alexander Udalov 4a91957ff0 Kapt+JVM_IR: fix "correct error types" mode for delegated properties
Use the property as PSI element origin for delegated property accessors
and field in JVM IR as it is done in the old JVM backend. Otherwise kapt
"correct error types" mode can't find the property type and thus cannot
succeed in "resolving" it, which led to java.lang.Object being used as a
fallback.

Note that in the unmuted test, .txt and _ir.txt dumps differ only in an
unrelated NotNull annotation on a delegate field.

See also KT-37586 for some related changes which fixed this problem
initially in kapt.
2023-01-13 02:38:40 +01:00
Alexander Udalov 549bfb2d9e Kapt+JVM_IR: generate annotation property initializers
#KT-55490 Fixed
2023-01-13 02:38:40 +01:00
Alexander Udalov 1a5aedd27a Kapt+JVM_IR: unignore some tests 2023-01-13 02:38:39 +01:00
Pavel Mikhailovskii 38a56ba8e8 KT-55308, KT-55769 Sort InnerClasses entries. Add DONT_SORT_DECLARATIONS directive 2023-01-13 01:07:10 +00:00