Commit Graph

570 Commits

Author SHA1 Message Date
Tomas Husak ec167d4d42 K2: implement FirForLoopStatementAssignmentChecker
#KT-60006 Fixed
2024-02-20 17:34:49 +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
Roman Efremov 8c000b8319 [LightTree] Stop reporting LOCAL_VARIABLE_WITH_TYPE_PARAMETERS on
...destructuring declarations to make it similar to PSI.

^KT-62704
2024-01-29 14:09:59 +00:00
Roman Efremov d22cc01638 [LightTree] Stop reporting NAME_IN_CONSTRAINT_IS_NOT_A_TYPE_PARAMETER on
...local properties to make it similar to PSI.

See this logic in `org.jetbrains.kotlin.fir.builder.PsiRawFirBuilder.Visitor.toFirProperty`

^KT-62704
2024-01-29 14:09:59 +00:00
Roman Efremov 3c8855c152 [LightTree] Fix positioning of VAR_TYPE_MISMATCH_ON_OVERRIDE in LT
The problem is that `override var b: String` in constructor has token
type `VALUE_PARAMETER`, thus was not considered as declaration.

^KT-62704
2024-01-29 14:09:59 +00:00
Roman Efremov 8edb1842a5 [Tests] Add spec tests in FIR + LightTree configuration
In some tests PSI and LT differ. Test data was fixed accordingly.

In the following tests I consider that difference is acceptable:
- compiler/tests-spec/testData/diagnostics/linked/expressions/try-expression/p-1/neg/3.1.kt
- compiler/tests-spec/testData/diagnostics/linked/expressions/try-expression/p-1/neg/4.1.kt

This is because:
- It only happens when recovering from syntax errors happened above in
code. I was unable to reproduce it in valid code.
- It doesn't break parsing further, the rest of the errors in file are
reported identically.

The rest of the tests will be fixed in subsequent commits.

^KT-62704 Fixed
2024-01-29 14:09:59 +00:00
Kirill Rakhman 251827c9aa [FIR] Don't approximate captured types
This fixes some type argument mismatch errors caused by a captured type
being approximated and then captured again.
Some places need to be adapted to work with captured types that
previously only worked with approximated types.

#KT-62959 Fixed
2024-01-17 08:20:05 +00:00
Denis.Zharkov 6052e24626 K2: Adjust test data after PCLA implementation [red-to-red]
^KT-59791 In Progress
2024-01-10 14:56:30 +00:00
Kirill Rakhman 8aa32d9f45 [FIR] Rename DUPLICATE_LABEL_IN_WHEN to DUPLICATE_BRANCH_CONDITION_IN_WHEN
... and fix the message

#KT-35289 Fixed
2024-01-02 15:17:02 +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
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
Brian Norman 0881910a1b [FIR] Rewind DFA after call arguments for correct receiver smartcasting
^KT-63709 Fixed
2023-12-08 14:32:22 +00:00
Egor Kulikov 43fc4ccf40 [FIR] Source for implicit iterator calls in for should not be null
^KT-62111 fixed


Merge-request: KT-MR-13029
Merged-by: Egor Kulikov <Egor.Kulikov@jetbrains.com>
2023-11-22 17:15:24 +00:00
Brian Norman cfa48b5cc0 [FIR] Add null implications to both sides of equality when appropriate
When both sides of an equality expression are null or Nothing?, only the
right side is receiving implications within the data-flow. Make sure the
left side has implications add as well. This is important for boolean
conditions when implications from both sides need to be combined.

^KT-63535 Fixed
2023-11-20 20:03:52 +00:00
Brian Norman a4b3b08e59 [FIR] Do not terminate smartcast CFG nodes when result is Nothing
Terminating a CFG node because the result is Nothing should be reserved
for explicit Nothing type definitions, and not apply when smartcasting.
This allows boolean expressions to propagate implications correctly even
when the RHS is impossible or will never be executed.

