Commit Graph

148 Commits

Author SHA1 Message Date
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
Nicklas Ansman Giertz 22ab43838b KAPT: Skip importing java.lang.System in the stubs
This fixes KT-43117
2023-01-12 18:01:10 +01:00
Nicklas Ansman Giertz 3c69a0493e KAPT: Fix error types for receivers and property setters in stubs
When using correct error types and there is a property setter or
receiver for an unknown type then the parameter type would be `Object` instead
of the error type.

This fixes KT-46965 and KT-46966
2023-01-12 02:13:08 +01:00
Nicklas Ansman Giertz dd051c1556 KAPT: Preserve the order of annotations in the stubs
Previously the annotations were included in reverse order. With this
change they are kept in the same order as in the source file.

This changes the test case for KT-23427 but that issue seems to relate
to annotation arguments that are missing, not the order of repeatable
annotations.

This fixes KT-51087
2023-01-11 22:01:22 +01:00
Alexander Udalov 5848b2fde6 Kapt+JVM_IR: add IrKotlinKapt3IntegrationTest 2022-12-07 21:14:29 +00:00
Mads Ager 30002e29d1 [KAPT+JVM_IR] Do not generate initializers for delegated properties.
^KT-54870 Fixed
2022-11-28 22:27:09 +01:00
Alexander Udalov c813e03c1e Kapt+JVM_IR: do not generate nested enum as final
#KT-54187 Fixed
2022-10-24 12:48:22 +00:00
Daniel Santiago 189be2b117 [KAPT] Setup KaptJavaLog writers during initialization.
Migrate KaptJavaLog to not used deprecated constructor in newer JDKs and instead set up the writers during initialization. This enables us to get rid of KaptJavaLog17.

Fixes KT-54030
2022-10-11 23:48:18 +02:00
Nicklas Ansman Giertz b02948b5f7 KAPT: Kapt generates illegal stubs for private interface methods
Interface methods that were private got both the `default` and `private`
modifiers when using `jvm-default=all` which is not valid.

The stub will now just contain `private` in this case.

This fixes KT-48013.
2022-09-26 12:21:56 +02:00
Dmitriy Novozhilov 9c41e75802 [KAPT] Migrate kapt tests to new test infrastructure 2022-07-20 10:12:24 +00:00
Pavel Mikhailovskii c3c09aa95a KT-4107 Data objects 2022-06-28 16:58:20 +02:00
Mikhael Bogdanov 162ca4ac2b KAPT+IR: support IR error types
#KT-49682
2022-06-20 11:42:53 +00:00
Alexander Udalov 448cba07bb Psi2ir: do not generate init block body in kapt mode 2022-06-17 16:51:06 +02:00
Alexander Udalov 7e9d7c895a Kapt: add flag kapt.use.jvm.ir for enabling JVM IR support
#KT-49682
2022-06-17 16:51:06 +02:00
Mikhael Bogdanov 093b1bebb0 KAPT+IR: Generate LVT in kapt mode 2022-03-22 09:50:08 +00:00
Mikhael Bogdanov 41a54241bb Update testdata 2022-03-15 11:38:04 +01:00
Mikhael Bogdanov 15c3dd527c KAPT+IR: Support data classes 2022-03-15 11:38:04 +01:00
Mikhael Bogdanov ceedad40f3 KAPT+IR: Support secondary constructors 2022-03-15 11:38:03 +01:00
Mikhael Bogdanov ccbecbaccb KAPT+IR: Update tests 2022-02-17 12:26:42 +01:00
Mikhael Bogdanov f05c72d48f KAPT+IR: Properly process annotations and backing field annotations 2022-02-17 12:26:42 +01:00
Mikhael Bogdanov ea2bf3c867 KAPT+IR: Support -Xjvm-default modes 2022-02-17 12:26:41 +01:00
Mikhael Bogdanov 00f2b83b84 KAPT+IR: Support @JvmOverloads annotation 2022-02-17 12:26:41 +01:00
Mikhael Bogdanov 7ec19d015c KAPT+IR: Properly process repeatable annotation
~review fix
2022-02-17 12:26:41 +01:00
Mikhael Bogdanov d810d93578 IR: Keep annotations in enum constructor during lowering 2022-02-17 12:26:40 +01:00
Alexander Udalov 032d69aa41 Kapt: handle special names correctly
Parameter names of some methods are different in JVM IR, for example
extension receivers of property `$annotations` methods are named
`<this>`, which made the `Name.identifier` call fail. It seems fine to
use the "p + index" name for this instead.

 #KT-49682
