Commit Graph

1268 Commits

Author SHA1 Message Date
Alexander Udalov e4e1bcefbd JVM: remove tests on JVM target 1.6 2023-05-19 13:23:59 +00:00
Nikolay Lunyak 200fb1e5ce [FIR] KT-54874: Ensure this code is red
^KT-54874 Fixed
2023-05-15 14:44:10 +00:00
Denis.Zharkov c3ac2e44a0 Adjust test data for enabling ProhibitUsingNullableTypeParameterAgainstNotNullAnnotated
^KT-55388 Fixed
2023-05-15 10:43:19 +00:00
Simon Ogorodnik 82611ad124 FIR. BI: Fix stub type leakage in builder inference
Previously, updateTypeInBuilderInference was calling
updateTypeFromSmartcast to actually perform type update in
implicit receiver after stub types was inferred
Such action results in creation of following FIR:

FirSmartCastExpression(
    original=FQAE(FirImplicitThisReference, typeRef=R|Inv<Stub>|)
    typeRef=R|Inv<String>|
)

in receiver position during completion of calls

However, it wasn't the case in general situation due to
action of FirStubTypeTransformer, which, in turn visits and updates
type ref inside original expression, but only if there was at
least one call (that was completed) using that implicit receiver
As after such type update updateTypeFromSmartcast function does
nothing

Yet in situation, when there was only partially resolved calls
referencing that implicit receiver we actually create smart-cast
expression and don't update type

The change just removes usage of updateTypeFromSmartcast and
replaces is with direct type update
We still mutate state of implicit receiver, potentially
improperly, it should be addressed in future

^KT-54708
^KT-58365 Fixed
2023-05-04 12:46:28 +00:00
Kirill Rakhman 8afc8950e6 [FIR] Report illegal in/out modifier on star projection
#KT-55668 Fixed
2023-05-02 15:16:07 +00:00
Mikhail Glukhikh 94c94d0605 K1: add a language feature to negate new errors from DiagnosticReporterByTrackingStrategy
Related to KT-55055, KT-55056, KT-55079, KT-57854
2023-05-01 11:47:01 +00:00
Dmitriy Novozhilov 71d6103122 [FIR] Report ASSIGNMENT_TYPE_MISMATCH on properties with numeric types
^KT-46047
^KT-56951 Fixed
2023-04-30 16:12:54 +00:00
Denis.Zharkov 555d8eeb25 K2: Fix false-positive DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE
For explanation, see nestedPartiallyResolvedCallsSimple.k

The problem was caused by "select" variable is being leaked to the
inference session of delegate while it should not happen because
it doesn't belong to the common system of `KotlinVal { ..` call,
as we complete it with fixing `E` variable during completion
for `A(select(null, fun(): Int { return 1 }))`.

The root of the problem is that we were adding all the partial
nested calls to the session, while in fact we only need there
the top-level one.

^KT-57543 Fixed
2023-04-28 16:20:06 +02:00
Alexander Udalov 3120a35a88 JvmDefault: remove most tests on @JvmDefault
The tests are removed because JvmDefault is going to be deprecated with
error in KT-54746 and removed later in KT-57696.

Many of the removed tests already had existing counterparts with the new
modes `all` and `all-compatibility`. In this change, I've added such
tests where they were missing, and removed tests which were testing
behavior specific to the JvmDefault annotation, such as some
diagnostics.

 #KT-54746
2023-04-25 14:33:00 +00:00
Kirill Rakhman 8b47a4fa48 [FIR] Fix resolution of objects in presence of low-priority candidates
For CallKind.VariableAccess, the condition when to *skip* resolution of
objects was previously collector.isSuccess. This wasn't strict enough
because collector.isSuccess could be true when the best found candidate
has an applicability like RESOLVED_WITH_LOW_PRIORITY (e.g. from dynamic
scope or annotated with @LowPriorityInOverloadResolution). In these
cases, we do want to resolve objects. To fix this, the condition is
changed to collector.shouldStopResolve which is stricter.

