Commit Graph

285 Commits

Author SHA1 Message Date
Kirill Rakhman c3c2f6f90a [FIR] Don't set lambda parameter type to Nothing by default
... when the expected type is not a function type.
Instead set it to a new type variable.
This fixes a bunch of false negative CANNOT_INFER_PARAMETER_TYPE.

#KT-59882 Fixed
2024-02-26 08:59:22 +00:00
Ilya Chernikov 49559d2a5a K2 Scripting: fix implicit receivers resolution order
#KT-65975 fixed
2024-02-23 22:03:44 +00:00
Nikolay Lunyak 8f8c7fe7cf [FIR] Properly calculate visibilities
`testIntersectionOfPrimitiveBasedFunctions`
is fine, because we deprecate this
already in ^KT-63243.

`CANNOT_INFER_VISIBILITY` is
positioned as `DECLARATION_NAME`,
just in case we decide for
some reason that we do want to
report it along with
`MANY_*_NOT_IMPLEMENTED`. In that
case, we'd get a problem that
their bounds overlap, but not
completely contain one another.

^KT-63741 Fixed
^KT-59400 Fixed
2024-02-15 16:10:14 +00:00
Kirill Rakhman c6b2675089 [FIR] Implement deprecation for calls to overrides of hidden
#KT-65438
2024-02-14 13:13:00 +00:00
Brian Norman fced126c9f [FIR] Properties defined in a do-while may not always be initialized
Local properties defined within the body of a do-while loop can be used
in the condition of the loop. However, use of a `continue` may mean the
property isn't always initialized, even if it is initialized when it is
defined. So while a local property may be within scope and has an
initializer, this doesn't always mean that the property is initialized.

As such, properties that are defined within a do-while loop and also
used in the condition of the same do-while loop should be tracked. Then,
these properties should still be checked for proper initialization even
if they have an initializer.

^KT-64872 Fixed
2024-01-31 13:37:30 +00:00
Dmitry Savvinov f28863b983 [k2, dfa] Use transitive closure of dependsOn for stability checks 2024-01-31 09:53:45 +00:00
Dmitry Savvinov 74fa6fc12c [k2, dfa] Smartcasts are not allowed on FirJavaField from other module
Handle case with FirField properly. Previously the code was returning
STABLE_VALUE in that case.

Note that in fact the changed 'when' branch expects only FirJavaField,
as FirFieldImpl should be handled by FirBackingFieldSymbol-check at
the beginning of the method. However, it is impossible to refer to
FirJavaField directly due to module visibility

Enumerate all cases more carefully via exhaustive 'when',
it's more readable and will prevent potential issues in future in case
more subclasses are added.

^KT-58279 Fixed
2024-01-31 09:53:45 +00:00
Brian Norman a2c9e5b36a [FIR] Copy implications from previous data flows when there is only one
Postponed lambdas introduce a host of challenges in data-flow analysis.
While inheriting type statements was disabled while these challenges are
being considered, we must still copy type statements from non-postponed
lambda edges. It seems the same is true for implications.

Implications are copied from previous flows when there is only a single
previous flow. That is because it never seemed to be required based on
test results. However, a recent test case revealed that copying is
required when there are multiple previous flows, but only one flow is
from a non-postponed-lambda node.

Combining implications from multiple non-postponed-lambda nodes did not
have an impact on test results, so until such a test case can be
created, the overhead of calculating common implications from multiple
flows will be avoided.

^KT-63351 Fixed
2024-01-30 17:22:31 +00:00
Brian Norman 7f9774819c Revert "[FIR] Do not smartcast class delegation implemented properties"
This reverts commit bb6f466162.

Reverting the fix for KT-57417 as it causes failures in IntelliJ and
Space projects. May reintroduce fix after failures are investigated and
resolved.
2024-01-29 19:24:03 +00:00
Brian Norman bb6f466162 [FIR] Do not smartcast class delegation implemented properties
When a property is implemented via class delegation, it should be
considered unstable for smart-casting. This is because it is unknown
what kind of stability the underlying class delegate property has. It
could be a stable property, or it could be implemented via a custom
getter and unstable.

^KT-57417 Fixed
2024-01-29 14:20:11 +00:00
Simon Ogorodnik 3f4d2e93c6 K2. Minor. Rename CFG ConstExpressionNode to LiteralExpressionNode
^KT-64314
2024-01-25 23:05:15 +00:00
Simon Ogorodnik 53e89a9722 K2. Minor. Rename FirConstExpression to FirLiteralExpression
FirConstExpression is usually confused with "constant" calculations,
while in fact, it just denotes a simple literal expression
and `1 + 1` isn't represented by a FirConstExpression.

