Commit Graph

6237 Commits

Author SHA1 Message Date
Ivan Kochurkin 1f0fb5a1a8 [FIR] Check for ConeErrorType in doUnify to prevent endless recursion
^KT-64625 Fixed
2024-01-05 19:21:10 +00:00
Mikhail Glukhikh 8a560d2629 FE tests: don't render text of disabled diagnostics 2024-01-05 17:20:32 +00:00
Nikolay Lunyak aea2e8052a [FIR] Ensure KT-64089 works
Make sure SENSELESS_COMPARISON
is absent in this case.

^KT-64089 Obsolete


Merge-request: KT-MR-13754
Merged-by: Nikolay Lunyak <Nikolay.Lunyak@jetbrains.com>
2024-01-05 14:15:06 +00:00
Nikolay Lunyak 8cd87059c8 [FIR] Fix the failing test after merging 533ed5c6
It started failing because of other
changes having been merged right before it

^KT-64644 Fixed

Merge-request: KT-MR-13755
Merged-by: Nikolay Lunyak <Nikolay.Lunyak@jetbrains.com>
2024-01-05 13:34:43 +00:00
Ivan Kochurkin 69b9bfc3e0 [FIR] Initialize public visibility for class-like declarations at FIR building phase if no modifier is presented
Java resolving subsystem requires calculated visibility for correct disambiguation of supertypes.
But visibility remains `Unknown` for Kotlin class-like declarations during supertypes resolving because `STATUS` resolve phase is performed after `SUPER_TYPES` phase.
To fix the problem, the visibility should be initialized to public at the FIR building phase if no modifier is presented.

^KT-64127 Fixed
2024-01-04 16:17:32 +00:00
Brian Norman aae8cd2a7c [FIR] Local variable assignment must be propagated before loops
When performing lookahead for local variable assignments, make sure
assignments taking place within loops are being propagated before loops.
This makes sure smartcasts within non-inline declarations before the
loop are disallowed.

^KT-63867 Fixed
2024-01-04 14:20:21 +00:00
Kirill Rakhman 10d6d95ee8 [Tests] Add regression test for #KT-64702 2024-01-04 14:12:42 +00:00
Nikolay Lunyak 7c3042772e [FIR] Reproduce KT-64644
Ensure the given code crashes the
compiler.

^KT-64644
2024-01-04 14:08:43 +00:00
Nikolay Lunyak 9c0ac27307 [FIR] Don't miss annotations on properties from primary constructors
^KT-64609 Fixed
2024-01-04 09:45:27 +00:00
Nikolay Lunyak 1f46aed3e0 [FIR] Reproduce KT-64609
^KT-64609
2024-01-04 09:45:27 +00:00
Kirill Rakhman 1018ff280e [FIR] Fully expand the bounds of type parameters for canBeNull check
This is required because a not-null bound `Foo` can resolve to a
`typealias Foo = Bar?` in which case we must return true.

#KT-64645 Fixed
2024-01-03 17:15:50 +00:00
Brian Norman 3346cc4b19 [FIR] Lambdas without contracts should be considered repeatable
^KT-63777 Fixed
2024-01-03 14:08:04 +00:00
Kirill Rakhman fd12f24725 [FIR] Only let supertypes of ILTs include Number when it's not unsigned
#KT-64607 Fixed
2024-01-03 12:05:18 +00:00
Kirill Rakhman 5d3738c804 [FIR] Improve annotation use-site target rendring for diagnostics
#KT-62816 Fixed
2024-01-02 15:17:02 +00:00
Kirill Rakhman 8f3f72d9c9 [FIR] Use correct type renderer in symbol rendering for diagnostics
#KT-62815 Fixed
2024-01-02 15:17:02 +00:00
Kirill Rakhman 6b049df87c [FIR] Render deprecation message if it's not a named argument. 2024-01-02 15:17:02 +00:00
Kirill Rakhman 8aa32d9f45 [FIR] Rename DUPLICATE_LABEL_IN_WHEN to DUPLICATE_BRANCH_CONDITION_IN_WHEN
... and fix the message

