Commit Graph

61 Commits

Author SHA1 Message Date
Evgeniy.Zhelenskiy 782e35dc8d [K2, JVM, IR] Add tests for clashing inner classes names
#KT-65586 #KT-65439
2024-02-19 15:20:57 +00:00
Anastasia.Nekrasova c04767f1f4 [K2] Disappeared UNSUPPORTED_FEATURE (2)
Added a check for the enabled context receivers feature flag for declaration.

^KT-59913
2023-11-22 06:04:13 +00:00
Nikolay Lunyak 80cccce8d0 [FIR] Use the proper processAll* functions for CONFLICTING_OVERLOADS
The `*leaf*` functions were
introduced due to my false
assumption. The normal processing
functions only collect leafs
already. `*leaf*`s are bad, because
they don't cache anything.

The change in
AbstractFirOverrideScope reflects
KT-63290, and is needed to avoid
duplicate `CONFLICTING_OVERLOADS`
and `VIRTUAL_MEMBER_HIDDEN`.
2023-11-15 07:56:32 +00:00
Mikhail Glukhikh 3cb9396b20 K2: prefer derived class sources for callable copies (e.g. fake overrides) 2023-10-24 17:08:40 +00:00
Xin Wang 51325ba630 [IR] Implement getContextReceiverParameters for IrBasedPropertyDescriptor
Fixes: KT-59590
2023-10-24 10:07:08 +00:00
Mikhail Glukhikh 0fb4c9b4fe FIR2IR: generate specific sources for property accessors
Related to KT-60111
2023-10-13 15:42:58 +00:00
Kirill Rakhman cee355196a [Tests] Fix accidental overload resolution ambiguity in test 2023-08-11 10:54:25 +00:00
Alexander Udalov bad7fa597b Tests: move some tests to diagnostics 2023-08-09 23:58:51 +00:00
Alexander Udalov 3ff21db77f Tests: remove unused .diag.txt file 2023-07-29 23:06:23 +00:00
Alexander Udalov 0a748f8ea0 Tests: remove .txt dumps from diagnostic tests with JVM backend
They are mostly useless now.
2023-07-29 23:06:23 +00:00
Alexander Udalov 965946d3ef K2: report JVM backend errors in the same way in PSI as LT
Do not try to find PSI element, but always use the IR element offsets
instead. This greatly simplifies test data because we don't need to have
custom PSI- and LT- based diagnostic ranges in every test, and K1/K2
behavior also is mostly the same.

The exact offset ranges are not as important for backend diagnostics, so
it's better to have K2+PSI and K2+LT behaving the same.
2023-07-29 23:06:23 +00:00
Alexander Udalov 6069aaee9c K2: report JvmMultifileClass+JvmSynthetic error in JVM backend
Specifically, the case when not all parts of a multifile class are
annotated with `@JvmSynthetic`. Report the error on the
`@JvmMultifileClass` annotation instead of the package directive,
because the latter is difficult to find via IR. This fixes the test
FirLightTreeDiagnosticsTestWithJvmIrBackendGenerated.MultifileClasses.testJvmSynthetic.

 #KT-59586
2023-07-29 01:14:29 +02:00
Alexander Udalov 5f2ff06296 Add tests for JVM backend diagnostics with K2 light tree
In the vast majority of tests, diagnostics are reported at a slightly
different location in LT vs PSI. This is because in the light tree mode,
backend errors are reported basically on the start of the IR element,
which is for example the keyword "class" for a class and not its name as
in K1 or in K2+PSI. Similarly, the end of the diagnostic is at the
ending offset of the IR element.

Normally it would be a bit user-unfriendly to highlight the whole class
as red, starting from the keyword "class" and ending with the closing
brace "}". But remember that these are backend diagnostics in the K2+LT
mode, which is only possible in the compiler scenario, not in the IDE.
And in this case, the ending offset doesn't matter at all because it's
not presented to the user, and minor change in the starting offset is
not a problem as well.

There are some tests which legitimately fail in the LT mode because the
corresponding diagnostics haven't been supported. They will be dealt
with in subsequent commits:

  testPropertyInlineCycle
  testInlineCycle
  MultifileClasses.testJvmSynthetic
  testSuspendInlineCycle
  testIndirectInlineCycle

 #KT-59586
2023-07-29 01:14:29 +02:00
Ivan Kylchik d0da736b13 [FIR] Add the new test set to render diagnostics from IR const evaluator 2023-07-27 22:50:21 +00:00
Alexander Udalov 8fc6c03e16 Tests: merge firTestWithJvmBackend into testsWithJvmBackend 2023-07-17 16:55:24 +00:00
Alexander Udalov 9935519656 Tests: add RENDER_ALL_DIAGNOSTICS_FULL_TEXT directive
Use it in diagnostic tests with JVM backend instead of the
RENDER_DIAGNOSTICS_FULL_TEXT directive.

This is needed because otherwise in
AbstractDiagnosticsTestWithJvmBackend there are two handlers trying to
dump full diagnostic texts: JvmBackendDiagnosticsHandler and
FirDiagnosticsHandler, which dump different diagnostics (reported by
backend vs frontend) and in slightly different formats.

