1747 Commits

Author SHA1 Message Date
Aleksandra.Arsenteva 83d0e1f447 [Test] KT-66152 Add tests for generic static function 2024-03-14 10:16:46 +00:00
Mikhail Glukhikh d897bfbcad Fix tests after a semantically conflicting merge of KT-50008 and KT-65596 2024-03-12 14:54:10 +00:00
Kirill Rakhman 973e337bf5 [FIR] Enhance getter overrides based on overridden properties
The following tests are failing with exceptions and will be fixed in the
following commits

j+k/testKjkPropertyAndExtensionProperty.kt
j+k/testKjkImplicitReturnType.kt

#KT-62118 Fixed
2024-03-12 10:29:45 +00:00
Mikhail Glukhikh c4bcdc42c1 K2: don't count use-sites of Java type parameter with nullable bounds as not null 2024-03-11 18:05:04 +00:00
Mikhail Glukhikh 60f9206d3b Fix test data for IR fake override tests 2024-03-11 13:38:05 +00:00
Mikhail Glukhikh 78b6432ced K2: don't make T = Type! substitutions for constructors, including SAM
Without this commit we get some ABI changes and it looks bad.

Related to KT-65596
2024-03-11 13:38:05 +00:00
Denis.Zharkov 81414d758d K2: repeat K1 representation for flexible type parameters
This commit changes the behavior of KT-59138 effectively declining it in 2.0.
However, we plan to implement KT-59138 behavior under a feature
flag in 2.0 (see KT-66447), and switch this feature on version 2.x.

Also, this commit implements the LC resolution about postponing
KT-57014 change. We don't have KT-57014 described behavior in 2.0 anymore.
However, we plan to implement a deprecation warning here, see KT-65578.

After this commit, 6 diagnostic tests become incorrectly broken:
- 5 tests from PurelyImplementedCollection group
- a test platformTypes/nullableTypeArgument.kt

This commit also breaks currently fixed-in-k2 KT-50134
(it is fixed again in the following commits),
as well as KT-58933 (it will remain not fixed till we enable KT-59138
behavior again).

#KT-65596 In Progress
#KT-57014 In Progress
#KT-58933 Submitted
2024-03-11 13:38:05 +00:00
Ivan Kochurkin ea44d4defd [FIR2IR] Remove non-existent accessors from property references on Java fields
Rename `MissingFieldInJavaClass` to `FieldsFromJavaClass` to correspond its content

^KT-65722 Fixed

Merge-request: KT-MR-14837
2024-03-08 10:10:05 +00:00
Dmitriy Novozhilov 4b5eac7816 [Test] Add regression tests for issues which are fixed in K2
Related issues:
KT-10879, KT-18055, KT-20617, KT-23873
KT-25668, KT-31191, KT-33108, KT-41013
KT-51827, KT-53886, KT-56624, KT-58447
KT-58458, KT-58751, KT-58814, KT-60597
KT-62806, KT-63258, KT-63444, KT-65101
KT-65408, KT-65844, KT-66186

^KT-65926 Fixed
2024-03-07 12:49:47 +00:00
Wojciech Litewka cbabfc0fe2 [IR] Drop ir.ir2cfg module
#KTI-952 Fixed
#KT-65773 Related
2024-03-06 18:30:22 +00:00
Kirill Rakhman 69a7bf7f68 [FIR] Add equality constraint from expected type for some synthetic function calls
This fixes some cases where we infer some type variable inside one
of the branches to Nothing instead of the expected type because Nothing
appeared in some other branch.

Specifically, we add an equality instead of a subtype constraint during
completion of calls to synthetic functions for if/when, try and !!.
We don't do it when the call contains a (possibly nested) elvis or is
inside the RHS of an assignment.
Otherwise, we would prevent some smart-casts.

#KT-65882 Fixed
2024-03-05 17:38:59 +00:00
Alexander Udalov 77b3f415a5 IR: fix "most specific" check in IrFakeOverrideBuilder
There were several problems with it:

1) `isMoreSpecific` should return true if a == b. Otherwise
   `isMoreSpecificThenAllOf` would never return true because it's always
   invoked with a collection that contains the candidate. K1 behaves
   similarly, `OverridingUtil.isMoreSpecific` returns true if a == b.
   So in fact, "more" should be understood as "not less" here.
