Commit Graph

47186 Commits

Author SHA1 Message Date
Ivan Kochurkin e3ddc843bc [FIR] Fix and simplify FirUnsupportedArrayLiteralChecker 2024-01-18 14:39:54 +00:00
Ivan Kochurkin 2be9a341ca [FIR] Report ARGUMENT_TYPE_MISMATCH for nested array literals
^KT-61843 Fixed
2024-01-18 14:39:54 +00:00
Ivan Kylchik aecf05c4ac [FIR] Use ConeKotlinType to represent vararg's element type
We are using `ConeKotlinType` instead of `FirTypeRef` to represent
that element type of vararg doesn't have any source. It has a type
that was inferred. If we try to specify a source, then we could
end up with the incorrect place for diagnostic.

#KT-59682 Fixed
2024-01-18 13:33:48 +00:00
Ivan Kylchik 86e6912447 [FIR2IR] Don't generate excess IR block from FirSingleExpressionBlock
This is needed to unify K1 and K2 behavior.

#KT-65064
#KT-63781 Fixed
2024-01-18 10:59:01 +00:00
Ivan Kylchik a56bebe44e [FIR2IR] Set correct endOffset for the IrBranch
We want to use end offset of branch's result as the end for the whole
branch, not just the end of its condition.

#KT-63779 Fixed
2024-01-18 10:59:01 +00:00
Kirill Rakhman 582dd1d3c0 [FIR] Only don't approximate nested captured arguments if they have recursive supertypes
This fixes a compiler crash
IllegalStateException: Captured type for incorporation shouldn't escape
from incorporation

The crash occurs when a captured type with status FOR_INCORPORATION
is two layers deep inside a captured type with status FROM_EXPRESSION.
We first check if approximation is required for the most outer captured
type in AbstractTypeApproximator.approximateCapturedType.
Then we encounter the second captured type with status FROM_EXPRESSION
in AbstractTypeApproximator.approximateParametrizedType.
At this point, we stop checking and miss the third captured type with
status FOR_INCORPORATION.

Unfortunately, we can't check recursively if nested captured types
need to be approximated because of types with recursive super types
(the original reason why the extra check was introduced).
That's why we restrict the second check to types with recursive
super types, effectively restoring the previous behavior for all other
types.

#KT-65050 Fixed
2024-01-18 09:22:15 +00:00
anzhela.sukhanova 7587f73846 [Test] KT-61937: add tests with context functions and naming clash
Update tests for ^KT-61937


Merge-request: KT-MR-13678
Merged-by: Anzhela Sukhanova <anzhela.sukhanova@jetbrains.com>
2024-01-18 08:27:31 +00:00
Kirill Rakhman cf494ada0b [FIR] Flatten ConeAttributeWithConeType when transforming
This is necessary to prevent exponential growth of the attribute
structure.
Since we usually care for the most inner value of a
ConeAttributeWithConeType like EnhancedTypeForWarningAttribute, this
shouldn't alter any behavior.
2024-01-18 08:27:10 +00:00
Kirill Rakhman b8ff04004a [FIR] Make EnhancedTypeForWarningAttribute a data class
(cherry picked from commit 76898ddb0f)
2024-01-18 08:27:10 +00:00
Kirill Rakhman 228ab60476 [FE 1.0] Fix new compilation warnings after #KT-63208
(cherry picked from commit dc0f4e6995)
2024-01-18 08:27:10 +00:00
Kirill Rakhman b7b1bd0a2c [FIR] Fix parameter order of NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS
(cherry picked from commit 8bfc4675c4)
2024-01-18 08:27:10 +00:00
Kirill Rakhman e91e9d8ca8 [FIR] Don't lose error level enhancements in warning-level-enhanced arguments
The error-level enhancement is kept as warning-level and a new
LanguageFeature is introduced to turn the warning into an error.

#KT-63208 Fixed
#KT-63209

(cherry picked from commit 371b1eb3d5)
2024-01-18 08:27:10 +00:00
Kirill Rakhman c39262195d [FIR] Let attributes opt-in to participating in ConeClassLikeTypeImpl structural equality
This is required for EnhancedTypeForWarningAttribute because scopes
should not be reused between cone types with different values of
this attribute.

#KT-63208

(cherry picked from commit 9189154cae)
2024-01-18 08:27:10 +00:00
Dmitriy Novozhilov 0741250b12 [FIR] Use proper FirProvider in the FirKLibSerializerExtension
3aa84906 changed native metadata serialization to use proper platform
  session, but it caused a new bug: FirKLibSerializerExtension uses
  FirProvider from the passed session to get a containing file of
  serialized declaration to put some extension into the metadata. And
  platform session doesn't contain information about any declarations
  except platform ones