^KT-64314 Fixed
2024-01-25 23:05:15 +00:00
Dmitriy Novozhilov 3fba3b703e [FIR] Update call-sites which are interested in annotation arguments
After the previous commit, enum entry access to the annotation may be
  presented by two different nodes

^KT-64975
2024-01-25 15:55:19 +00:00
Dmitriy Novozhilov a4e8be8687 [FIR] Deserialize enum entries access in annotations into FirEnumEntryDeserializedAccessExpression
^KT-64975 Fixed
^KT-62900
2024-01-25 15:55:19 +00:00
Dmitriy Novozhilov 150ff1172e [FIR] Add session parameter to all "element --> reference" utilities
`FirDeserializedEnumAccessExpression` requires session to build proper
  reference, so it's important to have it in all utilities, which may
  pass this element as input

^KT-64975
2024-01-25 15:55:19 +00:00
Dmitriy Novozhilov bd9cb2b7e0 [FIR] Refactor val FirElement.calleeReference utility
1. Convert it to `toReference()` function to make it consistent with other
   similar utilities
2. Provide the proper implementation

^KT-64975
2024-01-25 15:55:19 +00:00
Dmitriy Novozhilov 36958d585f [FIR] Move reference-related utils from :fir:tree to :fir:semantics
This is needed to gain access to providers functionality in those
  utilities, which is important for support of FirDeserializedEnumAccessExpression
  node (see later commits)

^KT-64975
2024-01-25 15:55:19 +00:00
Nikolay Lunyak 9b786d35f8 [FIR] Fix NO_RECEIVER_ALLOWED
If we do create an implicit invoke call, and
then put the receiver into the argument list,
we should mark it.
2024-01-24 12:49:56 +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
Nikolay Lunyak 965d8d2fd5 [FIR] Abstract away symbol.fir in FirImportsChecker
It's easier to reason about correctness of
`symbol.fir` when it's localized in small
helper functions.
2024-01-16 14:18:09 +00:00
Vladimir Sukharev 07938205bc [FIR][K/N] Get rid of SymbolInternals in FirObjCInterop 2024-01-16 09:39:16 +00:00
Denis.Zharkov 276f5b26d8 K2: Implement partially constrained lambda analysis (PCLA)
It's expected to partially mimic the behavior of what
previously was called builder inference, but with more clear contracts
(documentation is in progress, though)

See a lot of fixed issues in the later commits with test data,
especially [red-to-green]

^KT-59791 In Progress
2024-01-10 14:56:30 +00:00
Nikolay Lunyak 69fba8d33b [FIR] Make captureFromTypeParameterUpperBoundIfNeeded smarter
Before this change `ARGUMENT_TYPE_MISMATCH` would complain that
`Y` "is not a subtype of" `Inv<Y>`, because the function would only
check immediate bounds of the type parameter `Y`. `chosenSupertype`
would be `X`, not `Inv<out kotlin/String>`.

^KT-60056
2024-01-09 10:47:13 +00:00
Kirill Rakhman 1018ff280e [FIR] Fully expand the bounds of type parameters for canBeNull check
This is required because a not-null bound `Foo` can resolve to a
`typealias Foo = Bar?` in which case we must return true.

#KT-64645 Fixed
2024-01-03 17:15:50 +00:00
Kirill Rakhman 28eb78fe16 [FIR] Add description to ERROR_IN_CONTRACT_DESCRIPTION
#KT-49084 Fixed
2024-01-02 15:17:02 +00:00
Kirill Rakhman 5186ba80e2 [FIR] Check for setter visibility in resolution stage
This is required for the following commit where candidates from the
original scope in presence of smart cast will not be ignored if they're
the same symbol.
2023-12-21 13:29:00 +00:00
vladislav.grechko c48753900c Fix CallableId::isIterator: recognize primitive array iterators
^KT-60266: Fixed
2023-12-18 12:13:12 +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
Ilya Chernikov ed820d6b57 K2 IC: fix lookup recording for a "red" companion object
#KT-63665 fixed
2023-12-13 13:40:44 +00:00
Dmitriy Novozhilov 93563d7c80 [FIR] Report PROPERTY_AS_OPERATOR for all operator conventions
^KT-62347 Fixed
^KT-59715 Fixed
2023-12-13 09:27:14 +00:00
Yan Zhulanow 0944e8fc36 [Analysis API] Keep the collected 'FirTowerDataContext' mutable
'ContextCollector' is used for computing context of 'FirCodeFragment's.
Code fragments themselves might contain additional smart cast operations
that modify the context receiver stack.