2) `transitivelyMostSpecificMember` in `selectMostSpecificMember` was
   always equal to the first element, so `isMoreSpecific` was invoked
   with incorrect arguments.
3) At the end of `selectMostSpecificMember`, we selected the first
   candidate with the non-flexible return type, however only dynamic
   type was considered. We need to check `isFlexible` via type system
   instead.

 #KT-66120 Fixed
2024-03-05 09:19:38 +00:00
Alexander Udalov 19cc7981dc Update test data for IR text tests 2024-03-05 06:59:11 +00:00
anzhela.sukhanova 82255d5ee8 [Test] KT-61360: add tests for the IrFakeOverrideBuilder
Add tests for fake overrides with focus on java interoperability

Co-authored-by: Aleksandra Arsenteva <aleksandra.arsenteva@jetbrains.com>
2024-03-04 16:21:02 +00:00
Kirill Rakhman 5bca945d05 [FIR] Fix nullability of types produced by ConeRawScopeSubstitutor
#KT-66067 Fixed
2024-03-01 14:08:39 +00:00
Brian Norman 78bb0be7aa [FIR2IR] Propagate NOT_IN statement origin when converting to IR
^KT-65636 Fixed
2024-02-29 15:10:09 +00:00
Artem Kobzar 2e4d02e9f4 [PSI2IR, K/Wasm] Sync start and end offsets on PSI and FIR for primary constructors 2024-02-29 14:42:33 +00:00
Alexander Udalov dfd9aabf8e JVM: update test data after enabling IR fake override builder
#KT-61514 Fixed
2024-02-29 10:14:31 +00:00
Alexander Udalov f98a22e8e4 Fir2Ir: enable IR-based fake override builder
Invert the logic of IR/FIR2IR-based generators: change the CLI argument
to -Xuse-fir-fake-override-builder, test directive to
USE_FIR_BASED_FAKE_OVERRIDE_GENERATOR, etc.

The changes in test data caused by using IR fake override builder by
default are in the subsequent commit.

 #KT-61514
2024-02-29 10:14:31 +00:00
Kirill Rakhman 5e83350576 [Infrastructure] Assert dumps don't exist without directive
#KT-58697 Fixed
2024-02-29 08:36:16 +00:00
Dmitriy Novozhilov 2febc807a1 Revert "[FIR2IR] Remove non-existent accessors from property references on Java fields"
This reverts commit 1e388ad7dc.
2024-02-28 13:26:25 +00:00
Dmitriy Novozhilov dd94de3a34 [FIR2IR] Properly set statement origin for all parts of += calls
^KT-65649 Fixed
2024-02-28 08:28:14 +00:00
Artem Kobzar 02a78051aa [PSI2IR] Sync start and end offsets on PSI and FIR for an implicit return inside lambdas 2024-02-27 19:25:24 +00:00
Pavel Kunyavskiy c991535756 [IRFakeOverrides] Fix accessors visibilities
^KT-65801
2024-02-23 16:35:27 +00:00
Kirill Rakhman 4780bb90e7 [FIR] Fix mapping of java annotation arguments when parameter is array
#KT-65933 Fixed
2024-02-23 14:01:16 +00:00
Dmitriy Novozhilov 6479b15e46 [Test] Add regression test for KT-65493 2024-02-23 12:16:12 +00:00
Ivan Kochurkin 1e388ad7dc [FIR2IR] Remove non-existent accessors from property references on Java fields
Rename `MissingFieldInJavaClass.kt` to `FieldsFromJavaClass.kt` to correspond its content

^KT-65722 Fixed
2024-02-23 11:22:44 +00:00
Dmitriy Novozhilov 4c9fc8f214 [FIR2IR] Add @EnhancedNullability and @FlexibleNullability independently
Previously @EnhancedNullability for IR type was added if only there wasn't
  an @FlexibleNullability annotation, which is inconsistent with K1
  behavior

