Commit Graph

2309 Commits

Author SHA1 Message Date
Artem Kobzar 800704a130 [K/JS] Allow private constructors inside external declarations ^KT-65964 Fixed 2024-02-27 16:51:07 +00:00
Artem Kobzar 3429cbd321 [K/JS] Support companion objects in external and exported declarations 2024-02-27 16:30:13 +00:00
Roman Efremov 23ae617ea0 Fix inaccurate report of DEPRECATED_ACCESS_TO_ENTRY_PROPERTY_FROM_ENUM
Add separate diagnostic for the case when it is reported on qualifiers.

^KT-64488
2024-02-27 11:22:35 +00:00
Roman Efremov 02b5fed389 Fix inaccurate report of DEPRECATED_ACCESS_TO_ENTRY_PROPERTY_FROM_ENUM
It can be reported not only from within the enum, but also from
top-level functions. Add separate diagnostic for such cases.

^KT-64488
2024-02-27 11:22:35 +00:00
Nikita Bobko c31a72a4af [FIR] Switch FirExpectActualDeclarationChecker to Platform checker
^KT-66028 Fixed
2024-02-25 18:18:55 +00:00
Nikita Bobko 7924573d20 [FIR] Report redeclaration across KMP source sets
^KT-57585 Fixed

Related tests:
- MultiPlatformIntegrationTestGenerated.testSimpleNoImplKeywordOnTopLevelFunction
- MultiPlatformIntegrationTestGenerated.testWeakIncompatibilityWithoutActualModifier
- FirPsiJsKlibDiagnosticsTestGenerated.testSignatureClash_MPP
- LLFirPreresolvedReversedDiagnosticCompilerFirTestDataTestGenerated$ResolveWithStdlib$MultiModule.testFakeOverrides
- DiagnosticCompilerTestFE10TestdataTestGenerated$Tests$Multiplatform:
- LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated$Tests$Multiplatform
- FirOldFrontendMPPDiagnosticsWithPsiTestGenerated
- FirOldFrontendMPPDiagnosticsWithLightTreeTestGenerated
- FirLibraryModuleDeclarationResolveTestGenerated.testDataClass
- org.jetbrains.kotlin.idea.k2.highlighting.K2HighlightingMetaInfoTestGenerated$Diagnostics.testDataClassFromLibrary
- org.jetbrains.fir.uast.test.FirLightClassBehaviorTest.testContainingFile
- org.jetbrains.fir.uast.test.FirLightClassBehaviorTest.testAnnotationParameterReference
- org.jetbrains.uast.test.kotlin.org.jetbrains.uast.test.kotlin.comparison.FE1LightClassBehaviorTest.testContainingFile
2024-02-22 16:06:36 +00:00
Nikolay Lunyak da6006b7d0 [FIR] Relax intersection overrides visibility requirements for Java
Allow multiple bases with default
implementations as long as there's a
non-abstract symbol from a class.

Our rules for Kotlin are stricter than
those in Java.
2024-02-21 20:24:13 +00:00
Nikolay Lunyak 76ed5453b3 [FIR] Report all Visibilities.Unknown in FirOverrideChecker
Check all members for `Visibility.Unknown`,
otherwise we miss them when they come
from supertypes. This is the reason why
the FP intellij build failed with a
cryptic stacktrace instead of a
human-readable diagnostic.

Also, do report the diagnostic at all
cases of `Visibilities.Unknown`. Turns
out, there are no "simple to reason
about" situations here :(

Also, an interesting detail:
`retrieveDirectOverriddenOf` returns an
empty list for intersection overrides.
But this doesn't seem to break anything...

Replacing `CANNOT_INFER_VISIBILITY`'s
type `KtDeclaration` with
`PsiNameIdentifierOwner` and the related
changes in `PositioningStrategies`
were needed to prevent an exception saying that
`PsiClassImpl` is not a subtype of
`KtDeclaration`.
2024-02-21 20:24:13 +00:00
Evgeniy.Zhelenskiy 2e66954d01 [FIR] Forbid no then branch in if expression
#KT-59883
2024-02-21 15:04:02 +00:00
Alexander Udalov 5ca7ab9801 K2 JVM: implement Java modules-related checkers
All existing tests use custom test data for FIR because the diagnostic
text in FIR has to have a dot at the end. Also, the K2 checker doesn't
check usages in imports because there are no "import checkers" in K2
right now, this will need to be fixed later if necessary.

 #KT-60797 Fixed
2024-02-21 14:10:44 +00:00
Kirill Rakhman f231338cd6 [FIR] Render list of symbols with linebreaks as separators
#KT-61823 Fixed
2024-02-21 12:25:22 +00:00
Dmitrii Gridin 072d191306 [compiler] replace Enum values() with entries
To fix warnings. Also, use of `Enum.entries` may improve the performance