#KT-35289 Fixed
2024-01-02 15:17:02 +00:00
Ivan Kochurkin 88f7b085e6 [FIR] Try to infer result type of incomplete when expression
^KT-62069 Fixed
2023-12-22 16:57:07 +00:00
Kirill Rakhman ad2689ecbf [FIR] Prefer the non-smartcasted receiver in resolution if it's visible
Previously, we would ignore the candidate with the non-smartcasted
receiver if they have the same symbol.
Now we prefer them when they're visible or when the smart cast changes
the nullability.
2023-12-21 13:29:01 +00:00
Kirill Rakhman 5186ba80e2 [FIR] Check for setter visibility in resolution stage
This is required for the following commit where candidates from the
original scope in presence of smart cast will not be ignored if they're
the same symbol.
2023-12-21 13:29:00 +00:00
Mikhail Glukhikh a02cf76d6c K2: build SAM-based function type for a given captured type properly
Before this commit, we assumed (erroneously) that a captured type
cannot have an associated SAM-based function type.
In this commit we changed this assumption, replacing a captured type
with its lower type for this purpose

#KT-63379 Fixed
2023-12-21 10:19:23 +00:00
Mikhail Glukhikh 8588588760 K2: add test reproducing KT-63379 2023-12-21 10:19:23 +00:00
Mikhail Glukhikh 3a106fc88e K1/K2: add some more tests around KT-63558 2023-12-21 07:43:38 +00:00
Mikhail Glukhikh d3a0a6cabe K2: discriminate candidates with adaptations in the first place in ConeOverloadConflictResolver
Before this commit, we discriminated particular candidates with callable
reference adaptations during resolution stages.
After disabling compatibility mode for new inference, it's not so,
but now we discriminate similar candidates in ConeOverloadConflictResolver;
more precisely, it's candidates with callable reference adaptation
in their postponed atoms.
This does not allow going up the tower,
but allows to select better candidate at similar tower level.

Related to KT-63558, KT-64307, KT-64308
2023-12-21 07:43:38 +00:00
Mikhail Glukhikh 087edc026d K2: discriminate particular SAMs in the first place in ConeOverloadConflictResolver
Before this commit, we discriminated particular candidates with SAM
during resolution stages. More precisely, candidates from Kotlin
which used Java SAM types, were discriminated allowing go up the tower
for better candidates. After disabling compatibility mode for new
inference, it's not so, but now we discriminate similar candidates
in ConeOverloadConflictResolver. This does not allow going up the tower,
but allows to select better candidate at similar tower level.

Related to KT-63558, KT-64306
2023-12-21 07:43:38 +00:00
Mikhail Glukhikh a7dc381b93 K2: disable compatibility mode for new inference
#KT-64306 Fixed
#KT-64307 Fixed
#KT-64308 Fixed
2023-12-20 21:39:21 +01:00
Ivan Kochurkin a2cd2200d6 [FIR] Infer Unit type for generic lambda function if implicit return exists
Make behavior more consistent with K1

^KT-63563 Fixed
2023-12-20 13:50:05 +00:00
Roman Efremov 30aad31ece [FIR, IR] Prohibit actualization of expect Kotlin property to Java field
The problem from KT-63624 was that during matching phase we must choose
only one candidate, but in Java we can have two successfully matched
properties: 1) from field and 2) from method, which overrides Kotlin
property.
See test `propertyAgainstJavaPrivateFieldAndPublicMethod.kt`.
As a result, we choose field candidate, throw away method candidate, and
then fail during visibility check.

Instead of inventing special rule of prioritizing field over method
it was decided to prohibit actualization to Java field at all because:

1. It doesn't seem that Java fields actualization was implemented in K1
on purpose
2. People usually don't use public Java fields, and use instead
private field + getter, especially when compatibility is important, so
it shouldn't be a breaking change

Besides that, such solution simplifies code and is consistent with
the current logic of matcher, which doesn't expect that two members
can be matched successfully. Also, it fixes KT-63624 and KT-63667.