^KT-47931 Fixed
2023-11-16 18:04:26 +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
Vladimir Sukharev 0fb853a995 [FIR] Fix Disappeared CONTRACT_NOT_ALLOWED
https://youtrack.jetbrains.com/issue/KT-60004/K2-Disappeared-CONTRACTNOTALLOWED

Merge-request: KT-MR-12613
Merged-by: Vladimir Sukharev <Vladimir.Sukharev@jetbrains.com>
2023-11-02 20:47:05 +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
Evgeniy.Zhelenskiy f4d18da6a0 [FIR] Introduce OPERATOR_CALL_ON_CONSTRUCTOR diagnostic
#KT-59943
2023-10-24 12:24:52 +00:00
Nikolay Lunyak a68a2409d3 [FIR] Remove the applicability filtering when reporting diagnostics
In case we don't want to introduce any new
abstractions like "user relevance for
applicability", we can just remove the
filtering.

^KT-62541 Fixed
2023-10-19 09:27:45 +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
Vladimir Sukharev 56eedfebee [FIR] K2: Fix disappeared diagnostic UNDERSCORE_USAGE_WITHOUT_BACKTICKS on types
^KT-59985 Fixed

Merge-request: KT-MR-12282
Merged-by: Vladimir Sukharev <Vladimir.Sukharev@jetbrains.com>
2023-09-22 11:18:19 +00:00
Kirill Rakhman 10f7989af6 [FIR] Report UNRESOLVED_REFERENCE on the first unresolved qualifier
#KT-55471 Fixed
2023-09-04 08:05:07 +00:00
Brian Norman 833072e1fb [FIR] Add checker for MISSING_DEPENDENCY_CLASS
#KT-59371 Fixed
2023-08-28 15:00:04 +00:00
Kirill Rakhman fa77e3952d [FIR] Bring equivalent call behavior closer to K1
#KT-61159 Fixed
2023-08-21 12:11:58 +00:00
Kirill Rakhman 640d1e3fc8 [FIR] Fix augmented array set call on smartcasted receiver
#KT-60917 Fixed
2023-08-17 15:13:38 +00:00
Kirill Rakhman 724d527fd8 [FIR] Fixes for call conflict resolution
Let ConeCompositeConflictResolver pass the results of the previous
resolver to the next one.
Otherwise, we get false positive conflicts when a set of candidates
can't be fully reduced by one resolver but could be resolved by the
subsequent application of multiple ones.
This change makes ConeCompositeConflictResolver order-dependent and
thus, ConeOverloadConflictResolver must be invoked last, because it
must work on a pre-filtered list.

Also, let ConeEquivalentCallConflictResolver use
FirStandardOverrideChecker instead of compareCallsByUsedArguments
because it's stricter.

This all fixes a false positive overload resolution ambiguity in common
metadata compilation that is caused by stdlib using the new KMP
format.
Now stdlib metadata is in the classpath, and so declarations from the
stdlib are returned from both MetadataSymbolProvider and
KlibBasedSymbolProvider.
This isn't a problem per se because duplicate candidates are filtered
out by ConeEquivalentCallConflictResolver (K1 works analogously), but
in the case of top-level functions with generic receivers like
Collection<T>.toTypedArray, the check failed because of the direct
comparison of receiver types.

#KT-60943 Fixed
2023-08-11 10:54:24 +00:00
Alexander Udalov 7fc3e60854 K2: add JVM checker for NO_REFLECTION_IN_CLASS_PATH warning
It's based on the existing K1 checker `JvmReflectionAPICallChecker`.

 #KT-60587 Fixed
2023-08-03 13:42:03 +00:00
Brian Norman 0e2b3ce845 [FIR] Create alternate DFA flows through finally blocks
Entering a `finally` block can happen from many different places:
through an exception, a jump, or normal exit from the `try` block. When
in the `finally` block, all DFA flows must be merged to have correct
smart casting. However, after the `finally` block, if exiting normally
or because of a jump, the combined flow from within the `finally` block
should not be used, but rather an alternate flow which combines the
correct flows from before the `finally` block.