^KT-48872
2024-02-20 17:56:46 +00:00
Tomas Husak ec167d4d42 K2: implement FirForLoopStatementAssignmentChecker
#KT-60006 Fixed
2024-02-20 17:34:49 +00:00
Ivan Kochurkin 55159694df [FIR] Use Operator origin for ITERATOR and HAS_NEXT function calls instead of Regular
It automatically fixes KT-62356 since iterators now are operators

^KT-62356 Fixed
2024-02-20 13:30:47 +00:00
Ivan Kochurkin 04ead1716a [FIR] Prohibit constructor and supertype on typealias with type projection
Introduce `CONSTRUCTOR_OR_SUPERTYPE_ON_TYPEALIAS_WITH_TYPE_PROJECTION`

^KT-60305 Fixed
2024-02-19 19:27:28 +00:00
Anastasia.Nekrasova fd4f6c90c7 [K/N][K2] K2 behavioral difference with inconsistent inheritance of ObjCName
Support for complex cases with multiple substitution overrides.

#KT-64276 Fixed
2024-02-19 09:29:43 +00:00
Anastasia.Nekrasova bb8c7dd04c [K/N][K2] K2 behavioral difference with inconsistent inheritance of ObjCName
When a declaration with an ObjC annotation is stored in a different
module, the annotation arguments are not resolved by default. This leads
to a bug in the checker. Before attempting to find the objCName, it is
necessary to resolve the annotation first.

#KT-64276
2024-02-19 09:29:43 +00:00
Mark Mann ec12637d7a [K/N][K2] INCOMPATIBLE_OBJC_NAME_OVERRIDE error message changed from K1
There's been a change in the error message for
INCOMPATIBLE_OBJC_NAME_OVERRIDE in K2 which makes it much more difficult
to diagnose the underlying issue. Previously in K1 the symbol that had
an incompatible objc name would be output, but in K2 only the class
declaration is output making it difficult to determine which member is
causing the error.

#KT-65572 Fixed
2024-02-16 11:20:54 +00:00
Nikolay Lunyak 8f8c7fe7cf [FIR] Properly calculate visibilities
`testIntersectionOfPrimitiveBasedFunctions`
is fine, because we deprecate this
already in ^KT-63243.

`CANNOT_INFER_VISIBILITY` is
positioned as `DECLARATION_NAME`,
just in case we decide for
some reason that we do want to
report it along with
`MANY_*_NOT_IMPLEMENTED`. In that
case, we'd get a problem that
their bounds overlap, but not
completely contain one another.

^KT-63741 Fixed
^KT-59400 Fixed
2024-02-15 16:10:14 +00:00
Nikolay Lunyak 7056ad5325 [FIR] Set status.isOverride for fake overrides
Even though SO may not be correct
overrides sometimes, it feels more
natural to treat fake overrides as...
well, "overrides". And without it
we'd need to make the code in
`FirOverrideChecker` less intuitive.
2024-02-15 16:10:13 +00:00
Nikolay Lunyak 694029d67f [FIR] Run FirOverrideChecker for fake overrides
The change in
`FirOptInUsageBaseChecker` is needed
to prevent `OPT_IN_OVERRIDE` on
intersection overrides where one
of the base functions requires opt-in.
We never designed this in such
a way that it's an error.
See:
`FirPsiOldFrontendDiagnosticsTestGenerated.testIncorrectTargetsForExperimentalAnnotation`.

According to KT-63741, the case like
`kt40510.fir.kt` should, in fact,
be an error. It will be addressed
separately.
2024-02-15 16:10:13 +00:00
Nikolay Lunyak 3b5fff5473 [FIR] Don't copy VP default values for fake overrides
In general, overrides should not
contain default values, and it's
better to make fake overrides be close
to proper overrides as much as
possible. It will be important when
we begin running `FirOverrideChecker`
for fake overrides.

^KT-63879 Fixed
^KT-65534
2024-02-15 16:10:13 +00:00
Dmitriy Novozhilov c64575f4a2 [FIR] Move check for _private-to-this_ visibility into checker
^KT-55446
^KT-65790 Fixed
2024-02-15 13:08:35 +00:00
Kirill Rakhman 33648e1f44 [FIR] Unwrap vararg array types for diagnostic rendering
#KT-65770 Fixed
2024-02-15 10:48:56 +00:00
Roman Efremov 3994e3f63a [FIR] Deprecate using typealias as callable qualifier in import
^KT-64350 Fixed
2024-02-15 08:37:02 +00:00
Kirill Rakhman 35e9170af1 [FIR] Rename hidden methods around HiddenEverywhereBesideSuperCalls and add documentation. 2024-02-14 13:13:01 +00:00
Kirill Rakhman e8cbd8a1cd [FIR] Report OVERRIDE_DEPRECATION for overrides of HIDDEN_IN_DECLARING_CLASS_ONLY
#KT-65438 Fixed
2024-02-14 13:13:01 +00:00
Kirill Rakhman 2f49272c42 [FIR] Create fake hidden versions of List.getFirst/getLast in JDK < 21
... so that overrides are marked as deprecated regardless of the JDK.