#KT-57960 Fixed
2023-04-20 08:04:07 +00:00
Dmitrii Gridin 6170d83301 [FIR] update reversed testData
^KT-56543
2023-04-19 20:12:41 +00:00
Dmitrii Gridin 1c5aa6c45b [FIR] add reversed testData to update it in the next commit
^KT-56543
2023-04-19 20:12:41 +00:00
Dmitrii Gridin 72def186a3 [LL FIR] rework transformers, so transformers resolve only a specific set of declarations
The change is needed for the parallel resolution (^KT-55750), so we can resolve the declaration
under a lock that is specific to this declaration.
Previously, if LL FIR was resolving some FirClass, LL FIR  resolved all its children too, and it had no control over what parts of the FIR tree were modified.
The same applied to the designation path, sometimes the classes on the designation path
might be unexpectedly (and without lock) modified.

This commit introduces LLFirResolveTarget, which specifies which exact declarations should be resolved during the lazy resolution of the declaration.
All elements outside the declarations specified for resolve in LLFirResolveTarget, should not be modified.

The logic of lazy transformers is the following:
- Go to target declaration collecting all scopes from the file and containing classes
- Resolve only declarations that are specified by the LLFirResolveTarget, performing the resolve under a separate lock for each declaration

^KT-56543
^KT-57619 Fixed
2023-04-19 20:12:38 +00:00
Nikolay Lunyak c9d7b47900 [FIR] Report == for identity-less
Since we forbid overriding `equals` for
value classes, and value classes may only
implement interfaces, we know everything
about their `equals`, hence we can
guarantee if it always returns `false`
for different value classes.
2023-04-19 16:05:19 +00:00
Nikolay Lunyak 8d04ab3142 [FIR] Ignore nullability in the definition of "identity-less"
The definition of a "builtin" already
ignores nullability.

`Int? === String?` must trigger a
diagnostic by design.
2023-04-19 16:05:19 +00:00
Nikolay Lunyak 5ecedcbb16 [FIR] Ensure K2 doesn't report Int? === String? 2023-04-19 16:05:18 +00:00
Mikhail Glukhikh 9374202ebc FirCallResolve: disable property resolve optimization in builder inference
#KT-57889 Fixed
2023-04-18 17:05:01 +00:00
Mikhail Glukhikh f9a7a7fda2 K2: reproduce KT-57889 2023-04-18 17:05:00 +00:00
Dmitriy Novozhilov bde4d003be [FIR] Extract contracts from original functions of fake overrides
^KT-57911 Fixed
2023-04-18 13:31:29 +00:00
Dmitriy Novozhilov f8dc8057f0 [FIR] Prohibit referencing type parameters in contracts ...
...if they are not reified or not belong to owner declaration of the contract

KT-57911
2023-04-18 13:31:28 +00:00
Dmitriy Novozhilov 5a92eb2c67 [FIR] Properly track problems in contract description during effect extraction 2023-04-18 13:31:28 +00:00
Mikhail Glukhikh 50f82c9094 FirBuilderInferenceSession: fix calculation of effectivelyEmptyCommonSystem
#KT-57873 Fixed
2023-04-18 09:23:20 +00:00
Mikhail Glukhikh 7bd5491498 K2: reproduce KT-57873 2023-04-18 09:23:20 +00:00
Ilya Gorbunov b8da3e69ce KT-55268 Make k.c.Volatile stable 2023-04-08 15:07:56 +00:00
Kirill Rakhman 085df96afe [FIR] Make Volatile diagnostics applicable to kotlin.concurrent.Volatile
#KT-55628 Fixed
2023-04-04 10:36:39 +00:00
Kirill Rakhman 91adb88eff [K1] Make Volatile diagnostics applicable to kotlin.concurrent.Volatile
#KT-55628
2023-04-04 10:36:39 +00:00
Mikhail Glukhikh bd27ec840c K1: report swallowed diagnostic about receiver type mismatch
#KT-55056 Fixed
2023-04-03 16:35:55 +00:00
Dmitrii Gridin badd09e4fd [FIR] TowerLevels: add missing lazy resolve
^KT-56543
2023-04-01 06:39:46 +00:00
Nikolay Lunyak f0720c1d12 [FIR] Fix K2 behavior according to RULES1
The compiler should only report diagnostics for
comparisons over builtins and identity-less types,
other incompatibilities should be reported
via inspections.

