Commit Graph

6844 Commits

Author SHA1 Message Date
Brian Norman e8b4550173 [FIR] Add checker for finite bounds validation
Added a new FIR based checker for both FINITE_BOUNDS_VIOLATION and
FINITE_BOUNDS_VIOLATION_IN_JAVA errors. Implementation copied from the
existing descriptor based checker with some minor changes.

#KT-59378 Fixed
2023-08-11 21:13:58 +00:00
Kirill Rakhman cee355196a [Tests] Fix accidental overload resolution ambiguity in test 2023-08-11 10:54:25 +00:00
Kirill Rakhman 724d527fd8 [FIR] Fixes for call conflict resolution
Let ConeCompositeConflictResolver pass the results of the previous
resolver to the next one.
Otherwise, we get false positive conflicts when a set of candidates
can't be fully reduced by one resolver but could be resolved by the
subsequent application of multiple ones.
This change makes ConeCompositeConflictResolver order-dependent and
thus, ConeOverloadConflictResolver must be invoked last, because it
must work on a pre-filtered list.

Also, let ConeEquivalentCallConflictResolver use
FirStandardOverrideChecker instead of compareCallsByUsedArguments
because it's stricter.

This all fixes a false positive overload resolution ambiguity in common
metadata compilation that is caused by stdlib using the new KMP
format.
Now stdlib metadata is in the classpath, and so declarations from the
stdlib are returned from both MetadataSymbolProvider and
KlibBasedSymbolProvider.
This isn't a problem per se because duplicate candidates are filtered
out by ConeEquivalentCallConflictResolver (K1 works analogously), but
in the case of top-level functions with generic receivers like
Collection<T>.toTypedArray, the check failed because of the direct
comparison of receiver types.

#KT-60943 Fixed
2023-08-11 10:54:24 +00:00
Kirill Rakhman 86ef313233 [FIR] Check context receivers in FirStandardOverrideChecker
#KT-61145 Fixed
2023-08-11 10:54:24 +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
Nikolay Lunyak b7d1298f20 [FIR] Report UNSUPPORTED_SEALED_FUN_INTERFACE
^KT-59957 Fixed
2023-08-10 13:36:43 +00:00
Nikolay Lunyak 70e98c9c2b [FIR] Report inherited java members referencing FunctionN
^KT-60000 Fixed
2023-08-10 05:14:08 +00:00
Alexander Udalov bad7fa597b Tests: move some tests to diagnostics 2023-08-09 23:58:51 +00:00
Alexander Korepanov 7a31167e0b [Common IR] Do not add internal methods to overrides
[JS IR] Use a module name in JsFunctionSignature for internal methods

^KT-60635 Fixed
2023-08-09 16:35:59 +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
Alexander Udalov e87bccd5c7 K2: fix reporting of NO_REFLECTION_IN_CLASS_PATH on implicit invoke
#KT-61054 Fixed
2023-08-08 20:19:11 +00:00
Nikolay Lunyak 921db9f8d4 [FIR] Report UNSUPPORTED_SUSPEND_TEST
^KT-60002 Fixed
2023-08-08 16:48:02 +00:00
Nikolay Lunyak 71cc634a7c [FIR] Prevent missing diagnostics on free lambdas
The change in `FirPsiDiagnosticTestGenerated.Resolve#testCast`
only highlights the existing
problem that we don't assign a
valid type to `_`.

^KT-58906 Fixed
2023-08-08 11:00:04 +00:00
Kirill Rakhman 09f895efe6 [FIR] Implement VERSION_REQUIREMENT_DEPRECATION diagnostics 2023-08-08 09:28:08 +00:00
Nikolay Lunyak 7151e6a41c [FIR] Report UNSUPPORTED_CONTEXTUAL_DECLARATION_CALL
^KT-59969 Fixed
2023-08-04 15:17:21 +00:00
Nikolay Lunyak c2ad475153 [FIR] Render outer type parameters differently 2023-08-04 11:20:40 +00:00
Nikolay Lunyak e4246e8f51 [FIR] Support ENUM_CLASS_CONSTRUCTOR_CALL
^KT-59411 Fixed
2023-08-04 11:20:40 +00:00
Nikolay Lunyak f4ffd479cc [FIR] Support TYPEALIAS_EXPANDED_TO_MALFORMED_TYPE
^KT-59410 Fixed
2023-08-04 11:20:40 +00:00
Nikolay Lunyak 97b00793b4 [FIR] Prevent duplicate direct overridden-s from substitution overrides
This change prevents going up the scopes once we find a
substitution override. Whatever we'd find by going further is not
going to be a direct overridden anymore, so it would lead to incorrect
results when collecting direct overridden-s. Without this change, we get
error modules in FT intellij.
2023-08-04 11:20:40 +00:00
Nikolay Lunyak 61448531cb [FIR] Support MULTIPLE_DEFAULTS_INHERITED_FROM_SUPERTYPES
^KT-59408 Fixed
2023-08-04 11:20:39 +00:00
Nikolay Lunyak 9850987415 [FIR] Fix mutant extension function types
Consider the following example from
`extensionLambdasAndArrow.kt`:

```
val x4: String.() -> String = if (true) {
    { str: String -> "this" }
} else {
    { str: String -> "this" }
}
```

Because of
`coerceFirstParameterToExtensionReceiver`
the given lambdas must be of the type
`String.() -> String`, but because of a bug
they are `String.(String) -> String`. At the
same time, during inference their expected
types are, indeed, calculated correctly as
`String.() -> String`.

