Commit Graph

1436 Commits

Author SHA1 Message Date
Kirill Rakhman 69f2e8826a FIR: fix a bunch of issues after DiagnosticsReporter refactoring related to reporting diagnostic on null source 2023-01-11 08:30:36 +00:00
pyos 803abfeba8 FIR: rewrite lambda return type inference
* `return` should only be added to the last statement if the return
   type is not Unit

 * If there is a `return` without an argument, then the expected return
   type is Unit and the last expression is not a return argument (unless
   it's an incomplete call, in which case it is inferred to return Unit;
   this behavior is questionable, but inherited from K1)

 * There should be a constraint on return arguments even if the expected
   type is Unit, otherwise errors will be missed

 * When the expected type is known, using the call completion results
   writer is pointless (and probably subtly wrong).

^KT-54742 Fixed
2023-01-10 15:40:45 +02:00
Pavel Mikhailovskii 906c161068 KT-52791 Make it possible to pass multiple context receivers to a class 2022-12-28 11:21:03 +00:00
Steven Schäfer 6af616d3c3 FIR: make declarations marked with 'override' implicitly open
#KT-52236 Fixed
2022-12-14 21:46:41 +00:00
Denis.Zharkov cd0d6d2773 Adjust test data for postponing ProhibitUsingNullableTypeParameterAgainstNotNullAnnotated
^KT-55357 Related
^KT-36770 Related
2022-12-12 11:39:04 +00:00
Dmitriy Novozhilov 3cffb33ab7 [FE] Drop ApproximateIntegerLiteralTypesInReceiverPosition language feature
This feature is not needed because it is unconditionally disabled for K1
  (because of not fully correct implementation) and unconditionally enabled
  in K2 (K2 does not support old behavior)

^KT-38895
2022-12-09 15:10:02 +00:00
Dmitriy Novozhilov a86bc425e5 [FIR2IR] Lookup for nested classes in scope in Fir2IrLazyClass
^KT-55269 Fixed
2022-12-09 12:02:07 +00:00
Dmitriy Novozhilov 866150a2e0 [FIR2IR] Add static functions to Fir2IrLazyClass.declarations
^KT-55269
2022-12-09 12:02:07 +00:00
Dmitriy Novozhilov 5d6cb2b691 [Test] Use IrPluginContext for searching declarations for DUMP_EXTERNAL_CLASS check 2022-12-09 12:02:07 +00:00
Dmitriy Novozhilov e7f6482857 [Test] Use DUMP_EXTERNAL_CLASS instead of invalid DUMP_DEPENDENCIES directive in ir text tests 2022-12-09 12:02:06 +00:00
pyos f485413cfd FIR DFA: x !is T? => x != null
^KT-22996 tag fixed-in-k2
2022-12-08 10:19:27 +00:00
pyos 0d46dfc1ba FIR: fix substitution of type arguments in SAM type aliases
^KT-54730 Fixed
2022-12-07 22:09:20 +00:00
Steven Schäfer 21fef70367 Standardize context receiver parameter names
Previously, FIR used `_context_receiver_n` while FE10 used `<this>` for
all context receiver parameters. This commit changes the code in FE10
to follow the convention from FIR.
2022-12-03 00:11:38 +01:00
Steven Schäfer a7ba081d22 FIR: Fix interface delegation ABI
- Unifies the name of the `$$delegate_<n>` field between K1 and K2.
- Make the `$$delegate_<n>` field private
2022-12-02 21:54:18 +00:00
Sergej Jaskiewicz aa1b18b0c8 [IR] Prevent infinite recursion when rendering bound symbol references
Refactor the renderer, make BoundSymbolReferenceRenderer a static class
to prevent calling RenderIrElementVisitor's methods from it to avoid
infinite recursion in the future.