^KT-63624 Fixed
^KT-63667 Fixed
2023-12-20 13:37:43 +00:00
Roman Efremov 3f95e99e29 [Tests] Add tests for matching of expect property against Java property
...via typealias. Java property can be either field or method, which
overrides Kotlin property.

^KT-63624
2023-12-20 13:37:43 +00:00
Mikhail Glukhikh c322644860 K2: report only warning on lambda parameters with missing dependencies
During the fix of KT-62525, we've forbidden to use lambda parameters
with inaccessible types at all. After it, some impact was noticed,
so we decided to forbid them only in case it's necessary
(the case when associated types have type arguments, see KT-62525
description), and to deprecate them in other cases.

#KT-64266 Fixed
2023-12-20 12:48:00 +00:00
Mikhail Glukhikh 44aa2d86d3 K2: add test to reproduce KT-64266 2023-12-20 12:47:59 +00:00
Dmitriy Novozhilov fa33c5dc79 [FIR] Implement deprecation warning for synthetic without java base getter
Also implement new resolution behavior under language feature

^KT-63076 Fixed
^KT-64358
2023-12-19 09:04:26 +00:00
Dmitriy Novozhilov be6694f049 [Test] Add tests for KT-63076 2023-12-19 09:04:26 +00:00
Aleksandra.Arsenteva c6b32200df [Test] Add diagnostic tests for smartcast in K2
List of issues:
KT-28806, KT-7186, KT-22997, KT-1982, KT-22996, KT-54443, KT-37308, KT-37115, KT-4113, KT-25747, KT-24779
2023-12-18 13:08:33 +00:00
Mikhail Glukhikh 7c53387fc4 K1/K2: add test confirming the behavior of KT-61694 case 2023-12-15 22:18:45 +00:00
Evgeniy.Zhelenskiy 20f74c22d7 [FIR] Support redeclaration diagnostics for different levels of destructured parameters
#KT-59875 #KT-59898
2023-12-15 21:00:01 +00:00
Kirill Rakhman 242e16baea [FIR] Don't check class super type annotations for loops
Only do it for typealiases.

#KT-64059 Fixed
2023-12-15 16:39:50 +00:00
Ivan Kylchik 46cb108a23 [K2] Forbid to use "get class" in the context of string concat and equality
#KT-63941 Fixed
2023-12-15 13:54:13 +00:00
Kirill Rakhman 3bfcf3090c [FE] Use indexed loop to prevent CME in incorporation
#KT-60225 Fixed
2023-12-15 08:47:09 +00:00
Brian Norman b2041e0927 [FIR] Disable data flow from in-place lambdas
There are many complications with the current design of passing data
from within in-place lambdas to surrounding code. Solving these
complications will involve more time to investigation than is available
within the K2 release. So we are disabling passing type statement
information from lambdas for the time being until more time can be
devoted to a more complete solution.

^KT-60958 Fixed
^KT-63530 Fixed
2023-12-14 16:40:27 +00:00
Nikita Bobko 599998039e [IR] Use resolveFakeOverrideMaybeAbstract instead of resolveFakeOverride in hasStableParameterNames
Well, the resolved fake-override can be ABSTRACT

^KT-64045 Fixed
2023-12-14 11:23:51 +00:00
Dmitriy Novozhilov fb00c1dfb6 [FIR] Prohibit suspend anonymous functions in statement position
^KT-62018 Fixed
^KT-62019
2023-12-14 10:32:59 +00:00
Anastasia.Nekrasova e58b5e7d22 K2: change resolution for deprecated actual declaration
This commit addresses a scenario where an 'actual' declaration is marked
with a Deprecated annotation at the 'Hidden' level, while the
corresponding 'expect' declaration is not. When resolving,
'CheckHiddenDeclaration' marks the 'actual' declaration as unsuccessful,
leading to the selection of the 'expect' declaration as the successful
candidate.

'FirDeprecationChecker' handles a case where an 'actual' class is
annotated with Deprecated, but the 'expect' class is not. During the
checking of the 'actual' class constructor, 'CheckHiddenDeclaration'
skips it due to the absence of a direct Deprecated annotation.
'FirDeprecationChecker' then identifies this constructor and reports a
DEPRECATION_ERROR.