In fact, this is why exceptionFromInterpreter.fir.diag.txt was added in
48484368c7: the existing .diag.txt was detected as incorrect by
FirDiagnosticsHandler (even though the diagnostics are the same, just
printed in a different way), which led to the creation of .fir.diag.txt.
For these tests, the behavior about checking diagnostic text in
FirDiagnosticsHandler is useless because it doesn't include backend
diagnostics. So we disable it by using another directive.
2023-07-17 16:55:24 +00:00
Alexander Udalov dd3bebb690 Remove obsolete directives in diagnostic backend tests 2023-07-17 16:55:24 +00:00
Alexander Udalov 6f2bb8c05a Rename tests with diagnostics on JVM backend
Remove the "_ir" suffix. It was originally used to distinguish tests on
the JVM IR backend from the old JVM backend ("_old"), but the latter are
removed now.
2023-07-17 16:55:24 +00:00
Alexander Udalov 815ab15313 Remove JVM_OLD-specific test data from backend diagnostic tests
Old JVM backend is only used as a fallback in Evaluate Expression in the
IDE at this point, so it's supposed to compile only correct code anyway.
2023-07-17 16:55:24 +00:00
Alexander Udalov b03e50129e Tests: fix handling of diag.txt files in diagnostic tests with backend
Also take into account diagnostics reported via
GenerationState.collectedExtraJvmDiagnostics, and render them in the
similar format to KtDiagnostic.

Don't make the test pass if the reported list of diagnostics is empty,
because that defeats the purpose of the test.
2023-07-17 16:55:24 +00:00
Denis.Zharkov 2e5b783cc6 K2: Refine how JDK members are mapped to built-in classes
Previously, the semantic was more-or-less correct for most of the cases
but some corner one, like `sort` in MutableList didn't work properly.

Namely, `sort` should be marked there in a way to forbid to call it
everywhere beside super-calls.
Also, overriding it should be allowed.

Mostly, the logic was re-written to K2 model from K1-related
JvmBuiltInsCustomizer.

^KT-57694 In progress
^KT-57269 Fixed
2023-05-30 10:44:41 +00:00
Alexander Udalov 987e8c25dc K2: do not generate line numbers for delegated members
Psi2ir does not generate them, see
https://github.com/JetBrains/kotlin/blob/1.8.20/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ClassGenerator.kt#L319.

Besides influencing debugger and coverage behavior, it also affects how
conflicting JVM signature diagnostics are reported because they
use offsets to determine which element to report the error on. So after
this change, K1 and K2 behavior is the same in that regard as well.

 #KT-58215 Fixed
2023-05-10 10:32:07 +00:00
Evgeniy.Zhelenskiy 8c748bfea4 [IR] Add more tests for inline/value classes secondary constructors
Signed-off-by: Evgeniy.Zhelenskiy <Evgeniy.Zhelenskiy@jetbrains.com>