```
try {
    str as String // Potential cast exception
} finally {
    str.length // Shouldn`t be resolved
}
str.length // Should be resolved
```

When building DFA flows, track the start of possible alternate flows,
and continue building them until they end. Both of these situations are
now marked on CFGNodes via interfaces.

When building the default DFA flow, and the source node is the end node
of alternate flows, attempt to use the alternate flow with the same edge
label instead of the default flow of the source node.

#KT-56888 Fixed
2023-07-27 13:05:58 +00:00
Kirill Rakhman 2f3293f99e [FIR] Skip redundant INAPPLICABLE_CANDIDATE on call with unresolved callable reference argument
A new resolution diagnostic UnsuccessfulCallableReferenceAtom is
introduced that is used in EagerResolveOfCallableReferences.
No diagnostic is reported on unresolved calls with this diagnostic
because

#KT-59856
2023-07-20 07:29:18 +00:00
Nikolay Lunyak 884cd6c754 [FIR] Move FirReturnsImpliesAnalyzer to the extended checkers 2023-07-10 09:28:54 +00:00
Kirill Rakhman 028921ade1 [FIR] Implement checker for value parameter default value type mismatch
#KT-58901 Fixed
2023-07-03 10:11:36 +00:00
Denis.Zharkov 3279313f2c K2: Fix priority for implicit receiver + extensionInvoke
See K1 counterpart at org.jetbrains.kotlin.resolve.calls.tower.TowerResolver.Task.processImplicitReceiver

^KT-58943 Fixed
^KT-59541 Fixed
2023-07-01 16:29:06 +00:00
Egor Kulikov b147b7e929 [FIR] Store fir for invalid when branches
^KTIJ-25646 fixed

Merge-request: KT-MR-10646
Merged-by: Egor Kulikov <Egor.Kulikov@jetbrains.com>
2023-06-20 16:11:31 +00:00
Nikolay Lunyak 7541732752 [FIR] Fix TEST SPEC tests
Ensure the test data contents for both the frontends
are identical. This is needed for proper analysis of
K2-differences.
2023-06-19 07:40:15 +00:00
Nikolay Lunyak f94c795b5b [FIR] KT-55552: Report type mismatch for delegated properties
^KT-55552 Fixed
2023-05-17 12:44:52 +00:00
Kirill Rakhman b2fa104081 [FIR] Keep all failed resolution candidates and fully resolve them
Previously, when a candidate was found with an applicability that is
better than the current best applicability, all previous candidates were
thrown away. Now we keep them, unless the new applicability is
successful. If no successful candidates are found, we fully resolve all
the unsuccessful ones and select the ones with the least bad
applicability. This improves diagnostics for unresolved calls.

#KT-57844 Fixed
2023-05-10 11:48:58 +00:00
Dmitrii Gridin 72def186a3 [LL FIR] rework transformers, so transformers resolve only a specific set of declarations
The change is needed for the parallel resolution (^KT-55750), so we can resolve the declaration
under a lock that is specific to this declaration.
Previously, if LL FIR was resolving some FirClass, LL FIR  resolved all its children too, and it had no control over what parts of the FIR tree were modified.
The same applied to the designation path, sometimes the classes on the designation path
might be unexpectedly (and without lock) modified.

This commit introduces LLFirResolveTarget, which specifies which exact declarations should be resolved during the lazy resolution of the declaration.
All elements outside the declarations specified for resolve in LLFirResolveTarget, should not be modified.

The logic of lazy transformers is the following:
- Go to target declaration collecting all scopes from the file and containing classes
- Resolve only declarations that are specified by the LLFirResolveTarget, performing the resolve under a separate lock for each declaration

^KT-56543
^KT-57619 Fixed
2023-04-19 20:12:38 +00:00
Nikolay Lunyak 8d04ab3142 [FIR] Ignore nullability in the definition of "identity-less"
The definition of a "builtin" already
ignores nullability.

`Int? === String?` must trigger a
diagnostic by design.
2023-04-19 16:05:19 +00:00
Dmitriy Novozhilov f8dc8057f0 [FIR] Prohibit referencing type parameters in contracts ...
...if they are not reified or not belong to owner declaration of the contract

KT-57911
2023-04-18 13:31:28 +00:00
Dmitriy Novozhilov 5a92eb2c67 [FIR] Properly track problems in contract description during effect extraction 2023-04-18 13:31:28 +00:00
Kirill Rakhman 592baee852 [FIR] When call candidates resolve to errors, select the least bad ones
This fixes a scenario when INVISIBLE_REFERENCE is suppressed, but we
resolved to the wrong overload because when none of the candidates were
applicable, more or less the first one was chosen.

Because we call `fullyProcessCandidate` on the candidates, their
applicability can change which can lead to a situation where the
applicability of a ConeAmbiguityError is different to all its
candidates. The changes in coneDiagnosticToFirDiagnostic.kt account for
that, otherwise code like candidates.first { it.applicability ==
CandidateApplicability.UNSAFE_CALL } can throw NoSuchElementException.

#KT-57776 Fixed
2023-04-12 14:03:39 +00:00
Nikolay Lunyak f0720c1d12 [FIR] Fix K2 behavior according to RULES1
The compiler should only report diagnostics for
comparisons over builtins and identity-less types,
other incompatibilities should be reported
via inspections.

It's ok that in `equalityChecksOnIntegerTypes`
instead of `EQUALITY_NOT_APPLICABLE_WARNING` we get
`EQUALITY_NOT_APPLICABLE`, because
`ProperEqualityChecksInBuilderInferenceCalls`
is already active by default.

This change also replaces the notion of a representative superclass
with the least upper bound.
This makes complex types like
intersection/flexible transparent to
RULES1-based compatibility checks.
One way to look at it is to think
that this is an automatic way of handling
type parameters: automatic picking of
"interesting" bounds, and checking them against one another.

Note that `TypeIntersector.intersectTypes`
for `Int` and `T` where `T` is a type parameter
may return both `{Int & T}` or `null`
depending on `T`-s bounds. At the same time,
for type parameters `T` and `K` it will
always return `{T & K}`.

`ConeTypeIntersector.intersectTypes`, on the
other hand, will always return `{Int & T}`
irrespectively of the bounds. Meaning, the two
intersectors differ in corner cases.

`lowerBoundIfFlexible` call in `isLiterallyTypeParameter` is backed by
the `equalityOfFlexibleTypeParameters` test.

^KT-35134 #fixed-in-k2
^KT-22499 #fixed-in-k2
^KT-46383 #fixed-in-k2
2023-03-31 15:01:50 +00:00
Denis.Zharkov 55a58e54fe K2: Rework scopes for types with projection arguments for Out types
The only case when behavior is change is described at
 computeNonTrivialTypeArgumentForScopeSubstitutor

The idea is to avoid depending on the presence of @UnsafeVariance
and instead approximate captured types in covariant argument positions
before building substitution scopes

It's correct because for Captured(*) <: Supertype,
Out<Captured(*)> <: Out<Supertype> and when we've got @UnsafeVariance
value parameters at Out, it's ok to allow passing Supertype there.

^KT-57602 Fixed
^KT-54894 Fixed
2023-03-29 10:45:40 +00:00
Kirill Rakhman 1f0d56e157 [FIR] Make type parameters inaccessible for non-inner nested types
#KT-57209
2023-03-28 13:20:53 +00:00
Dmitrii Gridin 9a4a3d1f49 [LL FIR] introduce test with reversed resolve order
^KT-56543

Merge-request: KT-MR-9299
Merged-by: Dmitrii Gridin <dmitry.gridin@jetbrains.com>
2023-03-22 17:34:07 +00:00
Ivan Kochurkin e49bb1fe37 [FIR] Support of REDECLARATION for local val/var, ^KT-54405 Fixed 2023-03-21 20:24:57 +00:00
Nikolay Lunyak c7a71fec17 [FIR] KT-56877: Allow referencing implicit receivers in class contracts 2023-03-09 09:43:02 +00:00
Kirill Rakhman f946ddeb40 [FIR] Implement checks for contract not allowed
^KT-55423 Fixed
2023-03-09 08:32:02 +00:00