Commit Graph

7745 Commits

Author SHA1 Message Date
Dmitriy Novozhilov 5b01396a11 [FIR] Carefully process constructors of inner and nested classes in the tower
If there is an expression receiver, we should process constructors only
  of inner classes. Constructors of nested classes can be called only
  on classifier

^KT-65333 Fixed
2024-02-28 08:08:32 +00:00
Dmitriy Novozhilov 67557ce731 [Test] Reproduce KT-65333 2024-02-28 08:08:31 +00:00
Abduqodiri Qurbonzoda 557ea32f87 Introduce kotlin.AutoCloseable typealias in K/JVM stdlib #KT-55777 2024-02-27 20:52:49 +00:00
Artem Kobzar 3429cbd321 [K/JS] Support companion objects in external and exported declarations 2024-02-27 16:30:13 +00:00
Andrei Tyrin 4e10dcd808 [tests] Klib based signature clash improve coverage for KT-63670 2024-02-27 14:01:44 +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
Roman Efremov 34d87465ac [Test] Add test for Enum.entries shadowing when property is imported
This is similar to KT-64488 but without context receivers.
Warning message "access ... from within the enum" is also incorrect
here.

^KT-64488
2024-02-27 11:22:35 +00:00
Mikhail Glukhikh 678816f9e8 K1: introduce BUILDER_INFERENCE_STUB_PARAMETER_TYPE to prevent compiler crashes
This diagnostic is reported in rare situations when
StubTypeForBuilderInference is kept as a parameter type
of for loop or lambda. Before this commit, we had in K1
"Could not load module <error module>" from IrLinker instead.

Related to: KT-52757, KT-53109, KT-63841, KT-64066
#KT-53478 Fixed
2024-02-27 10:25:13 +00:00
Dmitriy Novozhilov 6f6e37f552 [FIR] Report about recursion in implicit types for receivers of invoke
^KT-65576 Fixed
2024-02-27 09:34:02 +00:00
Dmitriy Novozhilov 234cc5be2b [Test] Reproduce KT-65576 2024-02-27 09:34:02 +00:00
Mikhail Glukhikh 91e9fbd9bf K1: change depr. level of List.getFirst to HIDDEN but don't force it on overrides
#KT-65441 Fixed
2024-02-27 08:40:53 +00:00
Mikhail Glukhikh d870d9dcc6 K1/K2: add tests for KT-65441 current behavior 2024-02-27 08:40:52 +00:00
Nikolay Lunyak f1c7f929d2 [FIR] Don't miss diagnostics on resovled reified type parameters
^KT-66005 Fixed
2024-02-26 09:53:13 +00:00
Nikolay Lunyak b0e6db7807 [FIR] Reproduce KT-66005
^KT-66005
2024-02-26 09:53:13 +00:00
Kirill Rakhman c3c2f6f90a [FIR] Don't set lambda parameter type to Nothing by default
... when the expected type is not a function type.
Instead set it to a new type variable.
This fixes a bunch of false negative CANNOT_INFER_PARAMETER_TYPE.

#KT-59882 Fixed
2024-02-26 08:59:22 +00:00
Nikita Bobko c31a72a4af [FIR] Switch FirExpectActualDeclarationChecker to Platform checker
^KT-66028 Fixed
2024-02-25 18:18:55 +00:00
Ilya Chernikov 9ea775cbed K2 scripting: fix containing decl for last script expression
Generally the wrapping anonymous initializer can be used as a
"containing declaration" for some elements, but since the initialiser
for the last script expression could be dropped (the expression could
be converted to the result property), this may lead to the surprises,
e.g. as described in KT-65984
This fix marks the last initialiser as local, preventing it from being
referenced as "containing declaration".

#KT-65984
2024-02-23 22:03:44 +00:00
Nikolay Lunyak 35b172c40f [FIR] Ensure KT-65581 is non-reproducible
It seems it was briefly introduced at
and then present at `2.0.0-dev-14408`,
but no longer is at `2.0.0-dev-16490`

^KT-65581 Obsolete
2024-02-23 11:52:13 +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 01cff6b5e9 [FIR] Call distinctBy for containsMultipleNonSubsumed
Otherwise, when analyzing
`PsiTypeParameterListOwner` in the
related test, we (after flattening and
`nonSubsumed()`) get 2 `JvmMember.accept`
from the same very java enhancement
scope `JvmMember`.

