Commit Graph

928 Commits

Author SHA1 Message Date
Ilya Kirillov 69c024a5ce [FIR] optimize deprecation calculation for symbols
All symbols except member callables can be deprecated if they have non-empty annotation list

^KT-56800 fixed
2023-02-24 16:10:57 +01:00
Nikolay Lunyak 516efe77c9 [FIR] KT-56612: Fully-expand types when casting bare types
^KT-56612 Fixed

Merge-request: KT-MR-8849
Merged-by: Nikolay Lunyak <Nikolay.Lunyak@jetbrains.com>
2023-02-17 09:15:59 +00:00
Marco Pennekamp 5d391bc261 [FIR] KT-56505 Fix checkVisibilityModifier taking wrong modifier list
- KT-56505 occurred because `source.getChild(KtNodeTypes.MODIFIER_LIST)`
  returns any modifier list in the subtree of the source element, not
  necessarily the modifier list belonging to the checked element.
  `depth = 1` restricts the search to the modifier list belonging to the
  checked element itself.
- For example, given `f1` from KT-56505, `getChild` would return the
  modifier list of `public var foo = 0`. Because it contains a
  visibility modifier, `f1` wasn't marked with
  `NO_EXPLICIT_VISIBILITY_IN_API_MODE`.

^KT-56505 fixed
2023-02-16 10:50:48 +00:00
Marco Pennekamp e86c877733 [FIR] Explicit API mode: No REDUNDANT_VISIBILITY_MODIFIER for public
- In explicit API mode, the `public` visibility modifier is not
  redundant unless a declaration is hidden by a container. The
  `REDUNDANT_VISIBILITY_MODIFIER` diagnostic is now not reported in such
  cases.

^KTIJ-24485 fixed
2023-02-16 10:50:48 +00:00
Marco Pennekamp 5909b191a5 [FIR] KT-54507 Report REDUNDANT_MODALITY_MODIFIER for open interface
- `REDUNDANT_MODIFIER_FOR_TARGET` is already reported for `open`
  interfaces, but for consistency and IDE support, the compiler now
  reports `REDUNDANT_MODALITY_MODIFIER` as well via the extended
  checker.
- `REDUNDANT_MODIFIER_FOR_TARGET` cannot be disabled for this case
  because it's reported via a basic checker while
  `REDUNDANT_MODALITY_MODIFIER` is reported via an extended checker.
- Rename `implicitModality` to `redundantModalities` and return a set of
  modalities. The idea of a *single* implicit/redundant modality doesn't
  stand up to scrutiny. For example, for interfaces with `ABSTRACT`
  implicit modality, `OPEN` is also a redundant modifier. But this is
  not necessarily the case for all kinds of declarations.
  Hypothetically, if it was possible to declare a class that is abstract
  by default, adding an `open` modifier to that class would not be
  redundant, as it would make the class instantiable.
2023-02-16 10:50:48 +00:00
Denis.Zharkov d84490dcfa K2: Delete failing test for KT-55555
It appeared again after 2b3f34cc52
And still needs some investigation

