Commit Graph

983 Commits

Author SHA1 Message Date
Kirill Rakhman 2095f90e69 [FIR] Fix exception in Java scope caused by inherited member with implicit return type
It's caused by checking the return type of an inherited property.
toConeKotlinTypeProbablyFlexible() returns an error type when the
type ref is unresolved instead of throwing.
This "breaks" some override checks and in the added test, it leads
to an additional candidate being created for a synthetic property.
However, the candidate has applicability K2_SYNTHETIC_RESOLVED
and gets filtered out because the real property has a higher
applicability.

#KT-66392 Fixed
2024-03-15 12:01:55 +00:00
Mikhail Glukhikh 40c4e865c7 K2/Java/enhancement: implement wildcards replacement with flexible bounds
This commit in fact changes two very related places:
- first, it implements forgotten 'enhancedForWarnings' in K2 enhancement
- second, it repeats KT-48515 fix for K2 while enhancing wildcards

#KT-65594 Fixed
Related to KT-48515, KT-63746
2024-03-15 09:40:54 +00:00
Mikhail Glukhikh cd20f31810 K2: introduce JavaTypeParameterDefaultRepresentationWithDNN exp. feature
#KT-66447 Fixed
2024-03-14 22:39:03 +00:00
Dmitrii Gridin 675bf36049 [FIR] JavaTypeParameterStack: allow nullable return from get
It is not always possible to have the correct mapping,
at least on the Analysis API side

^KT-66530 Fixed
2024-03-14 18:05:15 +00:00
Nikolay Lunyak 7ecbaf7d1e [FIR] Calculate property setters visibilities for intersections properly
Basically, just calculate them the same
way it's done for other members.

`chooseIntersectionVisibilityForSymbolsOrNull`
is named like this to prevent a JVM clash.

^KT-66046 Fixed
2024-03-12 16:35:05 +00:00
Ilya Chernikov a823bfd600 K2 IC: refactor and optimize lookup tracking
- encapsulate semantic more into helpers
- allow lazy scopes iteration
- simplify reporting code in tower resolver
- fix some inconsistencies and wrong lookups
- remove redundant lookup recordings
- remove lookup scopes for non-star imports

The commit is a refactoring and doesn't change the behaviour of
neither IC nor CRI. Changes in the lookups are mostly due to the
previous obviously wrong lookups (see changed test data).
2024-03-12 11:38:07 +00:00
Kirill Rakhman f38dc3999c [FIR] Reformat SignatureEnhancement 2024-03-12 10:29:45 +00:00
Kirill Rakhman 0889770ccd [FIR] Fix scope of Java classes that inherit multiple properties with the same name
Use the receiver and context receiver types in addition to the property
name as cache keys for the synthetic property generation.
Also, fix logic that searches for accessor overrides by comparing
receiver and context receiver types.
Finally, let synthetic properties delegate their receiverParameter and
contextReceivers to their accessors.

#KT-65464 Fixed
#KT-66195
2024-03-12 10:29:45 +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
Kirill Rakhman 885ba11d97 [FIR] Defer computation of enhanced return type when overridden has implicit return type
#KT-66048
2024-03-12 10:29:45 +00:00
Kirill Rakhman 29a9d3cdd9 [FIR] Fix copy paste error in receiver enhancement 2024-03-12 10:29:44 +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
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
Mikhail Glukhikh 16c116908c Minor: fix typo 2024-03-11 13:38:05 +00:00
Dmitriy Novozhilov 624bea3ecf [FIR] Never create ConeSubstitutorByMap with empty substitution
Relates to KT-66323
2024-03-06 06:40:28 +00:00
Kirill Rakhman 172df04c9b [FIR] Fix raw type nullability computation
Consider the nullability of the type arguments, not of the type.
This fixes a false positive ARGUMENT_TYPE_MISMATCH.

#KT-66294 Fixed
2024-03-05 07:45:01 +00:00
Alexander Udalov 3bb2ea10b6 K2: add inline JVM target version checker
#KT-60777 Fixed
2024-03-04 22:25:36 +00:00
Kirill Rakhman 5bca945d05 [FIR] Fix nullability of types produced by ConeRawScopeSubstitutor
#KT-66067 Fixed
2024-03-01 14:08:39 +00:00
Dmitriy Novozhilov 6a94a3331f [FIR] Don't create synthetic property if getter and property came from the same class
Usually we create synthetic property in java class if there is a property
  from the base kotlin class and getter/setter with a corresponding name
  in the declared scope or one of supertype scopes. But there is a case,
  where the same supertype contains both property and getter:
```
// FILE: Base.kt
open class Base {
    open val b = "O"

    @JvmName("getBJava")
    fun getB() : String = "K"
}

// FILE: Derived.java
public class Derived extends Base {}
```

In this case we shouldn't create synthetic property, because `getB()`
  function is invisible for `Derived` class

