Commit Graph

294 Commits

Author SHA1 Message Date
Roman Efremov a05b37c652 [K2] Support reporting of SUPERTYPE_INITIALIZED_IN_EXPECTED_CLASS
...on regular classes and enum entries.

^KT-59979 Fixed
2023-10-12 13:01:40 +00:00
Roman Efremov 32a87836c2 [Test] Improve test of SUPERTYPE_INITIALIZED_IN_EXPECTED_CLASS diagnostic
Add case where explicit primary constructor is present in expect,
so that SUPERTYPE_INITIALIZED_WITHOUT_PRIMARY_CONSTRUCTOR is not
reported.

^KT-59979
2023-10-12 13:01:40 +00:00
Anastasia.Nekrasova e3bab4a7da [K2] Prohibit smart casts for 'expect' properties
^KT-61340
2023-10-11 17:05:29 +00:00
Roman Efremov e4ea733482 [K2] Support reporting of EXPECTED_ENUM_ENTRY_WITH_BODY
Test for the case when enum entry has constructor call but doesn't have
body already exist in
`compiler/testData/diagnostics/tests/multiplatform/enum/constructorInHeaderEnum.kt`.

^KT-59978 Fixed
2023-10-11 15:04:02 +00:00
Ivan Kochurkin 89fe73f6f4 [FIR] Consider expect default function parameters in FirSuperCallWithDefaultsChecker
^KT-61572 Fixed
2023-10-06 12:29:01 +00:00
Nikita Bobko e8630fd63f ActualClassifierMustHasTheSameMembersAsNonFinalExpectClassifierChecker: error -> warning
^KT-62263 Fixed
Review: https://jetbrains.team/p/kt/reviews/12401/timeline
2023-10-05 10:36:38 +00:00
Roman Efremov faae5f9b38 [IR] Fix annotation arguments comparison when expression is expect enum
...actualized via typealias. This caused false-positive report of
`ACTUAL_ANNOTATION_CONFLICTING_DEFAULT_ARGUMENT_VALUE`.
In such case it's incorrect to compare signatures, because classes have
different `ClassId`s. Instead, classes could be compared using
`areCompatibleExpectActualTypes` which actualizes both types, and
then enum value names compared.

^KT-62104
^KT-59940
2023-10-04 11:38:15 +00:00
Roman Efremov 705b2e87fd Revert "[K2] Temporary mute ACTUAL_ANNOTATION_CONFLICTING_DEFAULT_ARGUMENT_VALUE"
This reverts commit b232dbf484.
2023-10-04 11:38:15 +00:00
Roman Efremov 81fd9a679d [FIR] Prohibit expect class members with default values actualized
...by fake-override.
It is error without deprecation cycle because `expect` and `actual`
classes are still in Beta and expected impact of change is negligible.

^KT-62036 Fixed
2023-10-02 15:50:37 +00:00
Roman Efremov 02680442a0 [Test] Add tests for expect class default arguments which actualized
...by fake-override.

^KT-62036
2023-10-02 15:50:37 +00:00
Roman Efremov 7ad23aeb73 [Test] Drop forgotten TODO
^KT-62036
2023-10-02 15:50:37 +00:00
Roman Efremov b232dbf484 [K2] Temporary mute ACTUAL_ANNOTATION_CONFLICTING_DEFAULT_ARGUMENT_VALUE
...until tests fixed. Mute on TC is not enough
because user projects compilation are affected.

^KT-62104
2023-09-21 09:05:51 +00:00
Roman Efremov ad4d1a5ba8 [IR] Support ACTUAL_ANNOTATION_CONFLICTING_DEFAULT_ARGUMENT_VALUE in K2
It's implemented as IR checker because in K2 constant expressions are
evaluated on backend. FIR diagnostic removed because isn't needed.

"annotationViaActualTypeAlias" test has no `// FIR_IDENTICAL` because
diagnostic reported on entire typealias declaration instead of its name.
This is because in IR+LightTree we have only offsets, so can't navigate
to typealias name element.

^KT-59940 Fixed
2023-09-20 15:40:37 +00:00
Nikita Bobko b15787bfa8 Fir incorrect usage of AbstractExpectActualCompatibilityChecker.getCallablesCompatibility API
^KT-62027 Fixed

`getCallablesCompatibility` requires parentSubstitutor as a parameter,
but we created a member-level substitutor

`getCallablesCompatibility` will create member-level substitutor itself,
no need to create member-level substitutor on the call site.

