Commit Graph

270 Commits

Author SHA1 Message Date
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
Roman Efremov b57940a59b [FE1.0] Optimize search of expect class member in annotation checker
In the following scenario, when we search corresponding expect member
for actual `A.B`, we can skip checking compatibility of `B` scope.
```
class A {
  class B {
    fun foo() {}
  }
}
actual typealias AImpl = A
```

This is because:

1. Annotation checker runs no matter if found expect class is compatible
or not.
2. Class always has at most one corresponding `expect` class (unlike for
functions, which may have several overrides), so we are sure that we
found the right member.

^KT-60668
^KT-60936
2023-08-22 12:14:43 +00:00
Roman Efremov f1ea6545eb [IR] Fix incorrect position of reporting with fake overrides inside actual
^KT-60668
^KT-60936
2023-08-22 12:14:42 +00:00
Roman Efremov 58a30d524c [IR] Fix positioning of actual annotations diagnostic when reported on value
`parentsWithSelf` returns empty sequence if receiver is not a
`IrDeclarationParent`.

^KT-60668
^KT-60936
2023-08-22 12:14:42 +00:00
Roman Efremov ab1c0e3c48 [FE] Check annotations on actual class members including fake overrides
^KT-60668
^KT-60936
2023-08-22 12:14:42 +00:00
Roman Efremov 673b4b4d52 [FE] Add OptIn annotation to whitelist of annotation checker
It's valid to have `@OptIn` only on `expect` declaration.

^KT-61373
2023-08-22 09:02:20 +00:00
Nikita Bobko 25c082f02b K1: Implement a checker that disallows to have different member scopes for expect open and its actual
^KT-22841 Fixed
Review: https://jetbrains.team/p/kt/reviews/11603/timeline

The commit also introduces `@AllowDifferentMembersInActual` annotation in
stdlib which allows to suppress the diagnostic
2023-08-21 19:51:08 +00:00
Kirill Rakhman d0cc86f52c [Tests] Update test data after changes to FIR diagnostic messages 2023-08-21 16:28:48 +00:00
Kirill Rakhman 5b9c35de2e [Tests] Update test data with error suppression warnings
#KT-61129 Fixed
2023-08-18 13:29:20 +00:00
Nikita Bobko 577d0db3f1 [FE] Skip delegation descriptors during default params matching
^KT-61163 Fixed
Review: https://jetbrains.team/p/kt/reviews/11599/timeline

They can be safely skiped because we check overridden descriptors
anyway.

IMO, it's a bug that delegated descriptors are copied with default
params. But it's much harder problem, and my IMO can easily be wrong for
some weird reason.
2023-08-15 16:34:23 +00:00
Ivan Kochurkin d4d30dcfcf [FIR] Introduce OPTIONAL_EXPECTATION_NOT_ON_EXPECTED diagnostic
^KT-60892 Fixed
2023-08-10 17:46:08 +00:00
Ivan Kochurkin 8e8de513ee [FIR] Introduce OPTIONAL_DECLARATION_USAGE_IN_NON_COMMON_SOURCE diagnostic
^KT-60892
2023-08-10 17:46:08 +00:00
Ivan Kochurkin b08df32cac [FIR] Introduce OPTIONAL_DECLARATION_OUTSIDE_OF_ANNOTATION_ENTRY diagnostic
^KT-60892
2023-08-10 17:46:08 +00:00
Ivan Kochurkin dc1f1fe979 Move optionalExpectationIncorrectUse from MPP integration to diagnostics tests 2023-08-10 17:46:08 +00:00
Nikita Bobko d4758014ec [FE] Type-safety refactoring: Make areCompatibleClassScopes to return Incompatible.WeakIncompatible
Review: https://jetbrains.team/p/kt/reviews/11039/timeline

For StrongIncompatible `actual` declaration is considered as overload
and error reports on expected declaration. For WeakIncompatible the
error is reported straight away