^KT-66020 Fixed
2024-02-26 17:44:30 +00:00
Nikolay Lunyak 3b2bc598b5 [FIR] Reuse getNonSubsumedNonPhantomOverriddenSymbols
Just a small refactoring to avoid
duplicating comments.
2024-02-26 10:06:26 +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
Nikolay Lunyak 341a23d05c [FIR] Introduce containsMultipleNonSubsumed to intersection overrides
After this change the IO created for
`SimpleColoredComponent::setToolTipText`
will be `containsMultipleNonSubsumed == true`
while IOs created for classes in
`intersectionOverridesIntersection.kt`
will have this property set to `false`.

^KT-65972 Fixed
2024-02-21 20:24:16 +00:00
Nikolay Lunyak da6006b7d0 [FIR] Relax intersection overrides visibility requirements for Java
Allow multiple bases with default
implementations as long as there's a
non-abstract symbol from a class.

Our rules for Kotlin are stricter than
those in Java.
2024-02-21 20:24:13 +00:00
Alexander Udalov 5ca7ab9801 K2 JVM: implement Java modules-related checkers
All existing tests use custom test data for FIR because the diagnostic
text in FIR has to have a dot at the end. Also, the K2 checker doesn't
check usages in imports because there are no "import checkers" in K2
right now, this will need to be fixed later if necessary.

 #KT-60797 Fixed
2024-02-21 14:10:44 +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
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
Kirill Rakhman 889182629e [FIR] Simplify JavaOverridabilityRules.shouldApplyJavaChecker 2024-02-20 09:02:39 +00:00
vladislav.grechko d753a22fc6 [FIR] Handle expect declarations in JVM backend
1. Do not generate bytecode for expect declarations

2. Serialize @OptionalExpectation annotations into .kotlin_module file

^KT-62931: Fixed
2024-02-19 18:17:37 +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 eae72eac54 [FIR] Fix substitution of Java arrays enhanced for warning
... w.r.t the variance of their type arguments.
Because `Object[]` is represented as `Array<Any>..Array<out Any>?`,
when we substitute, we can't just take the upper bound because it
changes the variance of the type agument.
Instead, we construct a flexible type and use both bounds, like with
collections with flexible mutability.

#KT-65246 Fixed
2024-02-15 10:48:56 +00:00
Kirill Rakhman 35e9170af1 [FIR] Rename hidden methods around HiddenEverywhereBesideSuperCalls and add documentation. 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 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
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
Mikhail Glukhikh 8f906ca669 K2: refactor/simplify/comment processOverridesForFunctionsWithDifferentJvmName 2024-02-09 19:04:42 +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 c6f5e5f297 Add Kdoc to processOverridesForFunctionsWithDifferentJvmName 2024-02-09 19:04:42 +00:00
Mads Ager 79eee6de4f [FIR] Do not enhance nullability for annotation interface field types.
Java annotation interface fields are constant declarations that can
have any Java type and are not restricted in the same way that
method return types are for annotation interfaces.

#KT-65482 Fixed
2024-02-06 09:45:34 +00:00
Kirill Rakhman d937fb4350 [FIR] Fix exception in scopes caused by property and extension property with the same name in KJK hierarchy
#KT-65373 Fixed
2024-02-02 08:51:10 +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 3b164e560c JavaClassUseSiteMemberScope: add KDoc 2024-01-31 17:06:36 +00:00
Mikhail Glukhikh c0e0b4d32b K2/Java: cleanup code around processOverridesForFunctionsWithErasedValueParameter
#KT-64846 In Progress
2024-01-31 17:06:36 +00:00
Mikhail Glukhikh ac729e28da K2/Java: fix processing of built-in with value parameters to be erased in Java
In this commit we started to create and process a hidden copy
for a built-in functions, which value parameters are erased in Java,
in case we have an accidental Java override which value parameters
are not erased.

In this situation attempt to override such a Java override in Kotlin
again will lead to inaccessible functions
(see changes in containsAndOverload.fir.kt)

#KT-64846 In Progress
2024-01-31 17:06:35 +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
Mikhail Glukhikh ed246d372b K2: introduce platform-dependent filtering for non-JVM platforms
This commit fixes a false negative in testData/cli/metadata/getOrDefault
Related to KT-57268
2024-01-30 19:44:00 +00:00
Mikhail Glukhikh 672b5ba0d7 K2/Java: implement platform-dependent function filtering in JvmMappedScope
We drop Kotlin function 'remove' or 'getOrDefault' from JvmMappedScope,
if it has platform-dependent annotation, and the bound Java class scope
does not contain a function with the same signature.

#KT-57268 Fixed
2024-01-30 19:44:00 +00:00
Alexander Udalov 7d584e0eb4 K2/Java: add initial version of FirJvmPlatformDeclarationFilter
#KT-57268 In Progress
2024-01-30 19:44:00 +00:00
Simon Ogorodnik 53e89a9722 K2. Minor. Rename FirConstExpression to FirLiteralExpression
FirConstExpression is usually confused with "constant" calculations,
while in fact, it just denotes a simple literal expression
and `1 + 1` isn't represented by a FirConstExpression.

^KT-64314 Fixed
2024-01-25 23:05:15 +00:00