IndexOutOfBounds was happening in an attempt of creating member-level
substitutor

I will refactor the `createExpectActualTypeParameterSubstitutor` API in
the following commits later. It will help to avoid problems like that
2023-09-19 14:24:15 +00:00
Roman Efremov c88b4105c5 [K2] Correctly handle case when expect annotation is unresolved
Don't report if annotation has error type.

Review: KT-MR-12250

^KT-62026 Fixed
2023-09-19 10:19:08 +00:00
Roman Efremov 04c1bf749c [K1] Correctly handle case when expect annotation is unresolved
Before change NPE was thrown.

Review: KT-MR-12250

^KT-62026
2023-09-19 10:19:08 +00:00
Roman Efremov a23f2894b2 [K2] Support reporting of EXPECTED_CLASS_CONSTRUCTOR_PROPERTY_PARAMETER
^KT-59982 Fixed
2023-09-18 12:22:42 +00:00
Roman Efremov 5623427c6d [Test] Extract test for EXPECTED_CLASS_CONSTRUCTOR_PROPERTY_PARAMETER
...to separate file. Also, add 3 cases with true-negative reporting:
annotation class, value class and secondary constructor.

^KT-59982
2023-09-18 12:22:42 +00:00
Roman Efremov 489371219f [K2] Support reporting of EXPECTED_ENUM_CONSTRUCTOR
^KT-59980 Fixed
2023-09-18 12:22:42 +00:00
Roman Efremov 6112c4ab2c [K2] Rewrite condition for EXPECTED_PRIVATE_DECLARATION
...without `isTopLevelOrInsideClass` property. Behavior stays the same,
because in fact we require all `expect` member declarations to be non-private
except constructors and property setter.
Enhance already existing test.

^KT-59899
2023-09-18 12:22:41 +00:00
Roman Efremov 1fdc607898 [K2] Fix EXPECTED_DECLARATION_WITH_BODY not reporting on property accessors
We don't want any `expect` function to have body. So we're sure no
new false-positive reports are introduced because of removal of
`isTopLevelOrInsideClass` condition.

^KT-59899 Fixed
2023-09-18 12:22:41 +00:00
Roman Efremov e79851910e [FE, IR] Check annotations compatibility on expect and actual getters and setters
^KT-60671
2023-09-15 14:41:38 +00:00
Roman Efremov 8fb2935ef6 [FE, IR] Check annotations compatibility on expect and actual type parameters
^KT-60671
2023-09-15 14:41:37 +00:00
Roman Efremov 5c95f69aef [FE, IR] Check annotations compatibility on expect and actual value parameters
Comment was added to make it clear why whole declarations reported
in diagnostic instead of value parameter symbols (same will be done
with other targets in subsequent commits).

^KT-60671
2023-09-15 14:41:37 +00:00
Vladimir Sukharev bab00255dc [K/N, Tests] Add diagnostic tests for SUPER_CALL_WITH_DEFAULT_PARAMETERS
^KT-61572


Merge-request: KT-MR-11941
Merged-by: Vladimir Sukharev <Vladimir.Sukharev@jetbrains.com>
2023-09-13 11:10:25 +00:00
Anastasia.Nekrasova eab6e9bb36 Added tests for all code samples from KT-60523, except 2.3.
Test for 2.3 sample must be added in the context of KT-61792.
2023-09-12 07:03:20 +00:00
Roman Efremov 2dae7ce6c1 [LT2FIR] Fix missing "expect" modifier on members of nested classes
For members of nested classes inside expect class
`classWrapper.hasExpect()` would be false, because it only reflects
modifiers of nested class itself and not aware of "expect" modifier
inherited from the parent class.
Fix is done in same way in PSI2FIR, see
`PsiRawFirBuilder.Visitor.toFirProperty`.

This fix now makes it possible to add test for functionality from
previous commit.

Review: KT-MR-12107

^KT-61784
2023-09-11 21:29:02 +00:00
Roman Efremov c6d7f15070 [FE] Fix checker of DEFAULT_ARGUMENTS_IN_EXPECT_WITH_ACTUAL_TYPEALIAS
...not reporting on companion object members as well as other
nested classes.

Annotation classes are accepted because this is how it already worked,
see other tests, for example `annotationsViaActualTypeAlias.kt`.