It's ok that in `equalityChecksOnIntegerTypes`
instead of `EQUALITY_NOT_APPLICABLE_WARNING` we get
`EQUALITY_NOT_APPLICABLE`, because
`ProperEqualityChecksInBuilderInferenceCalls`
is already active by default.

This change also replaces the notion of a representative superclass
with the least upper bound.
This makes complex types like
intersection/flexible transparent to
RULES1-based compatibility checks.
One way to look at it is to think
that this is an automatic way of handling
type parameters: automatic picking of
"interesting" bounds, and checking them against one another.

Note that `TypeIntersector.intersectTypes`
for `Int` and `T` where `T` is a type parameter
may return both `{Int & T}` or `null`
depending on `T`-s bounds. At the same time,
for type parameters `T` and `K` it will
always return `{T & K}`.

`ConeTypeIntersector.intersectTypes`, on the
other hand, will always return `{Int & T}`
irrespectively of the bounds. Meaning, the two
intersectors differ in corner cases.

`lowerBoundIfFlexible` call in `isLiterallyTypeParameter` is backed by
the `equalityOfFlexibleTypeParameters` test.

^KT-35134 #fixed-in-k2
^KT-22499 #fixed-in-k2
^KT-46383 #fixed-in-k2
2023-03-31 15:01:50 +00:00
Nikolay Lunyak 12b11bd034 [FIR] KT-57568: Make K2 treat signed ints as more specific than unsigned
This is the way it works in K1.
See `OverloadingConflictResolver.kt:345`.

^KT-57568 Fixed

Merge-request: KT-MR-9395
Merged-by: Nikolay Lunyak <Nikolay.Lunyak@jetbrains.com>
2023-03-30 06:28:16 +00:00
Mikhail Glukhikh 930237b60e K1: report swallowed diagnostic about upper bound violation
#KT-55055 Fixed
2023-03-24 14:27:03 +00:00
Dmitrii Gridin 9a4a3d1f49 [LL FIR] introduce test with reversed resolve order
^KT-56543

Merge-request: KT-MR-9299
Merged-by: Dmitrii Gridin <dmitry.gridin@jetbrains.com>
2023-03-22 17:34:07 +00:00
Ivan Kochurkin e49bb1fe37 [FIR] Support of REDECLARATION for local val/var, ^KT-54405 Fixed 2023-03-21 20:24:57 +00:00
Mikhail Glukhikh 2fb79bf0b1 K1: don't report InferredIntoDeclaredUpperBound on non-physical element
#KT-56169 Fixed
2023-03-17 12:08:37 +00:00
Mikhail Glukhikh 980ab41ef1 FE: split one more test "buildList type argument is inferred into upper bound"
Related to KT-48445, KT-56169
2023-03-17 12:08:37 +00:00
Mikhail Glukhikh 97bec59bc9 K1: add forgotten INFERRED_INTO_DECLARED_UPPER_BOUNDS for incorporation case
#KT-56169 Fixed
2023-03-17 12:08:36 +00:00
Mikhail Glukhikh ba2d896c01 FE: split test "buildList type argument is inferred into upper bound"
Related to KT-50520, KT-56169
2023-03-17 12:08:35 +00:00
Nikolay Lunyak 967ddb8bb0 [FIR] KT-57211: Generate FirArrayOfCall for unsigned types
^KT-57211 Fixed