^KT-65972
2024-02-21 20:24:17 +00:00
Nikolay Lunyak 453b97a2d1 [FIR] Reproduce one more failure for KT-65972 #3
^KT-65972
2024-02-21 20:24:17 +00:00
Nikolay Lunyak 341a23d05c [FIR] Introduce containsMultipleNonSubsumed to intersection overrides
After this change the IO created for
`SimpleColoredComponent::setToolTipText`
will be `containsMultipleNonSubsumed == true`
while IOs created for classes in
`intersectionOverridesIntersection.kt`
will have this property set to `false`.

^KT-65972 Fixed
2024-02-21 20:24:16 +00:00
Nikolay Lunyak ee20d979cb [FIR] Reproduce one more failure for KT-65972 #2
And refactor another related test to
explain the desired behavior.

^KT-65972
2024-02-21 20:24:16 +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
Nikolay Lunyak 053eb07692 [FIR] Reproduce KT-65972
This code does lead to inferring
`Visibilities.Unknown`, but it's not
reported anywhere. This is because it
happens inside `AbstractIntSet` which
comes to us "pre-compiled" by javac,
whereas `FirOverrideChecker` only checks
members within `KotlinClass`.

^KT-65972
2024-02-21 20:24:13 +00:00
Evgeniy.Zhelenskiy 931f2eab58 [FIR] Remove implicit coercion of ifs and whens to Unit
The rule of thumb is the following:
If the `if` and `when` can be successfully replaced with `while`,
then it is used as a statement, otherwise, it is used as an expression.

#KT-59883
2024-02-21 15:04:03 +00:00
Evgeniy.Zhelenskiy 2e66954d01 [FIR] Forbid no then branch in if expression
#KT-59883
2024-02-21 15:04:02 +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
Dmitriy Novozhilov bd66b96f8a [FIR] Set EnhancedNullability attribute for former flexible types
In some cases we transform flexible type into non-flexible during
  enhancement, but don't add `@EnhancedNullability` attribute to them,
  which breaks consistency with K1 on IR level

This commit fixes it

^KT-65302
2024-02-21 12:04:11 +00:00
Ilya Chernikov cdf4b17052 K2 Scripting tests: adding tests on script decls visibility
fixes (makes it stable) behavior of the script top-level declarations
visibility in K2 scripts
2024-02-21 07:47:15 +00:00
Ivan Kochurkin 9a86b83a0c [FIR] Fix crash on assignment expression with incorrect lvalue with LT mode
^KT-65241 Fixed
2024-02-20 20:09:08 +00:00
Tomas Husak ec167d4d42 K2: implement FirForLoopStatementAssignmentChecker
#KT-60006 Fixed
2024-02-20 17:34:49 +00:00
Kirill Rakhman 9606a5a441 [Tests] Add test for vararg callable reference adaption with typealias
#KT-65817 Fixed
2024-02-20 14:11:14 +00:00
Kirill Rakhman 365973f03a [Tests] Convert diagnostics test for #KT-65555 to box test 2024-02-20 14:10:37 +00:00
Kirill Rakhman 26fae9e83a [FIR] Allow declarations to override parts of non-trivial intersection
A class can inherit two declarations that are compatible from the
overridability standpoint and are therefore combined to a non-trivial
intersection.
At the same time, the class can declare a member declaration that
only overrides one of the intersection's members.
In this case, we break up the intersection and only add the overridden
parts to the declared member's direct overridden list.

If the class doesn't override the intersection, it exists as
intersection override, like before.

#KT-65487 Fixed
2024-02-20 09:02:39 +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
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 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 d69240a2d5 [FIR] Fixed behavior of FirAnnotation.findArgumentByName for resolved annotations
The 'findArgumentByName' function was returning an invalid result for
annotation arguments with omitted argument name.

#KT-64276
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
vladislav.grechko 3dda88ddc2 [FIR] Handle FirErrorExpression when resolving arguments
^KT-65787: Fixed
2024-02-19 08:50:59 +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
Nikolay Lunyak 249886fb13 [FIR] Ensure the case from KT-63741 works
^KT-63741
2024-02-15 16:10:13 +00:00
Nikolay Lunyak 2ad0be7bdc [FIR] Ensure the case from KT-63578 works
^KT-63578
2024-02-15 16:10:12 +00:00
Stanislav Ruban 9fb920874c [tests] Add additional test data for KT-64222 2024-02-15 13:22:23 +00:00