2022-02-08 20:15:14 +01:00
Alexander Udalov 07d3e3a5bd Kapt: support property $annotations methods for JVM IR
`is PropertyDescriptor` check doesn't work for JVM IR where descriptor
is created on-the-fly and is an `IrBasedSimpleFunctionDescriptor`.

 #KT-49682
2022-02-08 20:15:14 +01:00
Alexander Udalov 25edf64daf Psi2ir: support mode without generation of bodies
This is needed for kapt + JVM IR.

 #KT-49682
2022-02-08 20:15:14 +01:00
Alexander Udalov b3820564b0 Kapt: never generate enums as final
Behavior differs between JVM and JVM_IR backends here because in JVM,
the class descriptor comes from the frontend, and its modality for enum
is never final. For JVM IR, the class descriptor is based on IrClass,
whose modality is sometimes final for enum, presumably because it's
easier for backends (see `ClassGenerator.getEffectiveModality`).

 #KT-49682
2022-02-08 20:15:14 +01:00
Alexander Udalov fc2c0eea27 JVM IR: generate source-retained annotations in kapt mode
#KT-49682
2022-02-08 20:15:13 +01:00
Alexander Udalov 1df2851611 IR: use names $this/$receiver for receivers in copied static functions
Similarly to the other places in the IR backend (e.g. see
`copyValueParametersToStatic` in the same file).

In JVM IR, these names are used for example for receiver parameters of
methods copied to DefaultImpls classes. Since Java stub code generated
by kapt mentions them, it fixes a few issues in tests on kapt + JVM IR
(KT-49682).
2022-02-08 20:15:13 +01:00
Alexander Udalov f6d3bb5b1b Kapt: add JVM IR expectations for some tests
All of these have a different order of declarations and/or extra
`@NotNull` annotations on fields, both of which doesn't seem like a
problem.

 #KT-49682
2022-02-08 20:15:13 +01:00
Alexander Udalov bcd221f714 Kapt: use descriptorBasedTypeMapping for type mapping
Since all anonymous types are approximated to a supertype in kapt, type
mapping doesn't require backend information (mapping of anonymous types
to class names) and can be performed statically, independently from
particular JVM backend internals, via descriptorBasedTypeMapping.

 #KT-49682
2022-02-08 20:15:13 +01:00
Alexander Udalov ebb9659e03 Add mode to run kapt with JVM IR, use in tests
Currently JVM IR is not supported in kapt, so almost all tests are
failing, and thus are muted with IGNORE_BACKEND.

 #KT-49682
2022-02-08 20:15:13 +01:00
Nikolay Krasko e733aa21d5 Fix error instead of muting it in kapt tests 2021-12-15 19:18:55 +03:00
Steven Schäfer 4f3debdec6 [KAPT] Correct error types in annotations (KT-32596) 2021-12-14 11:31:25 +03:00
Ivan Kylchik c7435ba760 Replace all occurrences of WITH_RUNTIME with WITH_STDLIB
We are going to deprecate `WITH_RUNTIME` directive. The main reason
behind this change is that `WITH_STDLIB` directive better describes
its meaning, specifically it will add kotlin stdlib to test's classpath.
2021-11-17 15:26:38 +03:00
Yigit Boyar 95f990adab Support line location information in KAPT for top level declarations
This CL fixes a bug in KAPT's MAP_DIAGNOSTIC_LOCATIONS flag where the
location mapping for top level elements didn't work.

I also needed to changes the Kapt3IntegrationTest to copy input files,
otherwise, it cannot map file paths since the mock project has no root
location.

Cleanup tmp folders in KAPT tests, update Kapt3IT test for new lines.

^KT-47934 Fixed
Test: KotlinKapt3IntegrationTests#testErrorLocationMapping
2021-09-14 10:48:37 +02:00
Andrey Zinovyev 78e20c1098 [KAPT] Keep original expressions in annotations vararg
#KT-29929 Fixed
2021-05-31 08:08:37 +00:00
Andrey Zinovyev 0c6066db74 [KAPT] Don't fail on illegal delegate
Kapt ignores error diagnostics, but backend can't
 compile such code at all
This is workaround so backend won't fail.
#KT-46176 Fixed
2021-04-27 16:18:44 +03:00
Andrey Zinovyev 8071a1e246 [KAPT] Keep constant references in annotations with array values
#KT-29929 Fixed
2021-04-20 15:47:03 +03:00
Andrey Zinovyev 8c464b4de5 [KAPT] Bring back properties resolution in light analysis
Because kapt fails on evaluation constant expressions of SomeType::class
2021-04-14 07:50:22 +00:00
Andrey Zinovyev b128577508 [KAPT] Some optimizations for stubs generation
* Add index to resolve compiled class by name
* Disable full property resolution
2021-03-03 12:05:49 +03:00