^KT-65302 Fixed
2024-02-21 12:04:11 +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
Dmitriy Novozhilov da567e54b9 [Test] Reproduce KT-65302 2024-02-21 12:04:11 +00:00
Dmitriy Novozhilov 3c86a4f9df [IR] Consider flexibility of the return type for intersection overrides
^KT-65207 Fixed
2024-02-21 12:04:11 +00:00
Dmitriy Novozhilov 9302c8c14d [Test] Reproduce KT-65207 2024-02-21 12:04:11 +00:00
Alexander Udalov cf425ffded Tests: fix stdlib declarations in IR interpreter test data
Fix some unresolved supertypes. This is necessary to be able to enable
IR fake override builder by default (KT-61514), because it traverses all
supertypes and asserts that they're classes, so that it can build fake
overrides for declarations from there. Without this change, for example
`IrFakeOverrideBuilder.buildFakeOverridesForClass` would crash.
2024-02-21 08:47:01 +00:00
Kirill Rakhman b054a4481d [FIR2IR] Fix cast insertion in SAM conversion with suspend conversion
#KT-65878
#KT-62855
2024-02-20 12:52:08 +00:00
Dmitriy Novozhilov 3469e3b198 [FIR2IR] Create delegated field for delegation to var property
^KT-65920 Fixed
2024-02-20 09:46:17 +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
Dmitriy Novozhilov d1e7b9b4cf [Test] Add Fir Identical checkers for signature dump handler 2024-02-19 13:59:48 +00:00
Pavel Kunyavskiy 576851e514 [Tests] Update testdata after bad rebase 2024-02-16 15:37:28 +00:00
Pavel Kunyavskiy e6f4d6e6fa [Tests] Use stable order for ir/kotlinLike dumps
^KT-65406
2024-02-16 10:19:38 +00:00
Pavel Kunyavskiy 0fa42a9c11 [Tests] More conservative stableOrdered dump
Order of enum entries and fields matters, we can't sort them too.

^KT-65460
2024-02-16 10:19:38 +00:00
Dmitriy Dolovov 9219a8f485 [FIR] Expand type of vararg parameter before constructing array type
This helps to have a primitive array instead of an array of primitives
as the type of vararg value parameter. Also, this prevents
ABI-incompatibility with the libraries (KLIBs) compiled with K1.

^KT-65588
2024-02-15 11:55:32 +00:00
Dmitriy Dolovov 05cbe66ee0 [FIR][tests] Unify IntArrayAsVararg.kt test between K1 and K2
Rename `main` function to `test` to avoid running JVM-specific mangling
and having different IR signature dumps for K1 and K2.

^KT-65588
2024-02-14 23:00:04 +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 931480b12d [FIR2IR] Fix nullability of converted raw types
#KT-65298 Fixed
2024-02-14 09:55:24 +00:00
Pavel Kunyavskiy 831ef0f909 [FakeOverrideBuilder] Fix referencing a local type from a return type
Copying tree part happens in two stages.
1. Collect all symbols to copy and create new version of them
2. Do copy tree, replacing collected symbols

For f/o builder 1-st stage traversed more nodes, than seconds.
This led to unbound symbols in tree.

^KT-65273 Fixed
2024-02-12 08:39:35 +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
Sergej Jaskiewicz 88b80e0ed2 [FIR2IR] Add Unit coercion for non-last expressions in try/catch blocks
^KT-61088 Fixed
2024-02-08 22:16:20 +00:00
Sergej Jaskiewicz b5793222d8 [test] Drop unnecessary WITH_STDLIB in an irText test 2024-02-08 22:16:20 +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
Alexander Udalov 53c5230520 IR: copy EnhancedNullability in CopyIrTreeWithSymbolsForFakeOverrides
Otherwise it leads to the following problem in the newly added test.

Suppose that we have a fake override `remove(Int)` inherited from
LinkedList _without_ EnhancedNullability on its parameter type. By
normal Kotlin rules, this method should override the method from
KotlinInterface. However, on JVM we have another overridability check in
IrJavaIncompatibilityRulesOverridabilityCondition which ensures that
"JVM primitivity" of parameter types is the same for the base and the
overridden method.

So the fake override `remove(Int)` from LinkedList is determined to be
override-incompatible with `remove(Int)` from KotlinInterface. But when
we try to create symbols for all fake overrides in the class, we get a
clash because there are two fake overrides with exactly the same
IdSignature, neither of which overrides the other.

If we keep the EnhancedNullability annotation on the parameter, it
starts working because the logic of computing signature in
JvmIrMangler.JvmIrManglerComputer.mangleTypePlatformSpecific adds an
"{EnhancedNullability}" mark to the IdSignature of a fake override from
LinkedList.

 #KT-65499 Fixed
2024-02-05 13:28:19 +00:00