^KT-52677 Fixed
2022-11-28 16:43:53 +00:00
Ivan Kochurkin 8883de3f00 [FIR] Don't resolve Enum.declaringClass and Enum.getDeclaringClass
^KT-53946 Fixed
2022-11-23 18:29:29 +00:00
pyos ae31275f73 FIR DFA: unwrap transparent expressions in more places 2022-11-22 15:44:35 +00:00
pyos 7c8e9ac316 FIR DFA: remove RealVariableAndType 2022-11-22 15:44:24 +00:00
Mikhail Glukhikh 1aae9d6456 FIR2IR: generate this reference to non-source class properly
#KT-53983 Fixed
2022-11-22 10:01:16 +00:00
Ivan Kylchik e3f8aa255a Fix StackOverflow in interpreter for case with recursive enum init
#KT-54884 Fixed
2022-11-21 20:03:18 +00:00
Mikhail Glukhikh 1d76bce3dd K2: fix outerClassSymbol behavior for local classes #KT-55018 Fixed 2022-11-21 09:23:54 +00:00
Dmitrii Gridin 33281770c7 [FIR IR] support FirReceiverParameter
^KT-54417
2022-11-17 09:50:11 +00:00
Ilya Chernikov 44cce3ad52 FIR JS: mute remaining tests for now 2022-11-12 16:28:23 +01:00
Ilya Chernikov 5b3816cce5 Test infra: refactor IGNORE_BACKEND directive
treat it as a general one, introduce *_K1 and *_K2 variants for
more specific ignoring
2022-11-12 16:28:23 +01:00
Mikhail Glukhikh 7205a90d9d FIR2IR: drop redundant visibility check in fake override generator 2022-11-11 13:30:37 +00:00
Alexander Korepanov d5e9e87538 [JS BE] Drop JS scripting support
JS scripting uses the old IR to JS transformer.
 The new IR to JS transformer can not be used for
 JS scripting out of the box. Patching the new transformer for
 JS scripting is potentially dangerous and requires a lot of effort.
 Dropping JS scripting and the old IR to JS transformer allows to
 refactor and simplify JS BE codebase.
2022-11-04 14:15:15 +00:00
Simon Ogorodnik 2cf8f75a90 KT-53255. Fix StackOverflow during IR verification from K2
In FIR we desugar when with multiple conditions leading to same block
as tree of OR expressions

Given
```
when(some) {
  "a", "b", "c" -> {}
  else -> {}
}
```

actually desugared into
```
when(val <subj> = some) {
  <subj> == "a" || <subj> == "b" || <subj> == "c" -> {}
  else -> {}
}
```

There is a multiple ways of how we can organize such expressions in FIR
Previously it was just nesting-chain of OR expressions

While the most efficient way in terms of required stack depth is
a balanced tree

KT-53255
2022-10-26 17:44:46 +00:00
Alexander Udalov b42a7be0de Psi2ir: keep nullability when substituting function type for SAM type
After we added "careful approximation of contravariant projections" in
584b70719e, some SAM conversions started to require an additional
implicit cast of the functional value before it is converted to the SAM
interface. The target type of this implicit cast was computed
incorrectly because it didn't contain nullability of the SAM type. This
could lead to a situation where a nullable value was incorrectly cast to
a non-null type, which caused a missing null check and NPE at runtime.

For example, let's consider the test `kt54600.kt`. SAM conversion
happens in the constructor call `J(filter)`. Before 584b70719e, the IR
for that argument was (irrelevant things are omitted for simplicity):

  TYPE_OP SAM_CONVERSION type=Condition<String!>!
    GET_VAR filter type=Function1<String, Boolean>?

After 584b70719e, the IR became:

  TYPE_OP SAM_CONVERSION type=Condition<Any?>!
    TYPE_OP IMPLICIT_CAST type=Function1<Any?, Boolean>
      GET_VAR filter type=Function1<String, Boolean>?

Note the two changes:
* The resulting SAM type changed from `Condition<String!>` to
  `Condition<Any?>`. This is exactly the point of the "careful
  approximation" change, because just erasing the "in" projection from
  the parameter type is incorrect, see the explanation for that change.
* The value is now implicitly cast to the _non-null_ function type
  before it is SAM-converted. The presence of the cast is fine, but the
  fact that it's to a non-null type is an oversight.

The target type for this cast is computed at
`KotlinType.getSubstitutedFunctionTypeForSamType` in psi2ir. Now it
extracts the nullability from the SAM type and retains it in the
resulting function type.

After this change, the IR for the argument becomes:

  TYPE_OP SAM_CONVERSION type=Condition<Any?>!
    TYPE_OP IMPLICIT_CAST type=Function1<Any?, Boolean>!
      GET_VAR filter type=Function1<String, Boolean>?

Note that the target type is now flexible, as the resulting SAM type.
Another option would be to make it nullable, as the type of the
functional value, but there doesn't seem to be any difference.

 #KT-54600 Fixed
