Commit Graph

427 Commits

Author SHA1 Message Date
Nikita Bobko 4120d6a8aa [FIR] Search expect for actual only in dependsOn dependencies
Before this commit, the expect-actual resolver could find expects in
regular dependencies

Note: The appeared `VIRTUAL_MEMBER_HIDDEN` in
compiler/fir/analysis-tests/testData/resolveWithStdlib/multiModule/FakeOverrides.kt
isn't caused by my change. It's caused by fixing the testData dependency
syntax notation.

The testData improperly used regular dependency syntax notation, while
it should have been using dependsOn

Before:
    Regular dependency syntax notation

    // MODULE: androidMain(commonMain)

After:
    dependsOn dependency syntax notation

    // MODULE: androidMain()()(commonMain)
2024-02-22 16:06:35 +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
Ivan Kochurkin 55159694df [FIR] Use Operator origin for ITERATOR and HAS_NEXT function calls instead of Regular
It automatically fixes KT-62356 since iterators now are operators

^KT-62356 Fixed
2024-02-20 13:30:47 +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
Nikolay Lunyak 7056ad5325 [FIR] Set status.isOverride for fake overrides
Even though SO may not be correct
overrides sometimes, it feels more
natural to treat fake overrides as...
well, "overrides". And without it
we'd need to make the code in
`FirOverrideChecker` less intuitive.
2024-02-15 16:10:13 +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
Brian Norman 17a1871b83 [FIR] Make sure the primary constructor is first in class CFG
The primary constructor of a class needs to be the first subgraph of the
class control-flow graph. Based on the Kotlin specification, class
initialization order goes first primary constructor, in-place
declarations (properties and init blocks), and then secondary
constructors. If the class doesn't have a primary constructor, then it
is just skipped in the order.

Unfortunately, the class control-flow graph had in-place declarations
first and then all constructors. Instead, we should treat the primary
constructor as the first in-place declaration, and then continue with
the existing processing as secondary constructors. This will guarantee
that super constructor calls have the correct property initialization
information.

^KT-65093 Fixed
2024-01-23 23:16:00 +00:00
Mikhail Glukhikh caa850e470 FIR: render resolved qualifier type arguments in dumps 2024-01-17 16:51:48 +00:00
Anastasia.Nekrasova ad9025afa6 [k1/K2]: Mark @SubclassOptInRequired as an experimental
At the moment, SubclassOptInRequired is marked with the
ExperimentalSubclassOptIn annotation. However, it does not work
as expected due to a missing opt-in error. To use SubclassOptInRequired,
an explicit opt-in is necessary because SubclassOptInRequired is an
unstable feature now.

^KT-64739
2024-01-15 14:54:36 +00:00
Dmitriy Novozhilov 0bd6ea764e [FIR] Consider only normal execution path during contracts verification
There might be several pathes out from the function from CFG point of view:
- normal execution path
- exceptional execution path

For verification of callsInPlace contract it's needed to check only
 the normal path

^KT-63414 Fixed
2024-01-03 14:18:46 +00:00
Dmitriy Novozhilov de9826683e [FIR] Unwrap named arguments during contracts verification
^KT-64501 Fixed
2024-01-03 14:18:46 +00:00
Dmitriy Novozhilov 6031f80e01 [Test] Reproduce KT-63414, KT-64500 and KT-64501 2024-01-03 14:18:46 +00:00
Brian Norman b2041e0927 [FIR] Disable data flow from in-place lambdas
There are many complications with the current design of passing data
from within in-place lambdas to surrounding code. Solving these
complications will involve more time to investigation than is available
within the K2 release. So we are disabling passing type statement
information from lambdas for the time being until more time can be
devoted to a more complete solution.

^KT-60958 Fixed
^KT-63530 Fixed
2023-12-14 16:40:27 +00:00
Ivan Kylchik 97ba3fe396 [K2] Revert changes done in KT-61786
Changes in this ticket remove type enhancement in java fields
for K2. But after KT-61920 fix, we can actually support it.
2023-12-12 13:54:31 +00:00
Alexey Belkov f53f92cdd6 K2: Add KtDiagnosticRenderers.CLASS_ID to render ClassId FQNs with dots
KT-MR-13391
2023-12-08 17:26:59 +00:00
Dmitriy Novozhilov bc95c5d142 [FIR] Make MemberWithScope a data class
Previously, there was a contract that each callable symbol in the chain
  of `processDirectOverriddenWithBaseScope` will be unique. And if some
  symbol is accessible from multiple scopes, then only last of them will
  be returned as a component of `MemberWithScope`. So there actually was
  no such thing as "pair of two different MemberWithScope with the same
  symbol and different scopes"

After the change of `processDirectOverriddenWithBaseScope` contract (see
  previous commits) each scope returns `MemberWithScope` for some symbol
  with the previous scope in the hierarchy even if it contains the same
  symbol as the current scope