^KT-55555 Open
2023-02-15 09:17:11 +00:00
Denis.Zharkov 14418a31ac K2: Adjust test data after 9fa0f51a61 2023-02-15 09:17:11 +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 9fa0f51a61 K2: Fix false-negative RETURN_TYPE_MISMATCH
^KT-53987 Fixed
^KT-55932 Fixed
2023-02-15 08:13:42 +00:00
Dmitriy Novozhilov 8e3022452e [FIR] Unify diagnostic message in FIR dump for syntax error between PSI and LT 2023-02-14 17:08:55 +00:00
Dmitriy Novozhilov aef9b129d2 [FIR] Add regression tests for number of issues fixed in K2
List of issues:
KT-4113,  KT-6822,  KT-7389,  KT-17817, KT-20223
KT-21463, KT-24503, KT-24737, KT-24779, KT-24901
KT-27261, KT-28668, KT-30497, KT-30756, KT-36958
KT-37365, KT-37490, KT-38288, KT-41038, KT-41721
KT-42136, KT-42169, KT-42449, KT-42715, KT-43553
KT-43603, KT-43846, KT-43936, KT-46288, KT-46301
KT-47373, KT-47484, KT-47490, KT-47495, KT-47750
KT-47815, KT-47870, KT-48975, KT-49024, KT-49045
KT-50134, KT-50160, KT-50550, KT-51045, KT-51143
KT-51796, KT-52262, KT-52424, KT-52860, KT-52934
KT-53086, KT-53494, KT-53671, KT-53752, KT-53819
KT-54478, KT-54518, KT-54931, KT-54990, KT-55138
KT-55379, KT-55555, KT-56243
2023-02-14 17:08:55 +00:00
Dmitriy Novozhilov 8ae5213155 [FIR] Add tests for KT-50386 and KT-50646 2023-02-14 17:08:54 +00:00
Dmitriy Novozhilov 092ebf4c11 [FIR] Add test for KT-49249 2023-02-14 17:08:54 +00:00
Dmitriy Novozhilov 019d7db737 [FIR] Add regression test for KT-44392
Also related to KT-56615
2023-02-14 17:08:53 +00:00
Dmitriy Novozhilov 197f19c627 [FIR] Add test for KT-43619 2023-02-14 17:08:53 +00:00
Mikhail Glukhikh 2405f28e64 K2: add test confirming successful work of KT-56261 2023-02-13 12:21:42 +00:00
Mikhail Glukhikh 5a9e8b3c0a FE: add tests for KT-53966 (positive/negative) 2023-02-08 17:40:20 +00:00
aleksandrina-streltsova 7db32f6430 [FIR] Fix unexpected primary constructor scope in secondary constructor
^KTIJ-23720
^KT-56353 Fixed
2023-02-06 10:30:28 +00:00
Dmitriy Novozhilov e9204521a9 [FIR] Properly create type ref for error type in various places 2023-02-06 08:09:56 +00:00
Anna Kozlova b415aa7446 [FIR] take ready implicit unit type instead of return type calculation
and assert that symbol is not a substitution/intersection override
in the `compute` method otherwise.

Because `fakeOverrideSubstitution` should be calculated for all real
implicit types, no call to this method should actually happen.

Otherwise, it can be problematic to create a session
which would contain the full designation path:
`provider.getFirCallableContainerFile(symbol)`
returns `firFile` of a super class which might be from module `a`,
when declaration and its outer classes are from module `b`.

^KTIJ-24105
2023-01-31 11:21:17 +00:00
Kirill Rakhman 1eb18f13bd FIR: Fix test data after making LHS of assignment an expression
KT-54648
2023-01-31 08:39:43 +00:00
Dmitriy Novozhilov 4c96495eef [FIR] Put new contract syntax under feauture flag
^KT-55171 Fixed
2023-01-31 07:53:09 +00:00
Nikolay Lunyak 5994a99dbb [FIR] KT-54507: Report redundant for abstract interfaces
^KT-54507 Fixed

Merge-request: KT-MR-8490
Merged-by: Nikolay Lunyak <Nikolay.Lunyak@jetbrains.com>
2023-01-30 16:45:20 +00:00
Dmitriy Novozhilov 88efa6bfb6 Update tests after switching to LV 1.9 2023-01-30 09:29:57 +00:00
Kirill Rakhman efc957586d FIR: Report EXPLICIT_DELEGATION_CALL_REQUIRED in some missing cases
^KT-55877 Fixed
2023-01-27 12:26:51 +00:00
Anna Kozlova e5b96561e0 [FIR] skip implicit call to enum constructor if super type call exists
otherwise, reference to the super type would be resolved even when it's not
e.g. for interface constructor
^ KTIJ-24437
2023-01-27 08:20:07 +00:00
Mikhail Glukhikh aafde418cc K2: store imported static qualifiers in dispatch receiver field
This is a partial revert of commit 104fd4c1
#KT-55116 Fixed
2023-01-26 15:27:55 +00:00
Kirill Rakhman 583584be7e FIR: Resolve error expression in initializer of FirField
^KT-54775 Fixed
2023-01-26 14:12:48 +00:00
pyos f8f63f4573 FIR CFA: fix function locality check 2023-01-26 13:12:16 +00:00
pyos 99e51f6940 FIR: check assignments and references to members in constructors
I.e. emit VAL_REASSIGNMENT on repeated assignments to `this.something`,
UNINITIALIZED_VARIABLE on reads of it before any assignment if there is
no initializer, and CAPTURED_MEMBER_VAL_INITIALIZATION on assignments
inside non-called-in-place functions and named classes.

^KT-55528 Fixed
2023-01-26 13:12:13 +00:00
pyos c42dd0848e FIR: only allow member val initialization through this@T
class C {
    val x: Int
    init {
      // valid ways to initialize:
      x = 1
      this@C.x = 1
      // invalid:
      someOtherC.x = 1
      run { /*this@run.*/x = 1 }
      val self = this
      self.x = 1
    }
  }