2022-10-25 11:20:23 +00:00
Mikhail Glukhikh c0789b5207 PSI/FIR->IR translators: return to 1.7.10 behavior for field references
In 1.7.20 we used the nearest Java-based receiver for such field
references in backend. Now we are using use-site receiver again,
it can lead to accidental usage of derived class property backing field.

This is effectively a revert of KT-49507 fix, see commits:
- fa914f20
- b0a6508d

#KT-54393 Fixed
#KT-49507 Planned
#KT-52338 Planned
2022-10-25 08:36:01 +00:00
Ivan Kylchik 1fc2575052 Use correct toString method in IrCompileTimeChecker for analysis 2022-10-24 13:14:16 +00:00
Steven Schäfer 760f89efd3 FIR: Fix operator and infix flags for FIR builtins 2022-10-05 12:14:05 +00:00
Dmitriy Novozhilov 6623456d2a [FIR] Properly support @JvmRecord
^KT-53867 Fixed
2022-10-03 15:48:17 +03:00
Dmitriy Novozhilov c0ad67c4f9 [FIR] Generate java declarations for record components of java records
^KT-53964 Fixed
2022-10-03 15:48:17 +03:00
Mikhail Glukhikh de43877161 K2: add more tests about false overrides
Related to KT-53197
2022-09-29 08:34:13 +00:00
Mikhail Glukhikh bcd7a531b9 K2: filter invisible overridden in status resolver & FIR2IR
Related to KT-53197
2022-09-29 08:34:13 +00:00
pyos 3a5d75fd22 K2: introduce platform-specific visibility checks for overrides + tests
Related to KT-53197
2022-09-29 08:34:13 +00:00
Nikita Nazarov bd742bb95c Account for context class receivers when creating the ExpressionReceiver
^KT-54084 Fixed
2022-09-28 18:59:56 +04:00
Ivan Kochurkin 6c4dafc23c Disable IgnoreNullabilityForErasedValueParameters for indefinite time, ^KT-53751 Fixed 2022-09-13 16:45:06 +00:00
Pavel Mikhailovskii fe5a6fd511 Disallow non-local break/continue in crossinline lambdas 2022-09-12 13:26:19 +00:00
Dmitriy Novozhilov cb03ef89c5 [Test] Unmute passing test 2022-09-07 07:57:38 +00:00
Ilya Gorbunov 6aff3c6d07 Update misc test data after introducing rangeUntil member #KT-52933 2022-08-24 22:22:54 +00:00
Ilya Gorbunov baf7cbb3ac Add 'until' function for unsigned arguments to interpreter test helpers #KT-52933
Required to evaluate rangeUntil members of unsigned types.
2022-08-24 22:22:54 +00:00
Mikhail Glukhikh 8a4105e542 IR: fix origin of default getter of Enum.entries synthetic property 2022-08-19 10:08:08 +00:00
Simon Ogorodnik 513af2dfbc FIR. Refactor smart-cast representation in FIR tree
Make smart-casts non-transparent expression without delegation
to underlying FirQualifiedAccessExpression, as children delegation in
fir tree has unclear semantics
Remove two different kinds of tree nodes for smart-casts
2022-08-15 21:46:11 +00:00
Mikhail Glukhikh 12e8b1d844 K1: add support for Enum.entries synthetic property (see KT-48872)
#KT-53270 Fixed
2022-08-12 09:35:24 +00:00
Vsevolod Tolstopyatov 93f17a2b86 [FIR] Support static getters along with fake Enum.entries declaration in FIR
#KT-48872
2022-08-12 09:35:18 +00:00
Ivan Kylchik 45b89de9f4 Optimize ir interpretation of Enum.name
There is no need to create honest object in case of such simple
calculation. Furthermore, it can be harmful if enum class has
non-constant initializer or property.

#KT-53480 Fixed
2022-08-11 18:55:30 +03:00
Pavel Mikhailovskii 8ba80b4b7b KT-1436 Allow break/continue in inlined lambdas 2022-08-11 10:38:23 +00:00
Sergej Jaskiewicz 5e34ae5e0d [IR] Print annotations in source range compiler tests 2022-08-03 16:45:56 +00:00
Denis.Zharkov 7f7e5c5975 FIR: Fix candidate receivers orders when choosing a context receiver
^KT-53257 Fixed
2022-07-25 15:11:29 +00:00