Commit Graph

6393 Commits

Author SHA1 Message Date
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
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
Dmitriy Novozhilov b87aa470dd [Test] Ensure FIR doesn't fail on recursive private-to-this case
^KT-55446
2024-02-15 13:08:36 +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 81e0abeb8f [FIR] Fix mapped constructor hiding logic
Partially reverts 24367e0ad8

Constructors have their own list of hidden/visible.
We now require the constructor to be in VISIBLE_CONSTRUCTOR_SIGNATURES,
everything else is hidden.
This makes it unnecessary to check HIDDEN_CONSTRUCTOR_SIGNATURES

#KT-65821 Fixed
2024-02-15 13:08:15 +00:00
Kirill Rakhman 33648e1f44 [FIR] Unwrap vararg array types for diagnostic rendering
#KT-65770 Fixed
2024-02-15 10:48:56 +00:00
Kirill Rakhman 879cdd5952 [FIR] Fix flattening of substitution overrides of intersection overrides for subsumed check
#KT-65555 Fixed
2024-02-15 08:43:06 +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
Brian Norman e3ddeff230 [FIR] Track local variable assigned types for smartcast stability
When a lambda captures a local variable without a contract, future
assignments can impact the smartcast stability for that variable within
the lambda. Because future assignments can appear in both resolved and
unresolved code, track each assignment as encountered. To determine if
a smartcast can be considered stable, check that all future assignments
are resolved and do not revert variable to a super type.

^KT-58191 Fixed
2024-02-14 17:44:53 +00:00
Dmitrii Gridin e02c28c88a [LL FIR] support lazy resolve of destructuring declaration entries
^KT-62840 Fixed
^KT-65727
2024-02-14 16:16:01 +00:00
Kirill Rakhman e39af4583e [FIR] Report deprecation on synthetic property calls on super receivers
#KT-65438 Fixed
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 24367e0ad8 [FIR] Implement isHiddenEverywhereBesideSuperCalls logic for constructors
#KT-61448 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 fc6d25e50f [FIR] By default, only hide members from mapped scope but not overrides
This affects methods like List.getFirst/getLast where it was decided
to keep them hidden but to make them visible on overrides like
ArrayList or LinkedList.
The goal is to prevent a breaking change since some implementations
like LinkedList had this method before JDK 21.

#KT-65438
2024-02-14 13:13:00 +00:00
Nikolay Lunyak fa5ae18980 [FIR] Fix a typo in a test data file name
^KT-65337
2024-02-14 09:57:13 +00:00
Nikolay Lunyak fdb2b714c9 [FIR] Remove redundant INITIALIZER_TYPE_MISMATCH introduced earlier 2024-02-14 09:57:12 +00:00
Nikolay Lunyak 389f02b016 [FIR] Let FirErrorExpression have a working type if possible
^KT-65337 Fixed
2024-02-14 09:57:12 +00:00
Nikolay Lunyak 7f42596935 [FIR] Reproduce KT-65337
^KT-65337
2024-02-14 09:57:12 +00:00
Mikhail Glukhikh 6ed7c041b4 K1/K2: add various tests for context receiver tower resolve priority
Related to KT-64531, KT-64488
#KT-64531 As Designed
2024-02-14 09:55:51 +00:00
Kirill Rakhman e88865e4c7 [FIR] Fix methods with erased parameters missing from raw collection scope
#KT-65448 Fixed
2024-02-14 09:55:24 +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 91e4837c95 [Tests] Add test for #KT-65712 2024-02-12 10:42:51 +00:00
Pavel Kirpichenkov 3dede06d51 [Tests] Add diagnostic tests for sealed class inheritors
- Fix unrelated resolution errors in an existing test
- Add separate test for sealed classes and interfaces in HMPP projects,
located in different source sets

KT-64919
2024-02-12 10:17:20 +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
Kirill Rakhman b90598823e [FIR] Improve approximation of captured types
- Handle flexible types in recursion check
- Handle intersected supertypes separately
- Make check when not to approximate captured types in type argument
  position more fine-grained.
  Only apply it to case when the captured type is replaced by a star
  projection.
  All other cases are handled by recursive calls to
  approximateCapturedType

#KT-65377 Fixed
2024-02-12 08:47:10 +00:00
Nikita Bobko 21fff5634e [FIR] Fir modality of FirPropertyAccessor
^KT-61798 Fixed
Review: https://jetbrains.team/p/kt/reviews/14230/timeline

Q: How resolved modality of an accessor affects expect/actual matching
   algorithm of properties?
A: It's not expect/actual matching of properties, but expect/actual
   matching of properties setter. Declarations (setters in our case) in
   actual are allowed to have wider visibility but only if the
   appropriate expect is `final`. Before this commit, all property
   accessors were always `final` by mistake. After this commit, they
   have the modality derived from their containingProperty.

Related problem: PositionStrategy for ACTUAL_WITHOUT_EXPECT can be
improved KT-65720

The fix in `resolveModality` is similar to how `resolveVisibility` works