Merge-request: KT-MR-9216
Merged-by: Nikolay Lunyak <Nikolay.Lunyak@jetbrains.com>
2023-03-15 17:05:09 +00:00
Mikhail Glukhikh b64cb67370 K2: support ForbidInferringTypeVariablesIntoEmptyIntersection on/off 2023-03-11 10:15:23 +00:00
Mikhail Glukhikh f7544aff62 Delay ForbidInferringTypeVariablesIntoEmptyIntersection to 2.*
Note: here we set sinceVersion = null for this feature.
However, we plan in 1.9.* - 2.0 time frame to solve KT-56377
and to enable this feature in 2.0, the latest in 2.1.
2023-03-11 10:15:22 +00:00
Nikolay Lunyak c156dfe855 [FIR] KT-56877: Allow checking types of containing classes in contracts 2023-03-09 09:43:03 +00:00
Nikolay Lunyak c7a71fec17 [FIR] KT-56877: Allow referencing implicit receivers in class contracts 2023-03-09 09:43:02 +00:00
Kirill Rakhman f946ddeb40 [FIR] Implement checks for contract not allowed
^KT-55423 Fixed
2023-03-09 08:32:02 +00:00
Kirill Rakhman 3b9724d20e [FIR] Desugar increment/decrement in body resolve phase
The expression needs to be resolved first to determine if there is a
receiver that needs to be extracted to a temporary variable. Also, the
special case for prefix increment/decrement on local variable without
delegates requires resolution to check if the variable is local.

^KT-56771 Fixed
^KT-56659 Fixed
2023-03-02 10:19:57 +00:00
Kirill Rakhman 5ecf9cce25 [FIR] Don't resolve already resolved qualified access
^KT-30507 Fixed
2023-03-02 10:19:53 +00:00
Kirill Rakhman fbc0796ed2 [FIR] Accept opt-in annotations on primary ctor params of properties
For backward compatibility with K1.

KT-56177
2023-02-28 10:19:20 +00:00
Kirill Rakhman 2139914061 [FIR] Add diagnostic when annotation argument is resolved ambiguously
Annotation arguments that are resolved in COMPILER_REQUIRED_ANNOTATIONS
phase are resolved again in ANNOTATION_ARGUMENTS phase. If they resolve
to a different symbol, report an error.

KT-56177
2023-02-28 10:19:19 +00:00
Kirill Rakhman 9dda5e4fcd [Test] Remove redundant FIR_DISABLE_LAZY_RESOLVE_CHECKS directives
KT-56177
2023-02-28 10:19:18 +00:00
Kirill Rakhman eee66ab43f [FIR] Remove duplicate annotations from primary ctor params/properties
If an annotation doesn't specify an explicit use-site target,
previously it was added to both, the primary constructor value parameter
and the property in the FIR. Then, in FIR2IR, only the "correct" one was
added to the IR. Move up the deduplication logic into the frontend.

^KT-56177 Fixed
2023-02-28 10:19:17 +00:00
Denis.Zharkov 2b3f34cc52 K2: Fix false-positive type equality for different captured types
This is mostly a revert of 2f61a2f56f
There, we erroneously assumed that we may take captured types as equal
if they are based on the same-typed projections.

Each instance of capturing defines its own captured type,
that should not be equal to any other type captured in other place.

Initial motivation was brought by FP Ultimate, where a piece of code
from the new test was found that started working differently after
recent changes.

The most obvious consequence is the change in addAllProjection.fir.kt:
one cannot use an instance as an argument when expected type
is captured type based on the same instance.

Otherwise, it would lead to CCE if we allowed to put arbitrary charsequences
to the list that initially was a MutableList<String>

All other test data changes (but addAllProjection.fir.kt and differentCapturedTypes.kt)
are irrelevant and will be fixed in the subsequent commits
2023-02-15 08:13:52 +00:00