So it's needed to use the proper FirProvider in it, which can be
  extracted from Fir2IrComponents. This provider contains providers from
  all sessions that are being compiled plus providers for top-level
  declarations generated by compiler plugins

^KT-65024 Fixed
2024-01-17 17:38:44 +00:00
Evgeniy.Zhelenskiy 70d1a2ea8c [FIR] Report package usages as a LHS
#KT-59972
2024-01-17 17:28:46 +00:00
Mikhail Glukhikh e999e289ee K2: split EXPLICIT_TYPE_ARGUMENTS_IN_PROPERTY_ACCESS to property/objects
Related to KT-64982
2024-01-17 16:51:48 +00:00
Mikhail Glukhikh 4fd73b06e2 FIR: render FirErrorResolvedQualifier properly 2024-01-17 16:51:48 +00:00
Mikhail Glukhikh 581cac3d45 K2: report EXPLICIT_TYPE_ARGUMENTS_... also on resolved qualifiers
#KT-64982 Fixed
2024-01-17 16:51:48 +00:00
Mikhail Glukhikh ee515ec5c4 K2: drop TODO in buildResolvedQualifierForClass
#KT-59649 Fixed
2024-01-17 16:51:48 +00:00
Mikhail Glukhikh caa850e470 FIR: render resolved qualifier type arguments in dumps 2024-01-17 16:51:48 +00:00
Mikhail Glukhikh 0a21669fb9 K2: reproduce KT-64982 2024-01-17 16:51:48 +00:00
Brian Norman 8f9bb75e60 [FIR] Allow identity equality to be used in contract implications
^KT-63256 Fixed
2024-01-17 14:59:59 +00:00
Roman Efremov ee1ee965a1 [FIR] Fix incorrect work of K2 expect-actual matcher when actual is Java
...field, which is fake override.
This was failing in Stdlib with `expect HashMap` + actual typealias to
`java.util.HashMap`.

^KT-63624 Fixed
2024-01-17 14:47:41 +00:00
Roman Efremov 3d2a37ee41 [Test] Write reproducer test for expect-actual matching to Java field
..., which comes from super class, which incorrectly works in K2.

^KT-63624
2024-01-17 14:47:41 +00:00
Nikita Bobko 0dc8629312 [FIR] Don't report MUST_BE_INITIALIZED on private open properites
^KT-59074 Fixed

This solution is not ideal. Ideally, the allopen compiler plugin
shouldn't report `private` properites as `open` KT-64980, but it will
unpredictably break other things.
2024-01-17 14:18:06 +00:00
Alexander Udalov 35caae355d Tests: minor, add box test for KT-31367/KT-61805
For some reason, codegen box test was not added in 082c337faa. The main
point of it now is to check that everything works correctly in the
IrFakeOverrideBuilder mode.
2024-01-17 12:27:36 +00:00
Pavel Kunyavskiy 15094eb03a [IrFakeOverrideBuilder] Support fake overrides for java static methods
^KT-64150
2024-01-17 11:40:12 +00:00
Dmitriy Dolovov 8f046d36e0 [FIR2IR] Implement support for Fir2IrLazyTypeAlias
Fir-based lazy type alias is required in IR text tests to check that
lazily loaded IR is equivalent to deserialized IR (module bodies)
and does not cause ABI compatibility issues in KLIB-based backends.

^KT-65033
2024-01-17 11:37:48 +00:00
Nikolay Lunyak 96db6eb94f [FIR] Support tailrec safe-calls
^KT-63529 Fixed
2024-01-17 11:31:26 +00:00
Nikolay Lunyak a4b7697714 [FIR] Reproduce KT-63529
^KT-63529
2024-01-17 11:31:26 +00:00
Alexander Kuznetsov b828365bb5 ReflectiveAccess: find the exact class the field is declared in
Affects IR Evaluator in IDEA.

The problem is happening because
`ReflectiveAccessLowering#fieldLocationAndReceiver` returns the class
 the field was called on, not the class the field was declared in.

 Then the class is used for obtaining a field by using reflection's
 `getDeclaredField` to make the field accessible after.
 But `getDeclaredField` doesn't work for field declared in a superclass,
 hence the error.

#KT-65012 fixed


