Commit Graph

894 Commits

Author SHA1 Message Date
Kirill Rakhman ed53d45307 [FIR] Add TODO for deprecation and fix of error-level nullable arguments of warning-level annotated Java type
#KT-56989
#KT-63208
2023-11-15 08:43:55 +00:00
Kirill Rakhman 2005446296 [FIR] Preserve enhanced mutability when nullability was enhanced for warning
#KT-56989
2023-11-15 08:43:55 +00:00
Kirill Rakhman a6fdeeb7df [FIR] Implement warnings for java nullability type mismatch
#KT-56989
2023-11-15 08:43:55 +00:00
Kirill Rakhman 1ecbc094ec [FIR] Save warning-level enhanced types to an attribute
#KT-56989
2023-11-15 08:43:55 +00:00
Ilya Chernikov 122f16fc18 K2 ignore return type on special java funs overrides
#KT-62197 fixed
2023-11-03 18:32:05 +01:00
Kirill Rakhman 2d7cadc0ab [FE, Java Resolve] Filter out canonical record constructors
This fixes a false positive overload resolution ambiguity in FIR
when invoking a record constructor when it also defines a canonical
constructor (compact or explicit).

#KT-62151 Fixed
2023-11-02 12:39:45 +00:00
Mikhail Glukhikh af58b30e5f K2 Java: fix 'value' annotation constructor parameter type to Array<out>
#KT-61100 Fixed
2023-10-31 22:13:10 +00:00
Kirill Rakhman ac203591e5 [FE, Java resolve] Support inheritors of sealed Java type without permits clause
This fixes a false negative NO_ELSE_IN_WHEN in K2 and incidentally
also fixes a false positive NO_ELSE_IN_WHEN in K1 since the fix is in
the common code.

#KT-62491 Fixed
2023-10-31 13:41:56 +00:00
Mikhail Glukhikh 290adda8fc Calculate empty array literal types in FIR2IR instead of deserializer
This commit handles situations when some annotation in deserialized code
has an empty array literal argument [] or even non-empty [something].
Before this commit, we tried to guess a type of this array by "resolving"
the relevant annotation class and looking into the corresponding
parameter. Sometimes it can work, but also it can provoke recursive
resolve e.g. when the annotation class is a nested class in the same scope.
In this commit we changed the behavior in the following way:
- first, for non-empty array literals in deserialized code we just
take the array type from the corresponding array literal element
- second, for empty array literals we no more try to "guess" anything.
Instead we approximate array type as Array<Any>, and later at FIR2IR
stage we use the corresponding parameter type instead. At FIR2IR stage,
everything is already resolved and problems with recursions are no more
possible.

#KT-62598 Fixed
2023-10-31 12:30:29 +00:00
Mikhail Glukhikh 19a95f2fb4 K2: swap heuristics in AnnotationLoader (related to KT-62598)
Before this commit, we first tried to guess a type of array literal
in deserialized annotation (it's a strange heuristics which can
lead to SOE and maybe not needed at all, see KT-62598, KT-62929),
and then, if unsuccessful, took the type from the first literal element,
if any. Since the second heuristic is much more clear, safe, and
understandable, in this commit they were swapped.

This commit does not fix KT-62598 in general case,
but decreases a set of cases when it can occur to
empty array literals only.
See the commented line at the end of the added test.
2023-10-31 12:30:29 +00:00
Marco Pennekamp 38ebe60e9f [FIR] Refactoring: Move set utility functions to setUtils.kt 2023-10-25 11:04:36 +00:00
Marco Pennekamp efe587691b [FIR] Type "top-level classifier names in package" as Name
- This is more consistent with "top-level callable names in package" and
  simplifies the set construction quite a bit, as we can avoid a lot of
  `asString` conversions.