#KT-55333
2023-04-17 12:10:14 +00:00
Nikolay Lunyak 7b04201e77 [FIR] KT-57104: Preserve @JvmName on fake-override accessors
Otherwise, when we come to `ClassCodegen.kt:173
for `GradleActionTest` and check
`FUN FAKE_OVERRIDE name:<get-project>`,
we then go to `JvmSignatureClashDetector.kt:37`,
and call `mapRawSignature(overriddenFunction)`
which ignores the original `@JvmName`.
It does so because it relies on the property copy
which forgets to copy the getter, but
`@get:JvmName` is stored in it.

Extra when-branches for `FAKE_OVERRIDE` are needed,
because otherwise the annotations would not
be copied in `Fir2IrDeclarationStorage.kt:723`.

Extra when-branches for `DELEGATED_MEMBER` are
needed, because otherwise the generated IR changes
in some tests. For example, see:
`FirLightTreeIrTextTestGenerated.Declarations.testKt35550`.

The `assumesBackingField`-related change is backed by
the `FirLightTreeIrTextTestGenerated.Stubs.testJavaEnum` test.

`this.body = null` ensures the resulting IR
matches K1.

The change in `FirImplicitBodyResolve.kt` is needed,
because otherwise the bootstrap compiler fails at
`:compiler:frontend:compileKotlin`,
but I didn't come up with a smaller test for it.

If we don't make an explicit accessor copy,
then when we later create a `Fir2IrLazyPropertyAccessor`
for the fake override getter, it's `fir` will
be a reference to the `FirProperty`, not `FirPropertyAccessor`.
That's why `DumpIrTreeVisitor` will render `IntrinsicConstEvaluation` as
a getter annotation as well.

`FirPsiIrTextTestGenerated.testDelegatedGenericImplementation`
renders type parameters from `<get-x>`,
because when assigning `extensionReceiverParameter`
of the setter `<set-x>` we come to
`Fir2IrClassifierStorage.kt:638`,
and in this cache there's the parameter with
the `<get-x>` parent.
Note that `typeContext.origin == DEFAULT` in
`getCachedIrTypeParameter`.
It's `DEFAULT` because at the line `Fir2IrDeclarationStorage.kt:335`
the `function` variable is `null` (because there's no setter).

The change in `declarationAttributes.kt` is backed
by the `FirPsiIrTextTestGenerated.testKt45853` test.

^KT-57104 Fixed
^KT-57432 Fixed

Merge-request: KT-MR-9210
Merged-by: Nikolay Lunyak <Nikolay.Lunyak@jetbrains.com>
2023-03-22 18:16:31 +00: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 f96d41e414 KT-4107 Don't generate readResolve for data objects 2022-11-30 21:07:20 +00:00
Ivan Kochurkin 8883de3f00 [FIR] Don't resolve Enum.declaringClass and Enum.getDeclaringClass
^KT-53946 Fixed
2022-11-23 18:29:29 +00:00
Mikhail Glukhikh 69c883ecee FIR: use FIR_IDENTICAL instead of FIR_IGNORE for diags with BE tests 2022-10-17 12:46:25 +00:00
Mikhail Glukhikh 1826d9b332 K2: add & fix tests for JVM BE diagnostics 2022-10-17 12:46:24 +00:00
Pavel Mikhailovskii c3c09aa95a KT-4107 Data objects 2022-06-28 16:58:20 +02:00
Ivan Kylchik 001ecaa9b2 Support RENDER_DIAGNOSTICS_FULL_TEXT directive in new test infra 2022-05-18 21:20:03 +03:00
Ivan Kylchik 0f0b48f87b Move reporting of interpreter's backend errors tests to fir module 2022-05-18 21:20:01 +03:00
Ivan Kylchik 1431d4b356 Add jvm diagnostic tests to check report of exceptions from interpreter 2022-05-18 21:20:00 +03:00
Ivan Kylchik 51ccc32a3f Update test data after introducing IntrinsicConstEvaluation annotation 2022-05-18 21:19:57 +03:00
Ilya Chernikov c1c94778ce Detect and report inner classes capturing script instance 2021-12-14 13:39:22 +03:00
Ilya Chernikov 10c5071eda Implement backend error reporting on unsupported script capturing
#KT-30616 fixed
#KT-43995 fixed
#KT-19424 fixed
#KT-49443 fixed
2021-12-14 13:39:17 +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
Alexander Udalov 850d76f6bf Remove error on annotated types as arguments to typeOf
Instead, document that `KType.annotations` returns an empty list for
types created with `typeOf`. Annotations might be supported in the
future.

 #KT-49573 Fixed
 #KT-29919
2021-11-16 15:02:50 +01:00
Alexander Udalov 9ebd665c96 Report error on annotated type inside typeOf on JVM
Since it's not feasible to support annotated types in 1.6, we're making
this an explicit error in 1.6, so that typeOf can become stable and this
feature can be supported in the future without breaking changes to the
existing code.

Note that extension function types are a special case of annotated
types. A separate error is created for them just because the message
"annotated types are not supported" would be confusing, since such types
don't have explicit annotations in the source code.

 #KT-29919
2021-07-22 15:54:48 +02:00
Alexander Udalov 02774fae0c Report error on non-reified type parameter with recursive bound in typeOf
Instead of throwing an exception.

 #KT-40173
2021-07-09 14:31:52 +02:00
Alexander Udalov 438ce57183 Report error on typeOf<suspend ...>()
Otherwise an invalid type is constructed which causes kotlin-reflect to
crash, and stdlib implementation to render the type incorrectly. The
reason is that suspend functional types are not properly supported in
reflection. Once they are supported, this error can be removed.

 #KT-47562
2021-07-09 14:31:52 +02:00
pyos e06bacafad JVM: fix inline cycle detection
1. use the correct descriptor in the old backend;
 2. clear the temporary variables for arguments in the IR backend.

 #KT-45292 Fixed
2021-03-12 11:49:42 +01:00
Alexander Udalov bc5fc122c5 JVM, JVM IR: report error if not all parts of multifile class are @JvmSynthetic
#KT-41884 Fixed
2021-03-11 13:33:25 +01:00
Ilmir Usmanov 62123d72e2 IC: Add inline class -> @JvmInline value class warning 2021-02-25 16:06:47 +01:00
Dmitriy Novozhilov f1a2e66ba4 [Test] Setup proper jvm target for kotlinClassImplementsJavaInterface test 2021-01-12 18:35:33 +03:00
Dmitriy Novozhilov 85c87f7df9 [Test] Migrate AbstractBlackBoxCodegenTest to new infrastructure 2021-01-12 18:35:30 +03:00
Ilmir Usmanov f922ebbfc3 Value classes: Add JvmInlineValueClasses language feature 2020-12-18 17:53:58 +01:00
Ilmir Usmanov 69be56d042 Value classes: Forbid cloneable value classes
#KT-43741 Fixed
2020-12-04 23:27:46 +01:00
Dmitry Petrov 3b604cfa7f JVM_IR KT-32701 generate multiple big arity invokes, report error later 2020-11-30 15:49:02 +03:00