Before the refactoring `areCompatibleClassScopes` returned just
`Incompatible`. It is bad because StrongIncompatible isn't possible for
classes (classes can't be overloaded). Now all class incompatibilities
are weak.

The commit has a minor impact on observable behavior (cases where we
reported the compilation problems are still reported but on another
elements):
- We no longer report type parameter class incompatibilities on expect
  declaration, we report them only on actuals (it happened because all
  WeakIncompatible are reported only on actuals)
- In a sense, Java implicit actualization was the only way to "overload"
  classes (it would be a redeclaration compilation problem, so it
  doesn't count as a valid "overload"). And since type parameters
  incompatibility was StrongIncompatible for classes, we counted them as
  "overloads" and didn't report incompatibility problems on Kotlin
  class. Now we do report. (see
  implicitJavaActualization_multipleActuals)
2023-08-10 15:46:48 +00:00
Nikita Bobko eac4b81b11 [FE] Fix TypeParameterUpperBounds incompatibility priority
^KT-60902 Fixed
Review: https://jetbrains.team/p/kt/reviews/11039/timeline

We should prioritize to return STRONG incompatibilities over WEAK
incompatibilities. But this invariant broke in `areCompatibleCallables`,
because `areCompatibleTypeParameters` returns incompatibilities of both
types, and `areCompatibleTypeParameters` is called in WEAK
incompatibilities section.

The fix is to split `areCompatibleTypeParameters` into two functions:
`areStrongIncompatibleTypeParameters` and
`areWeakIncompatibleTypeParameters`. And call each of this function in
appropriate `areCompatibleCallables` sections.
2023-08-10 15:46:47 +00:00
Nikita Bobko d39755b578 [FE] Convert specific diagnostic for actual function with default arguments into a common incompatibility
^KT-59665 Fixed
Review: https://jetbrains.team/p/kt/reviews/11039/timeline

It's better to have this logic in common place
(AbstractExpectActualCompatibilityChecker) to avoid missing compilation
errors in the future

This commit fixes:
1. Missing compilation error for actual function with default arguments
   for 'actual typealias' KT-59665
2. Missing compilation error for actual function with default arguments
   for actual fake-override KT-59665

Alternative solution for KT-59665 is to create a special checker.

"incompatibility" vs "special checker":

Arguments for common incompatibility:
- What if we had a rule that expect and actual default params must
  match? If so then it certainly would be an incompatibility.
- Technically, we do the matching of expect and actual params (because
  we allow default params in common ancestors of expect and actual
  declarations).
- It's hard to check that the actual definition doesn't use default
  params because `ExpectedActualResolver.findActualForExpected` filters
  out fake-overrides and doesn't return them. It's not clear logic for
  me, that I'm afraid to touch.
  implicitActualFakeOverride_AbstractMap.kt test breaks if you drop this
  weird logic
- WEAK incompatibilities can be considered as "checkers". So it doesn't
  matter how it's implemented, as a "incompatibility" or a "checker"

Arguments against common incompatibility:
- Although we match expect and actual declarations to allow default
  params in common ancestors of expect and actual declarations, it's
  still can be considered that we check that the actual declaration
  doesn't have default params. And it doesn't feel right that we check
  correctness of the actual declaration in expect-actual matcher.
- ~~It may change the rules of expect actual matching~~ (It's not true,
  because ActualFunctionWithDefaultParameters is declared as WEAK
  incompatibility)
2023-08-10 15:46:46 +00:00
Nikita Bobko ab8913dee8 [FE] Cover "implicit actualization"/"actual fake-overrides" KT-58544 with regression tests
Review: https://jetbrains.team/p/kt/reviews/11039/timeline
2023-08-10 15:46:45 +00:00
marat.akhin ae4fab8483 [KMP] Allow matching expect ctorless final classes to objects
both directly and via typealias.

This is a possible fix to KT-59747
2023-08-08 23:18:35 +00:00
Roman Efremov 6943d03883 [FE, IR] Make expect actual annotations diagnostic message more friendly
Print which annotation exactly has a problem instead of
printing whole declarations with all annotations.

^KT-58551
2023-08-02 13:12:31 +00:00
Roman Efremov 31f21d8593 [IR] Fix IR expect-actual annotations checker in case when annotation is actual typealias
^KT-60830 Fixed
2023-08-01 14:10:04 +00:00
Roman Efremov 5ed3f308fa Add tests for repeatable annotations on expect-actual declarations
Add tests showing current behavior.

^KT-60670
2023-08-01 14:04:03 +00:00
Roman Efremov 3a3b30aef4 Fix mistake in name of test
^KT-58551
2023-08-01 07:08:24 +00:00
marat.akhin 34b271b13d [KMP] Implement ACTUAL_TYPE_ALIAS_TO_NOTHING/TO_NULLABLE_TYPE errors
^KT-60650 Done
2023-07-27 09:13:37 +00:00
Nikita Bobko f4ba5aaf9a [FE 1.0] Prohibit implicit Java actualization in K1
^KT-58545 Fixed
Review: https://jetbrains.team/p/kt/reviews/10561

It's not yet supported in K2 KT-59213

Related tests:
- ApiTest.testStdlib
- RuntimePublicAPITest.kotlinStdlibRuntimeMerged
- KotlinProjectViewTestGenerated.test_Arrays (in Kotlin plugin)
2023-07-25 22:30:09 +02:00