Commit Graph

1349 Commits

Author SHA1 Message Date
Denis.Zharkov 99448b77f3 FIR2IR: Imitate K1 behavior when SAM type has a bit different shape
See the relevant test at t/
estData/codegen/box/sam/contravariantIntersectionType.kt

After the previous commit, when generating a call for `doOnSuccess {}`,
we have a SAM type with removed projection Consumer<Any?>, while
real function type of the lambda is a bit different
(Function1<ConcreteType & ConcreteType2>).

While for me, that looks questionable, but in K1 it was effectively
resolved via the same implicit cast that on JVM is generated to an
INVOKEDYNAMIC that wraps initial function-typed value.

^KT-53552 Fixed
2023-02-20 14:54:09 +00:00
Denis.Zharkov 05ca001310 FIR2IR: Repeat the K1 behavior: SAM conversion with 'in' projection
It would be more consistently to prohibit the behavior from the unmuted
test (see KT-52428), but it was decided to postpone the breaking change.

Unfortunately, it didn't work to make a test where for computing
star projections we would need to substitute other type parameters
because effectively, it's not allowed to have SAM conversion when
star projections/wildcard is based on a type parameter which bounds
use other type parameters.

^KT-53552 In progress
2023-02-20 14:54:09 +00:00
Denis.Zharkov 2bafcddf7a K2: Avoid using Nothing? as inference result in the majority of cases
Namely, do not choose `Nothing?` result type when fixing a variable
that has other constraints besides the ones that came from
the relevant type parameter's upper bounds.

See more details in KT-55691.

In K1, the case from specialCallWithMaterializeAndExpectedType.kt
was working (inferred to String?) just because the branches
were analyzed independently with `String?` expected type.

This change became necessary after the previous commit when we united
inference subsystems for if/when branches (see motivation there).

NB: For K1, the behavior is left the same, but the code
was refactored a bit.

^KT-55691 Fixed
^KT-56448 Fixed
2023-02-15 08:13:50 +00:00
Denis.Zharkov a38040680c K2: Do not use KFunctionN as representation type for adapted references
Beside some corner cases, it's already prohibited in K1 because
adaptation have a bit strange nature
(they don't represent any existing real function exactly)

^KT-55137 Fixed
2023-02-15 08:13:45 +00:00
Mikhail Glukhikh 6d642c88f5 FIR2IR: make enum with abstract members from interfaces abstract
Related to KT-55828
2023-02-02 10:53:20 +01:00
Dmitriy Novozhilov d1b797ed97 [FIR] Generify resolution and inference of arguments of functional types 2023-02-02 08:24:50 +00:00
Kirill Rakhman e81f34d4b0 [FIR2IR] Generate fake overrides for synthetic properties
This fixes "IllegalStateException: Fir2IrSimpleFunctionSymbol for
<paramName> is already bound" when creating a callable reference to a
synthetic property

^KT-56072 Fixed
2023-02-01 11:56:26 +00:00
Mikhail Glukhikh f0ea8ab81b FIR2IR: make IrGetValue type consistent with IrVariable type
#KT-55458 Fixed
2023-01-31 13:43:26 +00:00
Mikhail Glukhikh 1c4d9175e7 FIR2IR: add test for KT-55458 2023-01-31 13:43:26 +00:00
Dmitriy Novozhilov a084bcbbb5 [FIR] Expand expected types before ILT approximation
^KT-56176 Fixed
2023-01-31 07:53:12 +00:00
Marco Pennekamp 9a693fa967 [FIR] Update backend tests with actual/expect in same module
- The fix for KT-55570 caused some backend tests to fail, because errors
  are now correctly reported for simple classes and actual/expect in
  the same module is not supported in FIR. See KT-55177.
- The commit also adds separate tests for K2. Unfortunately, these have
  to be disabled for K1 because K1 then reports "expect without actual"
  errors.
2023-01-30 17:17:58 +00:00
Dmitriy Novozhilov 88efa6bfb6 Update tests after switching to LV 1.9 2023-01-30 09:29:57 +00:00
Mikhail Glukhikh b867fd8c2f FIR2IR: set CATCH_PARAMETER origin for catch parameters 2023-01-25 12:31:35 +00:00
Mikhail Glukhikh ae4b8be16b FIR2IR: never generate empty when #KT-55459 Fixed
In details, this commit changes the following:
- it converts FIR when without branches to empty IR block without when
- it doesn't drop empty else branches in when anymore
2023-01-25 12:31:34 +00:00
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
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 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
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
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