Related tests:
- ConfigurationCacheForAndroidIT.testKotlinAndroidProject
- FirIdeNormalAnalysisSourceModuleCombinedDeclaredMemberScopeTestGenerated.testEnumClassWithAbstractMembers
- FirIdeNormalAnalysisSourceModuleCombinedDeclaredMemberScopeTestGenerated.testEnumEntryInitializerWithOverriddenMember
- FirIdeNormalAnalysisSourceModuleDeclaredMemberScopeTestGenerated.testDelegateInterfaceLibrary
- FirIdeNormalAnalysisSourceModuleDeclaredMemberScopeTestGenerated.testEnumClassWithAbstractMembers
- FirIdeNormalAnalysisSourceModuleDeclaredMemberScopeTestGenerated.testEnumEntryInitializerWithOverriddenMember
- FirIdeNormalAnalysisSourceModuleMemberScopeTestGenerated.testEnumClassWithAbstractMembers
- FirIdeNormalAnalysisSourceModuleMemberScopeTestGenerated.testEnumEntryInitializerWithOverriddenMember
- FirIdeNormalAnalysisSourceModuleSymbolByPsiTestGenerated.testEnumEntryOverride
- FirIdeNormalAnalysisSourceModuleSymbolByPsiTestGenerated.testEnumValueMember
- FirStandaloneNormalAnalysisSourceModuleCombinedDeclaredMemberScopeTestGenerated.testEnumClassWithAbstractMembers
- FirStandaloneNormalAnalysisSourceModuleCombinedDeclaredMemberScopeTestGenerated.testEnumEntryInitializerWithOverriddenMember
- FirStandaloneNormalAnalysisSourceModuleDeclaredMemberScopeTestGenerated.testEnumClassWithAbstractMembers
- FirStandaloneNormalAnalysisSourceModuleDeclaredMemberScopeTestGenerated.testEnumEntryInitializerWithOverriddenMember
- FirStandaloneNormalAnalysisSourceModuleMemberScopeTestGenerated.testEnumClassWithAbstractMembers
- FirStandaloneNormalAnalysisSourceModuleMemberScopeTestGenerated.testEnumEntryInitializerWithOverriddenMember
- DiagnosticCompilerTestFE10TestdataTestGenerated*testChangeSetterVisibilityInOverride
2024-02-09 19:49:35 +00:00
Mikhail Glukhikh a189509353 K2: build override structure for Java renamed builtins more precisely
#KT-65410 Fixed
2024-02-09 19:04:42 +00:00
Mikhail Glukhikh ba374a3978 K2: reproduce KT-65410 in diagnostic/BB tests 2024-02-09 19:04:42 +00:00
Denis.Zharkov a4ccb72b94 Add tests making sure that a couple of issues are fixed by PCLA
^KT-49283 Fixed
^KT-64077 Fixed
2024-02-09 13:03:12 +00:00
Mikhail Glukhikh e532220305 K1/K2: add a test fixing behavior of overloadResolutionByLambda/PCLA combo 2024-02-09 11:38:34 +00:00
Evgeniy.Zhelenskiy 7eab4b672d [K1, K2, CLI] Mark whole position range of compiler diagnostics in CLI
#KT-64989
2024-02-08 12:59:31 +00:00
Mikhail Glukhikh 94bcf6d87f K2: handle recursive types properly in approximation
This commit is intended to deal with inconsistency in K1/K2
star projection handling.
K1 star projection includes a 'type' property.
This type from a star projection can be used for relevant
functions / properties return types,
and already includes some approximation for recursive generics.
In contrast, K2 star projection is an object,
and return types of relevant functions / properties are
represented as captured types.
To prevent recursion in them in recursive generic case,
this commit includes additional replacement of their type arguments.
See more details in added comments.

#KT-65057 Fixed
2024-02-08 10:49:55 +00:00
Mikhail Glukhikh c4d6554493 K2: reproduce KT-65057 2024-02-08 10:49:55 +00:00
Brian Norman 1f904aef55 [FIR] Enhance equality smartcasting test case to include data classes
^KT-58169 Fixed
2024-02-07 22:26:16 +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
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
Dmitrii Gridin 39131a7f30 [LL FIR] rework FirDesignation collector
The main change – now we collect not only `FirRegularClass`, but also
`FirScript`.
This allows us to have a proper context collector for
diagnostics for scripts.
Also, this change fixes dangling files for scripts in `IGNORE_SELF`
as now we have the correct patcher for this case, so we won't resolve
the copied script

^KT-65345
^KT-62841 Fixed
2024-02-05 09:32:45 +00:00
anzhela.sukhanova 14b6f6d050 [Test] KT-59012: tests for inferring types based on self upper bound
Add tests on JK inheritance cases, extension functions for Enum and some basic recursive type cases
2024-02-05 09:05:13 +00:00
Mikhail Glukhikh e1df52bc02 K2: handle non lookup-tag based types in private-to-this analysis
#KT-62134 Fixed
2024-02-02 17:12:02 +00:00
Mikhail Glukhikh 3c3396a87e K2: reproduce some situations related to KT-62134 2024-02-02 17:12:02 +00:00