'FirDeprecationChecker' will now be applied to solving problems related
to 'actual' declarations with corresponding Deprecated annotations. The
process remains the same: 'CheckHiddenDeclaration' will skip the
'actual' declaration, and then 'FirDeprecationChecker' will identify it
and report the error.

^KT-61792 Fixed
2023-12-14 09:21:43 +00:00
Nikita Bobko 8bbbbfa3ce [FIR] Fix MT intellij tests
MT stands for "modularized tests"

^KT-64166 Fixed
Review: https://jetbrains.team/p/kt/reviews/13517/timeline

This commit fixes:

    java.lang.IllegalArgumentException: Local <local>/<anonymous> should never be used to find its corresponding classifier
            at org.jetbrains.kotlin.fir.resolve.providers.impl.FirProviderImpl.getFirClassifierByFqName(FirProviderImpl.kt:252)
            at org.jetbrains.kotlin.fir.resolve.providers.impl.FirProviderImpl$SymbolProvider.getClassLikeSymbolByClassId(FirProviderImpl.kt:60)
            at org.jetbrains.kotlin.fir.resolve.providers.impl.FirCachingCompositeSymbolProvider.computeClass(FirCachingCompositeSymbolProvider.kt:131)
            at org.jetbrains.kotlin.fir.resolve.providers.impl.FirCachingCompositeSymbolProvider.access$computeClass(FirCachingCompositeSymbolProvider.kt:27)
            at org.jetbrains.kotlin.fir.resolve.providers.impl.FirCachingCompositeSymbolProvider$special$$inlined$createCache$1.invoke(FirCachesFactory.kt:75)
            at org.jetbrains.kotlin.fir.resolve.providers.impl.FirCachingCompositeSymbolProvider$special$$inlined$createCache$1.invoke(FirCachesFactory.kt:69)
            at org.jetbrains.kotlin.fir.caches.FirThreadUnsafeCache.getValue(FirThreadUnsafeCachesFactory.kt:40)
            at org.jetbrains.kotlin.fir.resolve.providers.impl.FirCachingCompositeSymbolProvider.getClassLikeSymbolByClassId(FirCachingCompositeSymbolProvider.kt:158)
            at org.jetbrains.kotlin.fir.resolve.transformers.mpp.FirExpectActualResolver.findExpectForActual(FirExpectActualResolver.kt:41)
2023-12-13 18:42:14 +00:00
Kirill Rakhman 44b3c66ad7 [FIR] Add companion scope before static scope
Static scope is checked first during resolution
(scopes are in reverse order).
This fixes a difference between how K1 and K2 resolve annotations.

#KT-63249 Fixed
2023-12-13 16:46:24 +00:00
Dmitriy Novozhilov 93563d7c80 [FIR] Report PROPERTY_AS_OPERATOR for all operator conventions
^KT-62347 Fixed
^KT-59715 Fixed
2023-12-13 09:27:14 +00:00
Dmitriy Novozhilov 92c75fb7ab [Test] Reproduce KT-59715 2023-12-13 09:27:14 +00:00
Tomas Husak 91465d7110 [FIR] KT-59421 add checker context receiver property backing field 2023-12-13 07:12:11 +00:00
Ivan Kylchik 79c300209e [K2] Avoid type check for Kotlin's property in ConstUtils
When we check Java field for constant initializer, we could
be asked to get and check the type of Kotlin's property that
is used in this Java field. But there is no guarantee that the type
resolve phase was finished and this type is available. So we just
check for `const` modifier and skip type check.

#KT-63752 Fixed
#KT-62558 Obsolete
#KT-61786 Declined
2023-12-12 13:54:32 +00:00
Ivan Kylchik 97ba3fe396 [K2] Revert changes done in KT-61786
Changes in this ticket remove type enhancement in java fields
for K2. But after KT-61920 fix, we can actually support it.
2023-12-12 13:54:31 +00:00