So now scope is actually a part of `MemberWithScope`, which should be
  considered as part of equality. Otherwise, we can skip some part of
  the overridden hierarchy, because we will start to consider symbol as
  visited after its first occurrence (in opposite to the previous behavior,
  when only the last scope was returned)
2023-12-08 15:19:55 +00:00
Brian Norman 0881910a1b [FIR] Rewind DFA after call arguments for correct receiver smartcasting
^KT-63709 Fixed
2023-12-08 14:32:22 +00:00
Nikita Nazarov 1df318ff28 [FIR] Remove the redundant isFunctionType check
^KT-63865 fixed
2023-12-01 21:04:41 +00:00
Nikolay Krasko 5e5e5b8b9f Revert "[FIR] Remove the redundant isFunctionType check"
This reverts commit 1f97c268e1.
2023-12-01 11:27:39 +01:00
Nikita Nazarov 1f97c268e1 [FIR] Remove the redundant isFunctionType check
^KT-63865 fixed
2023-11-30 14:17:01 +00:00
Kirill Rakhman dd1d36816b [FIR] Insert SAM conversion expressions during completion
#KT-62847 Fixed
2023-11-30 08:39:04 +00:00
Mikhail Glukhikh 0c61ce61c3 K2: for Java source override, don't compare return types in override checker
#KT-57044 Fixed
2023-11-21 18:11:58 +00:00
Mikhail Glukhikh be5a27dd6b K2: add test to confirm KT-56409 now works properly 2023-11-14 14:25:13 +00:00
Kirill Rakhman d54068b8ab [FIR] Report NONE_APPLICABLE on callable references with multiple failed candidates 2023-11-08 15:45:48 +00:00
Kirill Rakhman d91000e39c [FIR] Report INAPPLICABLE_CANDIDATE or more specific diagnostic for callable references
... instead of just UNRESOLVED_REFERENCE when something went wrong
during resolution.

#KT-59401 related
2023-11-08 15:45:48 +00:00
Brian Norman 01a757cbd6 [FIR] Report PROPERTY_WITH_NO_TYPE_NO_INITIALIZER for all properties
Currently, PROPERTY_WITH_NO_TYPE_NO_INITIALIZER is reported for local
variables, but not reported for member or top-level properties. Add a
check to the common `checkPropertyInitializer` for when a property
type cannot be determined from the getter.

This also corrects a K1 versus K2 inconsistency, where K2 would allow
blocks from getters to determine property type instead of only allowing
expression bodies.

^KT-59935 Fixed
^KT-60117 Fixed
^KT-60123 Fixed
2023-10-30 16:28:10 +00:00
Ivan Kochurkin d50c6f1b6d [FIR] Fix missing USELESS_CAST
`FirUselessTypeOperationCallChecker` always checks exact types matching for `as` operator

Simplify code of cast checker and utils

^KT-56629 Fixed
^KT-56615 Fixed
^KT-59820 Fixed
2023-10-24 20:59:56 +00:00
Mikhail Glukhikh cebb6747e3 K2: drop unnecessary attributes when inferring declaration types
Related to KT-62578
2023-10-20 12:38:19 +00:00
Mikhail Glukhikh 4ed7504d87 FIR deserializer: apply attributes on type parameter-based types
#KT-62578 Fixed
2023-10-18 10:30:31 +00:00
Ivan Kochurkin 498f2e534a [FIR] Don't enhance Int and String Java final static fields
It's effectively a breaking change (^KT-62558)

