Commit Graph

4832 Commits

Author SHA1 Message Date
Ivan Kochurkin 968ecadff2 [FIR2IR] Erasure type of parameter of delegated property in K1 manner
Add `shouldEraseType` to `Fir2IrConversionScope`

^KT-62884 Fixed
2024-02-01 15:36:32 +00:00
Roman Golyshev a55b8d30fd KT-65425 [SLC] Correctly compute getQualifiedName for generated classes
Since the declarations generated by compiler plugins do not have proper
PSI (`classOrObjectDeclaration` in this case), we need to resort to
symbols for such declarations to compute the proper qualified name

^KT-65425 Fixed
2024-02-01 10:14:20 +00:00
Brian Norman dde2156f5f [FIR2IR] Always use property type if var
For destructing calls, the component type is used for the property type
in all cases. However, this can result in runtime and/or compilation
errors when the property is a var and changed, especially when the
component is a primitive but the property type is nullable. Instead,
only use the component type when the property is also a val.

^KT-64944 Fixed
2024-01-31 22:27:18 +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
Mikhail Glukhikh 49ec30735c K2: add a pair of KJ tests related to KT-64846 but w/out explicit override 2024-01-31 17:06:36 +00:00
Mikhail Glukhikh 30ad532ff9 K2/tests: add a similar to containsAndOverload test about charAt / get
Related to KT-64846
2024-01-31 17:06:35 +00:00
Nikita Bobko d69deb97fe K2: Put boolean DFA variables under a feature flag
^KT-62547 Fixed

I also tested the commit by disabling DfaBooleanVariables in all tests
and checking what tests will fail

I didn't find anything that worked in K1, but doesn't work in K2 with
DfaBooleanVariables disabled

Related tests:
- DiagnosticCompilerTestFirTestdataTestGenerated$Resolve$Smartcasts
- LLFirPreresolvedReversedDiagnosticCompilerFirTestDataTestGenerated$Resolve$Smartcasts
- PreFirIdeSpecTestGenerated$NotLinked$Dfa
- DiagnosticCompilerTestFE10TestdataTestGenerated$Tests$SmartCasts
- FirPsiDiagnosticTestGenerated$Resolve$Expresssions.testSyntheticSmartCast
2024-01-31 16:31:02 +00:00
Kirill Rakhman 853ad54699 [FIR] Fix incorrect updating of callable reference type in delegated property
... if the delegate happens to be a function call whose second
argument is a callable reference but not actually a provideDelegate
call.
The fix is to ensure that the call is _actually_ a desugared
provideDelegate call.

This fixes a CCE in a case where the delegate expression is a regular
function call and the second argument is a callable reference.

#KT-65165 Fixed
2024-01-31 14:51:51 +00:00
Marco Pennekamp 64ad40e863 [LL] LLFirAbstractSessionFactory: Fix eager loading of anchor module sessions
- `LLFirAbstractSessionFactory` should not load other sessions eagerly
  because session creation occurs inside a `computeIfAbsent`, which does
  not allow recursive updates to the session cache.
- The issue has not surfaced so far because the default implementation
  of `computeIfAbsent` is not sensitive to recursive updates.

^KT-65418 fixed
2024-01-31 12:19:42 +00:00
Kirill Rakhman 1238f081b7 [FIR] Defer computation of intersection override return type if overridden has implicit return type
#KT-59921
2024-01-31 11:16:50 +00:00
Kirill Rakhman 9ec0210c04 [FIR] Support enhancing intersection overrides
When a type annotated with @PurelyImplements (explicitly or implicitly)
inherited some methods from a java supertype and the purely implemented
Kotlin supertype, it was inconsistent which of the signatures the
intersection override would have (with or without flexible types).
This commit adds support for the enhancement of intersection overrides.
If one of the overridden methods has non-flexible types, the enhanced
method will have non-flexible types.
This fixes some false negative nullability type mismatches.