Test for nested annotation classes will be added in subsequent commit,
because it currently will fail in test
`TreeCompareTest.testCompareDiagnostics` because light-tree2fir
produces different tree due to a bug when converting properties
from expect primary constructor. See subsequent commit for a fix.

Review: KT-MR-12107

^KT-61784
2023-09-11 21:29:02 +00:00
Nikita Bobko 2127b2ce68 expect/actual classes: experimental -> Beta
KT-61573
^KT-61712 Fixed
Review: https://jetbrains.team/p/kt/reviews/12044/files

It's a follow up commit

According our guidelines, it must be in Beta
https://kotlinlang.org/docs/components-stability.html#stability-of-subcomponents

And the whole multiplatform was in Beta, so we can't make part of the
multiplatform to have lower stability level
2023-09-11 13:57:28 +00:00
Nikita Bobko 3c73331821 KMP: Put "prohibit actual typealias to special annotations" under the flag
^KT-61668 Fixed

Review: https://jetbrains.team/p/kt/reviews/12062/timeline
2023-09-08 10:51:43 +00:00
Nikita Bobko e742d43ee0 KMP: Put "prohibit expect/actual tailrec/external" under the flag
^KT-61668 Fixed

Review: https://jetbrains.team/p/kt/reviews/12062/timeline
2023-09-08 10:51:43 +00:00
Nikita Bobko 172c04c96a KMP: Put "prohibit expect actual OptIn annotations" under the flag
^KT-61668 Fixed

Review: https://jetbrains.team/p/kt/reviews/12062/timeline
2023-09-08 10:51:43 +00:00
Nikita Bobko 0922833b46 KMP: Put "prohbit actual typealias to Nothing and Nullable" under the flag
^KT-61668 Fixed

Review: https://jetbrains.team/p/kt/reviews/12062/timeline
2023-09-08 10:51:42 +00:00
Nikita Bobko 141bc9cac9 KMP: Put "prohbit actual typealias if expect has default params" under the flag
^KT-61668 Fixed

Review: https://jetbrains.team/p/kt/reviews/12062/timeline
2023-09-08 10:51:42 +00:00
Nikita Bobko 6868c95263 KMP: Put "prohbit expect/actual different annotations" under the flag
^KT-61668 Fixed

Review: https://jetbrains.team/p/kt/reviews/12062/timeline
2023-09-08 10:51:42 +00:00
Nikita Bobko 3a0c4d1087 KMP: Put "prohbit implicit Java actualization" under the flag
^KT-61668 Fixed

Review: https://jetbrains.team/p/kt/reviews/12062/timeline
2023-09-08 10:51:42 +00:00
Nikita Bobko 7667b36aa0 KMP: Put "prohibit member scope mismatch for non-final expect" under the flag
^KT-61668 Fixed

Review: https://jetbrains.team/p/kt/reviews/12062/timeline
2023-09-08 10:51:42 +00:00
Ilya Kirillov 030250d387 [FIR] fix resolution ambiguities between weakly compatible expect and actual
There is a corresponding example inside the stdlib,
see `kotlin.text.startsWith`.

JVM and common counterpart are weakly-compatible
as the actual declaration has default arguments,
which results in `ExpectActualCompatibility.Incompatible.ActualFunctionWithDefaultParameters`

This commit allows such cases.

^KT-61732 fixed
2023-09-06 16:30:28 +00:00
Roman Efremov 5e49b472f8 [FE, IR] Allow @ImplicitlyActualizedByJvmDeclaration to be set only on expect
@ImplicitlyActualizedByJvmDeclaration is the only one
OptionalExpectation annotation which works correctly when set only on
`expect`. All other (like @JvmName, @JsName) - not, so warning for them
must be reported.

^KT-61725 Fixed
2023-09-06 14:27:07 +00:00
Nikita Bobko 01fc708a0f Mark expect/actual classifiers as experimental
^KT-61573 Fixed
Review: https://jetbrains.team/p/kt/reviews/11969/timeline

Tests:
- MultiPlatformIntegrationTestGenerated
- CliTestGenerated
- MultiPlatformIntegrationTestGenerated
- DiagnosticTestGenerated.Multiplatform
- FirLightTreeOldFrontendDiagnosticsTestGenerated