#KT-65440 Fixed
2024-02-14 13:13:01 +00:00
Kirill Rakhman c6b2675089 [FIR] Implement deprecation for calls to overrides of hidden
#KT-65438
2024-02-14 13:13:00 +00:00
Kirill Rakhman e16f80c578 [FIR] Prevent duplicate full stop in DEPRECATION messages 2024-02-14 13:13:00 +00:00
Pavel Kunyavskiy 6e8a7d4662 [ObjCInterop] Implement @ObjCSignatureOverride
This annotation leads to conflicting overloads error supression,
in case where several function with the same argument types,
but different argument names are inherited from ObjC class.

We need to implement it in both K1 and K2 to make the IDE experience
better.
But the annotation itself wouldn't be available in K1.

    ^KT-61323
2024-02-14 11:44:01 +00:00
Nikolay Lunyak fdb2b714c9 [FIR] Remove redundant INITIALIZER_TYPE_MISMATCH introduced earlier 2024-02-14 09:57:12 +00:00
Alexander Korepanov c828b924b2 [JS FIR] Fix JS_NAME_CLASH false positive report
Intersections for interfaces and generic interfaces work differently.
`FirIntersectionCallableSymbol.getNonSubsumedOverriddenSymbols()`
does not retrieve the original symbol for a symbol inherited from
generic interfaces.
The patch explicitly obtains original symbols if they exist.

^KT-65216 Fixed
2024-02-13 12:19:29 +00:00
Stanislav Ruban 64083d6d5c [FIR][checkers][minor] Move FirNativeForwardDeclarationGetClassCallChecker to an appropriate package 2024-02-13 09:47:16 +00:00
Stanislav Ruban bc0633188c [FIR][checkers][minor] Move several checkers to more appropriate directories
Some FIR checkers were placed into the wrong directories either
by accident or minor oversight. This commit contains fixes
for such cases that were made during work on an internal KCCQA utility
to simplify its workings.

This commit is expected not to affect much (if anything).
2024-02-13 09:47:16 +00:00
Kirill Rakhman 58264e177f [FIR] Improve UPPER_BOUND_VIOLATED message
Suggest removing explicit type arguments when the upper bound is a
captured type since the only way to satisfy the upper bounds is
by letting the type variable be inferred to its bound.

#KT-65681 Fixed
2024-02-12 10:42:51 +00:00
Kirill Rakhman 9391ff8179 [FIR] Implement toString in FirTypeRefSource 2024-02-12 10:42:50 +00:00
Nikolay Lunyak 3db7df6898 [FIR] Fix FirDuplicateParameterNameInFunctionTypeChecker
It was supposed to check only function types...

Also note that it's probably impossible
to write a simpler test right now,
because we have a massive problem that
we ignore `FirTypeRef`s with `null`
sources despite having a dedicated
family of checkers for them
specifically. This will be fixed
separately as KT-65647.

^KT-65584 Fixed
^KT-65647
2024-02-12 09:00:15 +00:00
Nikolay Lunyak 8ec248131d [FIR] Reproduce KT-65584
The diagnostic target source element
type was changed to prevent crash due
to `checkPsiTypeConsistency()` in
`duplicateParameterNameSimplified.fir.kt`

^KT-65584
2024-02-12 09:00:15 +00:00
Nikita Bobko ab726fee3d [FIR] FirJvmNameChecker: take into account effective modality
^KT-65604 Fixed
Required for: KT-61798
Review: https://jetbrains.team/p/kt/reviews/14230/timeline

Related tests:
- DiagnosticCompilerTestFirTestdataTestGenerated$ResolveWithStdlib.testAnnotationUseSites
2024-02-09 19:49:35 +00:00
Nikita Bobko 58e1c4c6ac [FIR] Kmp: Deprecate header/impl keywords
Review: https://jetbrains.team/p/kt/reviews/14224/timeline

Timeline:
**(1)** Kotlin 1.1.60 https://github.com/JetBrains/kotlin/commit/59efedf610a25b004edf3d19897ce4dfca28ddb2 `header` keyword is introduced (committed on Dec 13, 2016)
**(2)** Kotlin `header`/`impl` has been deprecated (warning) at least since 1.1.60 https://github.com/JetBrains/kotlin/commit/5d251062677e09d607f295189b7978d5833e448f (committed on Sep 15, 2017)
**(3)** 1.1.60 release https://repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-compiler/1.1.60/ Nov 13, 2017