Merge-request: KT-MR-13919
Merged-by: Alexander Kuznetsov <Aleksander.Kuznetsov@jetbrains.com>
2024-01-17 11:04:33 +00:00
Vladimir Sukharev 48df87f635 [K/N][Tests] Migrate two more cinterop tests
^KT-61259
2024-01-17 08:33:41 +00:00
Kirill Rakhman 0cebf2b39f [Tests] Remove irrelevant code from test 2024-01-17 08:20:06 +00:00
Kirill Rakhman 00491a78f1 [FIR] Implement canBeNull for captured type by checking its supertypes
#KT-62959
2024-01-17 08:20:06 +00:00
Kirill Rakhman 7b0c4e5bf6 [FIR] Adapt assertion after #KT-62959 2024-01-17 08:20:06 +00:00
Kirill Rakhman ec78747f2b [Tests] Add test for #KT-62956 2024-01-17 08:20:06 +00:00
Kirill Rakhman 9d91eb2510 [FIR] Fix inference based on recursive upper bound
#KT-59012 Fixed
2024-01-17 08:20:06 +00:00
Kirill Rakhman 251827c9aa [FIR] Don't approximate captured types
This fixes some type argument mismatch errors caused by a captured type
being approximated and then captured again.
Some places need to be adapted to work with captured types that
previously only worked with approximated types.

#KT-62959 Fixed
2024-01-17 08:20:05 +00:00
Kirill Rakhman b6d7f35ebf [FIR] Implement capturing of captured types
This is in preparation of a future commit, where captured types won't be
approximated anymore after completion.

Consider a case like

class Box<T>(val value: T)
interface Foo<T> { fun bar() }

fun test(x: Box<out Foo<*>>) {
    x.value.bar()
}

The type of `x.value` will be `CapturedType(out Foo<*>)`.
Note that capturing only applies to the top level, i.e., nested
projections are not captured.
That's why it becomes necessary to support capturing of captured types,
otherwise the star projection in `CapturedType(out Foo<*>)` is not
properly captured in the receiver of the call `x.value.bar()`.

#KT-62959
2024-01-17 08:20:04 +00:00
Mikhail Glukhikh 3c20a7b82a K1/K2: add test for KT-62959 2024-01-17 08:20:04 +00:00
Vladimir Sukharev 80cf88c9b9 [K/N][Tests] Move threadStates tests to common codegen/box folder
^KT-61259
2024-01-16 20:15:25 +00:00
Pavel Kunyavskiy 2bf5a58a30 [Fir2Ir] Don't use FirSyntheticProperty as the cache key
^KT-64871
2024-01-16 19:14:52 +00:00
Sergej Jaskiewicz 731eeb020d [JVM] Don't rely on presence of signatures in JVM IR serialization tests
This patch should not change any reasonable testing behavior. The only
case when the behavior could be changed is when two different functions
have the same IdSignature, which is a problem on its own.

Required for KT-64809
2024-01-16 18:25:58 +00:00
Anastasia.Nekrasova 7429dd4b94 K2: Support for inter-module interaction for @SubclassOptInRequired
The inter-module interaction was partially supported, but the
DiagnosticCompilerTestFE10TestdataTestGenerated and
LFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated were
failing. This is because the arguments of annotations were not fully
resolved in loadExperimentalitiesFromAnnotationTo function.

^KT-60262 Fixed
2024-01-16 16:53:04 +00:00
Nikolay Lunyak d66b38b7a9 [FIR] Introduce FirPropertySymbol.initializerSource 2024-01-16 14:18:09 +00:00
Nikolay Lunyak f08c167729 [FIR] Introduce FirValueParameterSymbol.defaultValueSource
It's easier to read the code if you don't
see generic `fir` access and thus don't
need to check all its usages to make sure
it's used correctly.
2024-01-16 14:18:09 +00:00
Nikolay Lunyak cb89695e21 [FIR] Review symbol.fir in FirVisibilityQualifierChecker
Also introduce `firForVisibilityChecker`.
This way it's easier to use compared to
defining overloads in `FirVisibilityChecker`
that accept symbols.

This change exists, because I wasn't able
to make myself sure that accessing fir here
is safe. We may come here after a typealias
expansion, after all.
2024-01-16 14:18:09 +00:00
Nikolay Lunyak 0b7e8c4708 [FIR] Add unwrapFakeOverridesOrDelegated for symbols 2024-01-16 14:18:09 +00:00
Nikolay Lunyak c7d535ff46 [FIR] Introduce ownTypeParameterSymbols 2024-01-16 14:18:09 +00:00
Nikolay Lunyak 3afed72027 [FIR] Remove symbol.fir from FirNativeObjCOverrideInitChecker 2024-01-16 14:18:09 +00:00