2023-01-26 13:12:12 +00:00
pyos 9f17b5de97 FIR CFA: add edges according to constructor delegation 2023-01-26 13:12:11 +00:00
pyos 8aa50e9446 FIR CFA: add edges from maybe-throwing statements to catch/finally 2023-01-26 09:50:24 +00:00
Marco Pennekamp 88ac5727cc [LL FIR] KT-50732 Add support for LL FIR-specific tests (.ll.kt)
- `.ll.kt` test data can be added in cases where LL FIR resolution
  legally diverges from K2 compiler results.
- Each `.ll.kt` test is prefixed with an `LL_FIR_DIVERGENCE` directive
  which must explain why the test may diverge from K2 compiler results.
  - `LLFirDivergenceCommentChecker` ensures that each `.ll.kt` file
    contains an `LL_FIR_DIVERGENCE` directive.
- `LLFirIdenticalChecker` results in an assertion error if the `.ll.kt`
  test and its base test are completely identical, including in their
  meta info (but ignoring `LL_FIR_DIVERGENCE`).
  - The checker additionally ensures that the base source file and the
    `.ll.kt` source file have identical Kotlin source code (ignoring
    meta info and `LL_FIR_DIVERGENCE`). This ensures that both tests
    test the exact same thing.
- `.ll.kt` files are ignored by select test generators, in addition to
  `.fir.kt` files.
2023-01-16 15:20:50 +00:00
Ilya Kirillov 6204e43f3f [FIR] fix resolve contract violation from FirTypeParameter.eraseToUpperBound
^KT-54890
2023-01-13 21:32:52 +00:00
Ilya Kirillov 1bbcae5ed2 [FIR] fix resolve contract violation from scopes
We cannot call lazy resolve to STATUS phase from scopes as scopes may be accessed on a STATUS phase or earlier

^KT-54890
^KTIJ-23587 fixed
2023-01-13 21:32:51 +00:00
Mikhail Glukhikh f20e5daa92 K2: fix property VS field resolve in anonymous class case
Related to KT-55017, KT-50082
2023-01-13 13:49:20 +00:00
Kirill Rakhman 5a08d8da8d FIR: don't check annotations on returnTypeRefs that are not of real kind
This fixes an exception in FirAnnotationChecker where we tried to report
repeated annotations on implicit type refs that have no source.
2023-01-13 12:54:18 +00:00
Dmitriy Novozhilov e7148daad2 [FIR] Properly substitute arguments of error types 2023-01-12 17:45:06 +00:00
Denis.Zharkov b009ee3744 Add @SinceKotlin and KDoc for ContextFunctionTypeParams
Initially, it was added accidentally as part of e3f987459c
and missed all out processes.

Adding @SinceKotlin("1.7") after the annotation has already been
published before is not really a problem, because it only may be used
with an experimental `-Xcontext-receivers` flag, thus it doesn't have
to be a part of our regular backward compatibility routine.

^KT-55226 Fixed
2023-01-12 16:53:48 +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 e86b87fe0b Test: FIR CFA: fix the names of some nodes 2023-01-10 15:40:52 +02:00
pyos 0dd949bb36 FIR DFA: route data flow through anonymous objects
^KT-44515 Fixed
2023-01-10 15:40:50 +02:00
pyos 17ee8f3a7b FIR CFA: put primary constructor before other class members 2023-01-10 15:40:50 +02:00
pyos c6e9afb788 FIR CFA: remove class initializer part nodes
Instead, attach subgraphs directly to the class enter node.
2023-01-10 15:40:50 +02:00
pyos 54f32a6fba Test: FIR CFA: index nodes in rendering order 2023-01-10 15:40:49 +02:00
pyos a9397b7b23 Test: FIR CFA: don't output two node fill colors 2023-01-10 15:40:49 +02:00
pyos 4bb7b1ac9f FIR DFA: use class enter node as data flow source for members
Also fix graphs for enums with specialized entries - since we don't
create property subgraphs for FirEnumEntry, there is no body to insert
AnonymousObjectEnterNode, AnonymousObjectExitNode, and
AnonymousObjectExpressionExitNode into.
2023-01-10 15:40:49 +02:00
pyos 4c6eff9174 FIR CFA: compute subgraph relationships automatically
No more `addSubGraph`. Also no more `owner` in graphs.

^KT-40526 Obsolete
^KT-40582 Obsolete
2023-01-10 15:40:48 +02:00
pyos 7ff5ad1ad0 FIR CFA: remove modes
They are only used in one place that can just as well use kinds.

Especially considering that "the one place" used them incorrectly and
would not attach local functions in property accessors as subgraphs.
2023-01-10 15:40:48 +02:00