#KT-59921 Fixed
2024-01-31 11:16:50 +00:00
Kirill Rakhman 3b841dcb98 [FIR] Don't remove subsumed members from intersection overrides's overriddens
This fixes a bunch of missing overridden symbols in IR.
This is also required for fixing KT-59921 in the following commit
where we need to keep all overridden symbols of intersection overrides
so that we can enhance them properly.

#KT-57300 Fixed
#KT-57299 Fixed
#KT-59921
#KT-57300
#KT-62788
#KT-64271
#KT-64382
2024-01-31 11:16:50 +00:00
Dmitry Savvinov d80dee6e1c [k2] Convert allDependsOnDependencies to FirModuleData member property
This essentially caches topological sort of dependsOn-dependencies in
FirModuleData. Caching it became more necessary after previous commits
that started to call it quite frequently in
VariableStorageImpl.getStability
2024-01-31 09:53:45 +00:00
Dmitry Savvinov 337330f8c8 [Tests] Add a test on smartcasts on properties from dependsOn modules
Behaviour is undesired, will be fixed in the next commit
2024-01-31 09:53:45 +00:00
Dmitry Savvinov 6661a66fc3 [Tests] Add tests on smartcasts on static Java fields
Current behavior for different modules is undesired, will be fixed in
the next commit

^KT-58279
2024-01-31 09:53:45 +00:00
Dmitry Savvinov 008d670469 [Tests] Fix exception from SealedClassInheritorsProviderForTests
'getValue' throws if the key isn't present.

Modules without .kt-files might be legitimately absent in inheritorsMap
(see org.jetbrains.kotlin.analysis.low.level.api.fir.compiler.based.SealedClassesInheritorsCaclulatorPreAnalysisHandler)

Previously, such tests were not failing because if a module doesn't
contain .kt-files, then it contains only .java files. And there was
another bug in the tests infra that was essentially folding all the
.java-files in one main-module, effectively shadowing the bug in subject
of this commit.
2024-01-31 09:53:44 +00:00
Dmitry Savvinov f19859db4e [Tests] Do not add .java-files of whole project to contentScope in K2
Previously, the code was calling into
TopDownAnalyzerFacadeForJVM.newModuleSearchScope, which includes
AllJavaSourcesInProjectScope.