2023-10-25 11:04:36 +00:00
Ivan Kochurkin 1827df82c4 Removed useless as casts from compiler code
It allows compiling code with K2 and enabled `-Werror`
2023-10-24 20:59:56 +00:00
Kirill Rakhman 56f53fbd0b [FIR] Make ClassId not null in enum call mapped from java 2023-10-24 13:27:02 +00:00
Ivan Kylchik ad0fad5fad [FIR] Drop isStatic field from FirJavaFieldBuilder
It is not used anywhere, and it looks like the proper way to set
`isStatic` is through the `status` field.
2023-10-20 16:33:21 +00:00
Ivan Kylchik a45bb8d92b [FIR] Find the correct FIR file in Java finder for file with JvmName
#KT-57802
2023-10-20 16:33:20 +00:00
Ivan Kylchik 8c7c44f9f5 [FIR] Fix evaluation of Java properties for Char and String types
#KT-57802
2023-10-20 16:33:20 +00:00
Ivan Kylchik 4d9b4dd27f [FIR] Use lazy evaluation for FIR Java properties
This is needed to avoid recursive evaluations when we have
multiple `const val` properties in a single class or file.

#KT-57802
2023-10-20 16:33:20 +00:00
Ivan Kylchik 7935b2bdb1 [FIR] Allow to evaluate top level const properties in Java world
#KT-57802
2023-10-20 16:33:20 +00:00
Ivan Kylchik 886ef1a4b4 [FIR] Support the simple case of java field interpretation
#KT-57802
2023-10-20 16:33:20 +00:00
Ivan Kylchik 2af73c2b13 [FIR] Add FirJavaElementFinder to session's components
This change allows us to use `IrInterpreter` to evaluate Kotlin's
const properties that were called from Java world

#KT-57802
2023-10-20 16:33:20 +00:00
Dmitrii Gridin d689c1a38f [FIR] FirJavaFacade: fix contract violation from annotations
`isJavaDeprecatedAnnotation` can't be used here because it triggers
the resolution of an annotation ClassId

^KT-62705 Fixed
2023-10-20 09:24:43 +00:00
Dmitriy Novozhilov 16ab36e167 [FIR] Don't create synthetic overriden property if base property is invisible
^KT-62393 Fixed
2023-10-17 12:46:27 +00:00
Dmitriy Novozhilov 61ec143b74 [FIR] Don't generate delegated members for java methods with default implementation
^KT-62334 Fixed
2023-10-17 12:46:27 +00:00
Ivan Kochurkin 498f2e534a [FIR] Don't enhance Int and String Java final static fields
It's effectively a breaking change (^KT-62558)