K2 assigns flexible type to all static fields (from Java) and, for example,
`String? becomes String unlike K1. It affects IR signature generating.
That's why signature dump is disabled for some tests.

^KT-57811 Fixed
^KT-61786 Fixed
2023-10-16 17:16:56 +00:00
Kirill Rakhman fbf68a5bcc [FIR] Narrow down range of NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER
This uses the same approach as
INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION where we use a visitor
to find a call to a symbol that contains the type variable in question.

#KT-56140 Fixed
2023-09-22 13:49:59 +00:00
Ilya Kirillov d98da87278 [FIR] Render dot-separated FQNs instead of slash-separated ones in diagnostics
^KT-62030 fixed
2023-09-22 10:48:31 +00:00
Ivan Kochurkin 4b9e15dfa8 [FIR] Fix missing RETURN_TYPE_MISMATCH for labeled return statements
in lambda functions, ^KT-59907 Fixed

(cherry picked from commit 8e72f60996)
2023-09-21 12:52:31 +00:00
Ivan Kochurkin 063835488f Revert "[FIR] Fix missing RETURN_TYPE_MISMATCH for labeled return statements"
This reverts commit 8e72f60996

Since some intellij tests are failing
2023-09-20 12:29:41 +02:00
Kirill Rakhman 5b4409e34c [FIR] Store abbreviated type in deserialized declarations as attribute
#KT-58542 Fixed
2023-09-20 09:31:29 +00:00
Ivan Kochurkin 8e72f60996 [FIR] Fix missing RETURN_TYPE_MISMATCH for labeled return statements
in lambda functions, ^KT-59907 Fixed
2023-09-20 09:06:37 +00:00
Alexander Udalov 5cae87b263 K2: add package FQ name to ClassId of anonymous objects
This is needed because in order to figure out which declarations are
visible from anonymous objects in terms of overridability (see
`FirVisibilityChecker.isVisibleForOverriding`), we need to get the
package name of that anonymous object, because there's package-private
visibility on JVM.

 #KT-62017 Fixed
2023-09-19 09:32:55 +00:00
Denis.Zharkov 034671ad78 K2: Update substituted member candidate if it contains type variables
See the comment at updateSubstitutedMemberIfReceiverContainsTypeVariable

It became necessary after delegate inference is rewritten, since before
that happened, stub types were being left there and FIR2IR handled
them accidentally properly because stub types are equal to anything.

But that wasn't really correct even there because stub types are not
intended to leak out of the FIR

^KT-61060
2023-09-08 07:11:48 +00:00
Denis.Zharkov a02cb16fb2 K2: Rewrite delegate inference
The main idea is getting rid of stub types and using just type variables
See more detailed description at docs/fir/delegated_property_inference.md

The problem with stub types is that they need really special treatment
in many places, and on the other hand, there are no clear contracts on
how they should work (that regularly leads to bugs like KT-59529)

^KT-61060 Fixed
^KT-61075 Fixed
^KT-61077 Fixed
^KT-59529 Fixed
^KT-61633 Related
^KT-61618 Related
^KT-61740 Related
^KT-59107 Related
^KT-61747 Related
^KT-61077 Related
^KT-61781 Related
2023-09-08 07:11:48 +00:00
Brian Norman f51b7faa1b [FIR] Only track assignment nodes for uncaught exception edges in CFG
UncaughtExceptionPath edges are used to influence smart-casting within
catch and finally blocks. Previously these edges were added from every
node which could throw an exception. But only assignment nodes influence
smart-casts by resetting inference back to some less specific type.
Therefore, instead of tracking every possible node which could throw an
exception - even though almost every statement node can - only add edges
from assignment nodes to catch and finally blocks. This fixes many
missing exception cases and also reduces the total number of incoming
edges to catch and finally blocks.

#KT-56872 Fixed
2023-09-05 11:59:13 +00:00
Nikolay Lunyak cd392ebe69 [FIR] Don't miss RETURN_NOT_ALLOWED
^KT-59914 Fixed
2023-09-04 10:19:11 +00:00
Brian Norman b55fda0c55 [FIR] Create CFG for files to track top-level property initialization
In order to properly analyze top-level property initialization, a
control-flow graph must be created for FirFiles. This change adds the
foundation for the file CFG and updates body resolve to create the CFG.
Checking the CFG for proper initialization is separated into a following
change to ease code review.

KT-56683
2023-08-31 12:50:52 +00:00
Kirill Rakhman 411210b520 [RAW FIR] Use range as source of desugared loop-related statements 2023-08-31 10:19:33 +00:00
Mikhail Glukhikh 6ce096f0ed K2: handle extra value parameter in FirCallCompleter properly
#KT-60450 Fixed
2023-08-28 14:02:56 +00:00
Kirill Rakhman c30ce4aabe [FIR] Print operator keyword and token to unresolved diagnostic message
#KT-55672 Fixed
2023-08-28 08:12:25 +00:00
Kirill Rakhman 8de36c416e [RAW FIR] Put destructuring statements outside of main lambda block
This fixes a false positive REDECLARATION when you want to shadow
a destructured lambda parameter inside the lambda.

#KT-60771 Fixed
2023-08-24 11:07:45 +00:00
Mikhail Glukhikh 8cbefcc26f K2: add test to ensure #KT-55981 Obsolete 2023-08-22 11:40:26 +00:00
Mikhail Glukhikh 9846ec23df Raw FIR: generate 'return setValue' instead of just 'setValue'
#KT-61045 Fixed
2023-08-22 11:20:19 +00:00
Kirill Rakhman fa77e3952d [FIR] Bring equivalent call behavior closer to K1
#KT-61159 Fixed
2023-08-21 12:11:58 +00:00
Nikolay Lunyak f9c6af4d2a [FIR] Properly assign <local> packages to symbols
This prevents `FirConflictsExpressionChecker.kt`
from missing conflicting local functions. It used
to due to inconsistencies in assigning `<local>`,
and this commit makes it a bit more
straightforward.

The change in KtClassTypeQualifierRenderer
prevents `FirOverrideImplementTest.testLocalClass`
from failing in `intellij`. It didn't fail for
callables, because `KtCallableSignatureRenderer`
doesn't try to render packages.

^KT-59186 Fixed
2023-08-18 13:31:04 +00:00