This lead to .java-sources being incorrectly attributed to wrong
modules in tests, which, in turn, could've introduced undesired
behaviour around module-dependent checks (e.g. whether a variable
is from the other module and thus can't be smartcasted)
2024-01-31 09:53:44 +00:00
Dmitry Savvinov d03ee3150b Minor: fix typo 2024-01-31 09:53:44 +00:00
Nikolay Lunyak b6e913cde7 [FIR] Reproduce KT-65058
^KT-65058
2024-01-31 08:27:33 +00:00
vladislav.grechko d27adf6677 [FIR] Forbid multiple labels per statement
^KT-53629: Fixed
2024-01-30 19:58:53 +00:00
vladislav.grechko cd5b38b958 [FIR] Unwrap error expressions when detecting USAGE_IS_NOT_INLINABLE
Otherwise, false positive USAGE_IS_NOT_INLINABLE may be detected

^KT-65316: Fixed
2024-01-30 19:58:53 +00:00
vladislav.grechko 9aa8fb80e7 Set correct IR origins for inc/dec operations
NB: in order to produce correct IR origins, the source element kinds for
some FIR elements has been changed. As a side effect, mapping PSI to FIR
slightly changed: namely, for `a[b]++`, `a[b]` used to be mapped on
`set` call or callable reference, but now it is mapped on `get` call.

^KT-61891: Fixed
^KT-64387: Fixed
2024-01-30 14:26:10 +00:00
vladislav.grechko 8b1d87848d [FIR2IR] Fix unwrapping of single-statement blocks
Unwrapping should be done with respect to `forceUnitType` parameter.

^KT-65019: Fixed
2024-01-30 14:26:10 +00:00
Marco Pennekamp 9a4bf0601e [AA] Add KtClass-based KotlinSealedInheritorsProvider
- The compiler's `SealedClassInheritorsProvider` should not be exposed
  outside LL FIR, as it is an internal compiler component and also
  exposes `FirRegularClass`. `KotlinSealedInheritorsProvider` is an
  Analysis API provider for sealed inheritors that accepts a `KtClass`
  instead.

^KT-64718 fixed
2024-01-30 11:48:09 +00:00
Yan Zhulanow e001fa4e72 [Analysis API] Explicitly specify the context module in a directive 2024-01-30 11:41:26 +00:00
Yan Zhulanow 892212bdf6 [Analysis API] Add type code fragment test for a local class 2024-01-30 11:41:26 +00:00
Yan Zhulanow 3cd04a9e9e [Analysis API] Migrate existing code fragment tests to the new API 2024-01-30 11:41:26 +00:00
Yan Zhulanow ef890e9b76 [Analysis API] Add reference resolution tests for code fragments 2024-01-30 11:41:26 +00:00
Yan Zhulanow c548bed6f6 [Analysis API] Fix 'getContainingDeclaration()' for code fragments
^KT-65075 Fixed
2024-01-30 11:41:26 +00:00
Yan Zhulanow 1c883c93fc [Analysis API] Minor, prettify 'getContainingPsiDeclaration()' 2024-01-30 11:41:26 +00:00
Yan Zhulanow 83ad6eca08 [Analysis API] Minor, prettify 'hasParentSymbol()' 2024-01-30 11:41:26 +00:00
Yan Zhulanow 01ca31a061 [Analysis API] Add test infrastructure for code fragments
Now, Analysis API tests can define modules with code fragments.
The preceding module will be used as a context module.
2024-01-30 11:41:26 +00:00
Jinseong Jeon 42e8245007 AA: take into account type arguments if available
...when computing receiver type for double colon expression
2024-01-30 06:57:27 +00:00
Jinseong Jeon 2429d09edd AA: use explicit qualifier type if available
...when computing receiver type for double colon expression

^KT-65150 fixed
2024-01-30 06:57:27 +00:00
Brian Norman 7f9774819c Revert "[FIR] Do not smartcast class delegation implemented properties"
This reverts commit bb6f466162.

Reverting the fix for KT-57417 as it causes failures in IntelliJ and
Space projects. May reintroduce fix after failures are investigated and
resolved.
2024-01-29 19:24:03 +00:00
Nikita Bobko 19c46662c6 [FIR] Fix missing ACTUAL_WITHOUT_EXPECT when expect is fake-override
^KT-65270 Fixed
KT review: https://jetbrains.team/p/kt/reviews/14064/timeline
IJ review: https://jetbrains.team/p/ij/reviews/124657/timeline
2024-01-29 14:56:49 +00:00
Nikita Bobko c214c5445a [FIR] Implement EXPECT_AND_ACTUAL_IN_THE_SAME_MODULE
^KT-60367 Fixed
KT review: https://jetbrains.team/p/kt/reviews/14064/timeline
IJ review: https://jetbrains.team/p/ij/reviews/124657/timeline
2024-01-29 14:56:48 +00:00
Brian Norman bb6f466162 [FIR] Do not smartcast class delegation implemented properties
When a property is implemented via class delegation, it should be
considered unstable for smart-casting. This is because it is unknown
what kind of stability the underlying class delegate property has. It
could be a stable property, or it could be implemented via a custom
getter and unstable.

^KT-57417 Fixed
2024-01-29 14:20:11 +00:00
Artem Kobzar 1fe77705b0 [K/Wasm] Convert non-capturing lambdas into singletons ^KT-64803 Fixed 2024-01-29 12:52:18 +00:00
Dmitrii Gridin e03f8b503f [LL FIR] implement lock resolution algorithm for jumping phases
This commit extends `LLFirLockProvider` API functionality to provide
`withJumpingLock`, which can be safely used in multithreaded scenarios.
Comparing to regular `withWriteLock`/`withReadLock`, the new API has a
bit more overhead as we have to maintain `jumpingResolutionStatesStack`
and `FirInProcessOfResolvingToJumpingPhaseState` even without contention.
See KDoc of `LLFirLockProvider#withJumpingLockImpl` for implementation
details.

The implicit type phase has been migrated to the new approach, so
now it is safe to drop the last global phase lock.
Potentially, we can have some benefits from migration of other
jumping phases to this API.

^KT-56551 Fixed
^KT-55750 Fixed
2024-01-29 12:39:09 +00:00
Dmitrii Gridin 58ed52ee1f [LL FIR] LLFirTargetResolver: drop withPossiblyJumpingLock function
We should have explicit separation for jumping and non-jumping

^KT-56551
2024-01-29 12:39:09 +00:00
Dmitrii Gridin 0a55cfebd5 [LL FIR] LLFirLockProvider: cleanup code
^KT-56551
2024-01-29 12:39:09 +00:00
Dmitrii Gridin 92fc3ec824 [LL FIR] LLFirLockProvider: add registry key to disable global phase lock
It is enabled by default

^KT-56551
2024-01-29 12:39:09 +00:00
aleksandrina-streltsova d935db9e3a [Analysis API] render enhanced types
^KTIJ-28555 Fixed
2024-01-29 09:37:59 +00:00
Anastasia.Nekrasova ee143e9370 [K2]: compiler crash on unresolved delegated extention receiver
A report of UNRESOLVED_REFERENCE should not be made for elements like
FirImplicitThisReference that don't have a source, as they are implicit.

#KT-65044 Fixed
2024-01-29 07:59:13 +00:00
Anastasia.Nekrasova 1d817e2ace [K2]: Missing error and miscompilation in destructuring declaration delegation
In convertDestructingDeclaration, property delegates are mistakenly
treated as valid expressions for destructuring, but they should be
ignored.

#KT-65021 Fixed
2024-01-29 07:56:43 +00:00
Evgeniy.Zhelenskiy b0367d9399 [Reflection] Support callBy for inline class interface functions with default parameters
#KT-57972
2024-01-29 04:04:59 +00:00
Yan Zhulanow 36d5ffd4eb Revert "AA FIR: have KtFirReceiverParameterSymbol implement KtFirSymbol"
The commit is reverted due to failing tests:
    - FirGotoTypeDeclarationTestGenerated
    - FirGotoDeclarationTestGenerated

This reverts commit eb23984182.
2024-01-27 15:56:27 +09:00
Denis.Zharkov ca80ddb8ca K2: Run completion-writer related PCLA tasks for irregular call kinds
- For synthetic calls
- For delegated constructor calls

Also, I checked that for each toResolvedReference() (beside annotations)
that converts candidate to the resolved reference,
we run `runPCLARelatedTasksForCandidate()` in the same context.

^KT-65103 Fixed
2024-01-26 18:13:27 +00:00
Denis.Zharkov df2a1d4d02 K2: Refine handling of Delegate resolution mode
- Move it out of the ContextDependent hierarchy
- Get rid of many controversial checks that were necessary because
Delegate was a ContextDependent inheritor
- Actually fix semantics for lambda processing

Previously, lambdas as delegate expression were not being analyzed
thus leading to an exception (see KT-64635), and this change
forces analyzing them in the same mode as ContextIndependent
(thus `{}` made by default `() -> Unit` leaving to DELEGATE_SPECIAL_FUNCTION_MISSING)

Before this change, new test was failing with an exception.

I've analyzed all `is ContextDependent` and it seems that none of them
is relevant to delegates.

^KT-64635 Fixed
2024-01-26 16:56:07 +00:00