^KT-59394 Declined
(no more compiler crashes, #potential-feature)
2023-08-04 11:20:39 +00:00
Nikolay Lunyak bca44e5d8c [FIR] Prepend type variables with '+' rather than '_'
'++' is easier to notice than '__'.
'++++++' is easier to count than '######'.
2023-08-04 11:20:39 +00:00
Nikolay Lunyak a41273b966 [FIR] Properly add the outer type parameters
Looks like a type.

^KT-59393 Fixed
(because other differences are related to
nested typealiases)
2023-08-04 11:20:39 +00:00
Nikolay Lunyak 4bba93f633 [FIR] Implement PROTECTED_CONSTRUCTOR_NOT_IN_SUPER_CALL
^KT-59382 Fixed
2023-08-04 11:20:39 +00:00
Nikolay Lunyak 882b7fc9ca [FIR] Expand typealiases in extractNonFatalDiagnostics
^KT-59901 Fixed
2023-08-04 10:11:57 +00:00
Nikolay Lunyak c392b0c477 [FIR] Expand typealiases when resolving to companions
^KT-59901 Fixed
2023-08-04 10:11:57 +00:00
Nikolay Lunyak 4a9ba1c9ac [FIR] Expand typealiases when checking deprecations
^KT-59901 Fixed
2023-08-04 10:11:57 +00:00
Alexander Udalov 7fc3e60854 K2: add JVM checker for NO_REFLECTION_IN_CLASS_PATH warning
It's based on the existing K1 checker `JvmReflectionAPICallChecker`.

 #KT-60587 Fixed
2023-08-03 13:42:03 +00:00
Denis.Zharkov bd46bb02c1 K1: Enhance deprecation messages for getFirst/getLast JDK 21 members
^KT-60659 Fixed
^KT-60769 Fixed
2023-08-03 13:31:07 +00:00
Denis.Zharkov 0694ee50a3 K1: Report deprecation on synthetic properties for NOT_CONSIDERED JDK members
Currently, for other synthetic properties, deprecation from the original
method is already being propagated to the relevant new synthetic
property accessor.

But what we need is also reporting warnings on synthetic properties
accessors call-sites if original methods are considered deprecated
as a result of deprecation propagation.

KT-60659 Fixed
^KT-60769 Fixed
2023-08-03 13:31:07 +00:00
Denis.Zharkov eae97e4f76 K1: Force propagating deprecation on NOT_CONSIDERED JDK members to overrides
^KT-60858 Related
KT-60659 In Progress
^KT-60769 In Progress
2023-08-03 13:31:07 +00:00
Denis.Zharkov 1e86a82ee1 K1: Change how Kotlin sees some of the new JDK 21 collections members
- Make addFirst/Last and removeFirst/removeLast as members
- Leave getFirst/getLast unprocessed, thus visible for K1, but marked
as deprecated

Though the implementations of getFirst/getLast and synthetic property
access to them are expected to be deprecated as well, it's expected
to be fixed in later commits.

^KT-60659 In Progress
^KT-60769 In Progress
2023-08-03 13:31:07 +00:00
Denis.Zharkov 180a3bb320 K1: Fix false-positive ABSTRACT_MEMBER_NOT_IMPLEMENTED with JDK 21
Previously, it was reported for List.toArray because, when traversing
supertypes, we've been stopped at j.u.SequencedCollection
as it has no JavaAnalogue.

^KT-60770 Fixed
2023-08-02 15:32:25 +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
Kirill Rakhman ade1354a84 [FIR] If callable reference can't be resolved with expected type, try resolving with Any
In positions outside of calls (e.g. property initializers)
we resolve callable references using a synthetic outer call with the
expected type as parameter type.
If this fails, we previously returned an unresolved reference.
After this commit, we additionally try to resolve the callable reference
with expected type Any.
This lets us report more precise diagnostics like type mismatches or
when multiple overloads exist NONE_APPLICABLE.

#KT-55373 Fixed
#KT-55955 Fixed
2023-08-02 08:00:33 +00:00
Nikolay Lunyak 61d2e338a4 [FIR] Prevent compiler crash on lambdas in annotations
^KT-59110 Fixed
2023-08-01 14:58:52 +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
Kirill Rakhman 2de9480101 [FIR] Report deprecations on typealias constructor calls
Typealias constructor calls are now always wrapped with synthetic
FirConstructorCalls so that the referenced typeAlias can be extracted.
Previously, it was only necessary to map type arguments.

#KT-57780 Fixed
2023-08-01 13:50:22 +00:00
Roman Efremov 3a3b30aef4 Fix mistake in name of test
^KT-58551
2023-08-01 07:08:24 +00:00
Ivan Kochurkin dac8688a29 [FIR] Report missing TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM for local functions
^KT-59376
^KT-55221 Fixed
2023-07-31 17:38:46 +00:00
Anna Kozlova 8fb9461276 [Fir] get candidate from missed type args diagnostics in annotation call
Otherwise, navigation to unresolved reference is impossible ^ KTIJ-26441

In order to avoid duplicated diagnostic, wrapper is still used.
Symbol collector is updated to retrieve symbols from that wrapper.


Merge-request: KT-MR-11381
Merged-by: Anna Kozlova <Anna.Kozlova@jetbrains.com>
2023-07-31 16:12:17 +00:00
Kirill Rakhman 0a469ff3b9 [FIR] Use class scope to get constructors for redeclaration check
#KT-60793 Fixed
2023-07-31 08:13:49 +00:00