Also add -Xexpect-actual-classes flag to all necessary ./libraries/* modules
Otherwise compilation of those modules failes because of `-Werror`
2023-09-04 12:21:37 +00:00
Dmitriy Novozhilov de68ec7cd5 [FIR] Properly report SEALED_INHERITOR_IN_DIFFERENT_MODULE
^KT-46031 Fixed
^KT-59804 Fixed
2023-08-31 12:32:25 +00:00
Kirill Rakhman ac102dedac [IR Actualizer] Fix fake-override generation in actual A -> common B -> actual C hierarchy
...  where C defines a member x and A overrides the member x

#KT-61166 Fixed
2023-08-31 07:52:02 +00:00
Dmitriy Novozhilov 332eca2d55 [Test] Update testdata of fixed test
I don't really know which exact commit fixed this test, but there was
  a problem with return types of delegated members. Before my changes
  delegated `override fun foo(x: Int)` in `actual class E` had error
  return type and now it has correct type `Int`
2023-08-30 14:51:45 +00:00
Nikita Bobko 373abbde5d Partially revert "[FE] Stop ignoring ABSTRACT_MEMBER_NOT_IMPLEMENTED for expect classes"
^KT-61039 Fixed
KT-59739 is now open for K1 (but fixed in K2)
Review: https://jetbrains.team/p/kt/reviews/11867/timeline

This partially reverts commit 4f3ecedbca.
Only K1 part is reverted.

Motivation for revert: KT-59739 cannot be properly fixed in K1 because
of the bug it causes - KT-61039

We just accepted that we will have one more "green in K1 -> red in K2"
case
2023-08-30 14:35:59 +00:00
Nikita Bobko 3722f4d7d6 ActualClassifierMustHasTheSameMembersAsNonFinalExpectClassifierChecker: reuse "expect-actual" matcher
In scope of: KT-22841
Review: https://jetbrains.team/p/kt/reviews/11867/timeline

Reduce complexity by reusing "expect-actual matcher" (namely
`AbstractExpectActualCompatibilityChecker.getCallablesCompatibility`)

The current solution has worse algorithmic complexity. Previously it was
O(n) in the best case, where `n` is a number of members. Now, it's
O(m^2), where `m` is number of members in one overload group. But we
prefer to have worse complexity but reuse expect-actual matcher, number
of elements in one overload group shall not be big on real world
examples.

The previous logic was non-trivial because it compared types with with
double comparison in `equals`.
2023-08-30 14:35:56 +00:00
Nikita Bobko 17089276a7 Add regression tests for modality changes
Motivation: the discovered false negative in test
changeModalityFromAbstractToOpenInOverride.kt

Unfortunately, it can't be fixed in K1, so we will just live with that.
Luckily, we report ABSTRACT_MEMBER_NOT_IMPLEMENTED additionally.

In K2, MODALITY_CHANGED_IN_NON_FINAL_EXPECT_CLASSIFIER_ACTUALIZATION
will be correctly reported as a compilation error

In scope of: KT-22841
Review: https://jetbrains.team/p/kt/reviews/11867/timeline
2023-08-30 14:35:55 +00:00
Ivan Kochurkin d9b5d37baf [K2, MPP] Forbid matching actual callable with dynamic return type
to expect callable with non-dynamic return type

^KT-59251 Fixed
2023-08-28 09:29:05 +00:00
Roman Efremov 6b217369a8 [FE1.0] Fix false reporting of non-matching annotations in IDE...
...when typealiased expect class used in class literal.

^KTIJ-26700 Fixed
2023-08-23 13:15:20 +00:00
Roman Efremov 77ab13400e [FE1.0] Fix false reporting of non-matching actual annotations in IDE
It was reported because in composite module analysis we have both expect
and actual annotation descriptors, which may differ.
This may lead to bugs in the checker of ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT
diagnostic.

`fqName` comparison can be safely removed, because we already check
types in `areCompatibleExpectActualTypes`.

Tests:
- typealiasedAnnotation.kt - for annotation use (so it has different
ClassId)
- typealiasedAnnotationAsArgument.kt - when typealiased annotation
used in another annotation as argument
- sourceRetentionAnnotationsWhenTypealias.kt - tests same as
compiler/testData/diagnostics/tests/multiplatform/annotationMatching/sourceRetentionAnnotationsWhenTypealias.kt

No special test added for opt-in, because it's prohibited to have
expect/actual opt-ins by EXPECT_ACTUAL_OPT_IN_ANNOTATION checker.

^KTIJ-26700
2023-08-23 13:15:20 +00:00
Roman Efremov def4388c19 [FE, IR] Check annotations on expect and actual enum entries
^KT-60668
^KT-60936
2023-08-22 12:14:43 +00:00