^KT-63056 Fixed
2023-12-12 17:31:52 +00:00
Ilya Chernikov 12da3d2b9f K2 Scripting: add proper CFG processing for scripts
#KT-59683 fixed
#KT-63328 fixed
2023-12-12 09:58:19 +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
Roman Golyshev d6d9402b66 KT-59732 [FIR] Move reporting ConeUnresolvedParentInImport errors to FirUnresolvedInMiddleOfImportChecker 2023-12-04 16:51:46 +00:00
Roman Golyshev cd62f2f7a4 KT-59732 [FIR] Do not perform an actual resolve during IMPORTS phase
Use `FirSymbolProvider` to find the longest existing package, and
assume that the rest of the import is class name
2023-12-04 16:51:46 +00:00
Simon Ogorodnik 2f367b013a K2: Don't lose constraint errors in the builder inference session
Pass constraint errors from the integration system into a candidate to
make sure it is reported later.

Related to KT-59426, KT-59437, KT-53749
#KT-55168 Submitted
2023-12-04 15:27:20 +00:00
Mikhail Glukhikh 0ed6256bcc K2: implement BUILDER_INFERENCE_STUB_RECEIVER
#KT-59369 Fixed
2023-12-01 10:54:29 +00:00
Nikolay Lunyak 875e2b0cd6 [FIR] Prohibit calling functions with dynamic receiver over non-dynamics
^KT-63071 Fixed
2023-11-28 15:37:09 +00:00
Mikhail Glukhikh 83cfcc30c6 K2: handle type parameter vs nested class conflict in body resolve properly
This commit does two things:
- prioritize type parameter scopes against static scopes in body resolve
(effectively it's a revert of KT-58028 fix)
- consider type parameters as inapplicable callable, so during callable
resolve we can go up the tower and still resolve to static scope

This allows both KT-58028 and KT-63377 to work properly
#KT-63377 Fixed
2023-11-24 21:28:16 +00:00
Kirill Rakhman 9ea4afe7c8 [FIR] Fix isValidTypeParameterFromOuterDeclaration check for local class
This fixes an IllegalArgumentException when
symbolProvider.getClassLikeSymbolByClassId is called with a local
class ID.

#KT-63656 Fixed
2023-11-23 14:24:47 +00:00
Evgeniy.Zhelenskiy 67b1bb448a [FIR] Report repeating parameters in dynamic functions in Kotlin/JS
^KT-59988
2023-11-21 13:12:46 +00:00
Evgeniy.Zhelenskiy f5168527ae [FIR] Report type-parameterized implicit invoke call over type-parameterized property access
^KT-59988
2023-11-20 14:59:06 +00:00
Brian Norman e92fab65aa [FIR] Support including flow information when dumping CFG dot file 2023-11-16 18:04:26 +00:00
Mikhail Glukhikh 53ab32e0fb Rename: ConeTypeVariableType.lookupTag -> typeConstructor 2023-11-13 15:10:48 +00:00
Ivan Kochurkin 64db96eda3 [K1, K2] Use safe names when accessing to type parameters
^KT-57529 Fixed
2023-11-09 12:21:43 +01:00
Kirill Rakhman 789f886d3c [FIR] Implement ADAPTED_CALLABLE_REFERENCE_AGAINST_REFLECTION_TYPE diagnostic
#KT-59401 Fixed
2023-11-08 15:45:48 +00:00
Brian Norman b309786353 [FIR] RHS assignment during equality comparison should invalidate DFA
If the right-hand side of an equality comparison contains an assignment
to the variable used in the left-hand side, then implications about the
equality comparison within data-flow analysis cannot be applied, as the
value of the variable will be different after the comparison.

^KT-55096 Fixed
2023-11-06 22:12:22 +00:00
Kirill Rakhman 8821f8d1a4 [FIR] Expand type alias when checking for type parameters from outer declaration
This fixes a false positive OUTER_CLASS_ARGUMENTS_REQUIRED when
referring to an inner class of a supertype that is extended using a
typealias.

#KT-62099 Fixed
2023-10-27 08:05:58 +00:00
Ivan Kochurkin 1827df82c4 Removed useless as casts from compiler code
It allows compiling code with K2 and enabled `-Werror`
2023-10-24 20:59:56 +00:00
Evgeniy.Zhelenskiy f4d18da6a0 [FIR] Introduce OPERATOR_CALL_ON_CONSTRUCTOR diagnostic
#KT-59943
2023-10-24 12:24:52 +00:00