It sounds stupid but it looks like `header` was introduced and
deprecated right in the same release. Though it may be possible that we
had a release between **(1)** and **(2)** that I couldn't find

Anyway the keywords have been deprecated since basically forever

The fix is not perfect

"The perfect fix" would be:
1. Introduce a separate `DEPRECATED_MODIFIER_ERROR` diagnostic
2. Introduce LanguageVersionSettings for the `DEPRECATED_MODIFIER_ERROR`
   diagnostic

But "the perfect fix" requires:
1. Adopting `ReplaceModifierFix` in the IDE to make it work with the new
   diagnostic. `ReplaceModifierFix` is only implemented in K1 IDE. So
   there are two ways:
   1. Create a KTIJ ticket to port the diagnostic to K2 IDE (it needs to
      be ported anyway), and **mention** in the ticket that
      `DEPRECATED_MODIFIER_ERROR` also needs to be supported in K2 IDE.
      It's the ticket that nobody will probably find and fix
   2. Go and port `ReplaceModifierFix` to K2 IDE myself. It's fairly
      simple task, but I've not worked in intellij for quite a while,
      and it will take me too much time to index and compile

Considering that DEPRECATED_MODIFIER diagnostic is used only to report
`header`/`impl`, and there are literally 0 known cases when people use
it. It's just easier to convert the diagnostic to error in K2

Related tests:
- compiler/testData/diagnostics/tests/multiplatform/deprecated/header.kt

^KT-59839 Fixed
2024-02-08 16:34:27 +00:00
Ivan Kochurkin 6570d3fd55 [FIR] Minor fixes in FirDelegateUsesExtensionPropertyTypeParameterChecker
Fix a link in DELEGATE_USES_EXTENSION_PROPERTY_TYPE_PARAMETER message
2024-02-07 21:15:59 +00:00
Ivan Kochurkin c4e0cafe9c [FIR] Check DELEGATE_USES_EXTENSION_PROPERTY_TYPE_PARAMETER for anonymous objects
^KT-64102 Fixed
2024-02-07 21:15:59 +00:00
Alexander Udalov 28797a31b4 JVM: refactor JvmDefaultMode, remove/rename some entries
- remove ENABLE/COMPATIBILITY because they can no longer be used
- remove forAllMethodsWithBody because its behavior is now equivalent to
  isEnabled
- inline isCompatibility
- inline DEFAULT
- rename ALL_INCOMPATIBLE -> ALL
2024-02-06 17:18:44 +00:00
Igor Yakovlev ff20ae34e5 [Wasm/WASI] Allow external declarations only for top-level functions
Fix #KT-63737
2024-02-06 12:03:08 +00:00
Kirill Rakhman 376a9b8ace [FIR] Implement deprecation for accessing private operators from public inline function
This only affects delegation operators as well as the for-loop-related
next and hasNext operators.
All the other operators worked correctly before.
In K2, the previously mentioned operator calls will be flagged with a
deprecation error and will become and error in 2.1.

#KT-59782 Fixed
2024-02-06 11:18:25 +00:00
Anastasia.Nekrasova 434470a4f5 [K/N][K2]: K2 behavioral difference with inconsistent inheritance of ObjCName
The problem arises when retrieveDirectOverriddenOf returns a
substitution override member. For such members, it is impossible to get
the first base member. For a correct result, it is required to find
originalForSubstitutionOverride for all substitutionOverrides.

#KT-64276 Fixed
2024-02-02 13:54:45 +00:00
Mikhail Glukhikh 7615d863d5 K2: add ACCIDENTAL_OVERRIDE_CLASH_BY_JVM_SIGNATURE for clashing functions
This diagnostic is reported on an explicitly-declared function which
overrides a regular Java function with the same signature as a hidden
one from the same scope.

#KT-64846 Fixed
2024-01-31 17:06:36 +00:00
Brian Norman fced126c9f [FIR] Properties defined in a do-while may not always be initialized
Local properties defined within the body of a do-while loop can be used
in the condition of the loop. However, use of a `continue` may mean the
property isn't always initialized, even if it is initialized when it is
defined. So while a local property may be within scope and has an
initializer, this doesn't always mean that the property is initialized.

As such, properties that are defined within a do-while loop and also
used in the condition of the same do-while loop should be tracked. Then,
these properties should still be checked for proper initialization even
if they have an initializer.

^KT-64872 Fixed
2024-01-31 13:37:30 +00:00
Kirill Rakhman 1626057f75 [FIR] Improve rendering of override related diagnostics
Render symbols completely and add containing declaration.
2024-01-31 11:16:50 +00:00