K2 assigns flexible type to all static fields (from Java) and, for example,
`String? becomes String unlike K1. It affects IR signature generating.
That's why signature dump is disabled for some tests.

^KT-57811 Fixed
^KT-61786 Fixed
2023-10-16 17:16:56 +00:00
Dmitrii Gridin bb40ce0bfc [FIR] FirSyntheticProperty: make constructor internal
Also, backingField can be moved into the body

^KT-61990
2023-10-16 15:07:11 +00:00
Alexander Udalov 2788dcb5ff K2: resolve remove(Int) clash in JavaOverrideChecker
In Kotlin subclasses of `MutableCollection<Int>`, the method
`remove(Int)` has its argument boxed, so that it wouldn't clash with the
method from `java.util.List`. So `JavaOverrideChecker` should understand
that a Java method `boolean remove(java.lang.Integer)` overrides it,
otherwise platform declaration clash was reported.

The code is adapted from `forceSingleValueParameterBoxing` in K1's
`methodSignatureMapping.kt`.

The test has been moved and adapted from diagnostic to codegen box
tests, to check correct backend execution + runtime.

 #KT-62316 Fixed
2023-10-16 11:26:58 +00:00
Dmitrii Gridin b2c8d7e777 [FIR] do not treat external ide annotations as real one
Such annotations are supposed to affect only diagnostic warnings

^KT-62310 Fixed
2023-10-13 12:16:12 +00:00
Mikhail Glukhikh 156097fe17 Restore KotlinCompilerVersion.IS_PRE_RELEASE
This commit is a slightly modified revert of 4f29c113.
IS_PRE_RELEASE allows to make LATEST_STABLE version behave as
experimental when this flag is set to true.
The general goal is to prepare fix of KT-62058; after this commit
one can do it by changing IS_PRE_RELEASE flag to true.
The fix of KT-62058 is planned to be done during bootstrapping.
This preparation and the future fix are parts of umbrella KT-61951.
2023-09-21 20:09:25 +00:00
Mikhail Glukhikh 8b8088720b Rename: DeserializedContainerAbiStability.IR_UNSTABLE -> UNSTABLE
Related to KT-62056
2023-09-21 11:14:09 +00:00
Mikhail Glukhikh a77b758efa LV 2.0: drop reporting FIR_COMPILED_CLASS and relevant stuff
#KT-62056 Fixed
Related to KT-59171, KT-61951
2023-09-21 11:14:09 +00:00
Kirill Rakhman 2e4d486131 [FIR] Use enhanced scope to guess array type in annotation loading
Otherwise, we return null for any java annotation because the
unenhanced scope doesn't contain any properties.

#KT-61856 Fixed
2023-09-20 08:02:37 +00:00
Nikolay Lunyak ec9cb8beb6 [FIR] Rename JvmNames -> JvmStandardClassIds
This is more consistent with the code of
the common compiler checkers.

It would be nice to refactor the contents
of this object further, but it's out
of scope of the current branch.

^KT-54596
2023-09-19 22:14:09 +00:00
Nikolay Lunyak 986f1624ec [FIR] Remove jvm-specific annotations from common compiler code
^KT-54596 Fixed
2023-09-19 22:14:09 +00:00
Dmitriy Novozhilov 97cf240450 [FIR] Reuse enhancement storage during creation of synthetic properies
^KT-61972 Fixed
2023-09-18 15:09:07 +00:00
Mikhail Glukhikh f8ada456e4 K2: rename FakeOverrideTypeCalculator to CallableCopyTypeCalculator
This commits performs a rename.
According to KT-61443 this calculator is applicable not only to
fake (substitution/intersection) overrides.
2023-09-15 15:21:10 +00:00
Kirill Rakhman b9b99366e7 [FIR] Use resolvedType instead of coneTypeOrNull in java.deserialization
#KT-61367
2023-09-14 10:03:02 +00:00
Nikolay Lunyak aacfc31c90 [FIR] Resolve the continuation type inside createSuspendView()
Normally such types are resolved during enhancement,
but creating the suspend view happens before
enhancement, so the type may have not been resolved.

^KT-59915 Fixed
2023-09-13 11:18:06 +00:00
Kirill Rakhman 2bc25d4f6e [FIR] Properly check for visibility in FirTypeIntersectionScopeContext
This fixes a false positive OVERRIDING_FINAL_MEMBER caused by a
package-private member in a different package being added to the
list of overridden symbols. However, in Java, package-private members
from different packages are effectively like private members in that
they cannot be overridden.

#KT-61696 Fixed
2023-09-12 10:46:46 +00:00
Kirill Rakhman 16ae83bde0 [FIR] Fix Java sealed class inheritors
This fixes NO_ELSE_IN_WHEN diagnostics when using java sealed
classes in an exhaustive when.

#KT-58216 Fixed
2023-09-11 07:37:37 +00:00
Marco Pennekamp f64cc184f4 [FIR] Refactoring: Introduce base implementations for delegating scopes
- The implementations of some FIR scopes contain a significant amount of
  delegation to some original scope. This pollutes the implementation of
  such scopes and makes them harder to read.
  `FirDelegatingContainingNamesAwareScope` and `FirDelegatingTypeScope`
  can be used as base classes which delegate by default.
2023-09-08 11:13:28 +00:00
Kirill Rakhman 9a2307ad44 [FIR] Fix expression types in java annotations
#KT-61518 Fixed
2023-09-08 07:40:30 +00:00
Mikhail Glukhikh 4d9457862f K2: add sourceElement for binary Java classes
#KT-60555 Fixed
2023-09-06 13:14:16 +00:00
Alexander Udalov fec2d063c1 K2: report PRE_RELEASE_CLASS on JVM
Note that 3 tests are still muted, but for another reason: for FIR
versions of the tests, we need to compile the "pre-release library" with
the next language version which is 2.1. But since currently
LanguageVersion.LATEST_STABLE is 1.9, the compiler refuses to read
metadata of version 2.1, regardless of its own language version. Which
is correct, but it leads to irrelevant errors in the test output -- the
ones about the incompatible metadata version, NOT about the
prereleaseness.

These 3 tests can be unmuted once the default language version is
switched to 2.0.

 #KT-60780 Fixed
2023-09-06 08:05:34 +00:00
Alexander Udalov 8738ffb84f K2: suppress exception when reading unsupported metadata
Before the change, the compiler threw exception in the unmuted tests,
because it tried to load metadata even though it had an unsupported
version. Use the same approach as in K1 (see
DeserializedDescriptorResolver).

Now the tests are unmuted, but note that test data differs from K1. K1
does not report errors related to the class `a.A` because it loads this
class as a _Java class_, so calling its constructor and methods somehow
works. This behavior is questionable since the compiler surely knows
that it is a Kotlin class, but with an unsupported metadata version.
Trying to interpret it as a Java class may lead to subtle problems. So
it's safer for now to avoid loading Kotlin classes with unsupported
metadata versions in K2.

 #KT-60795 Fixed
2023-09-06 08:05:34 +00:00
Alexander Udalov 8f720ad24b K2: support -Xskip-metadata-version-check
#KT-60795
2023-09-06 08:05:34 +00:00
Alexander Udalov 7d60b5df43 K2: report INCOMPATIBLE_CLASS in JVM
#KT-60795
2023-09-06 08:05:34 +00:00
Alexander Udalov db8fb30343 K2: minor cleanup in JvmClassFileBasedSymbolProvider 2023-09-06 08:05:34 +00:00
Dmitriy Novozhilov fa4c6d55c1 [FIR] Store mapped jvm declarations in session component, share it between MPP modules
^KT-61640 Fixed

This change doesn't affect any tests in the moment, because it's part of
  bigger refactoring of proper storing IR declarations during FIR2IR
  conversion (KT-61637)

Without this change, there is one test break in branch for KT-61637:
- FirPsiBlackBoxCodegenTestGenerated.Multiplatform.K2.testJavaMethodWithTypeParameter
2023-09-05 14:43:43 +00:00
Dmitriy Novozhilov bb36beb364 [FIR] Share enhancedSymbolStorage between common and platform sessions
This is needed for two reasons:
1. common and platform modules are analyzed in the same setup with same
   dependencies and configurations, so the results of the enhancement for
   any function will be completely identical. So by sharing enhanced
   symbol storage, we avoid recomputation enhanced functions and improve
   performance
2. There is a goal to have some unique key for IR declarations in FIR2IR.
   For regular declarations, the key is just Fir symbol, and for fake-overrides
   it is a pair of original symbol and fake override owners lookup tag.
   But for enhanced functions the symbol is not unique, because we create
   different symbols for the same enhanced function for different modules.
   So this change fixes this problem

^KT-60397 Fixed

This change doesn't affect any tests in the moment, because it's part of
  bigger refactoring of proper storing IR declarations during FIR2IR
  conversion (KT-61637)

Without this change, there are some test breaks in branch for KT-61637:
- FirPsiBlackBoxCodegenTestGenerated.Multiplatform.testStarImportOfExpectEnumWithActualTypeAlias
- FirPsiBlackBoxCodegenTestGenerated.Multiplatform.K2.DefaultArguments.testNestedEnumEntryValue
- FirPsiBlackBoxCodegenTestGenerated.Multiplatform.K2.Basic.testEnumEntryNameCall
2023-09-05 14:43:43 +00:00