Commit Graph

641 Commits

Author SHA1 Message Date
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
Alexander.Likhachev 6eaccc997f [Build] Fix the typo junit jupyter -> jupiter 2023-09-06 22:47:34 +00:00
Alexander.Likhachev 6f96be0b76 [Build] Get rid of the testApiJUnit5 method
#KTI-1349 In Progress
2023-09-06 22:47:34 +00:00
Alexander.Likhachev 0ecbb64c64 [Build] Remove testApiJUnit5 parameters
Instead of declaring additional dependencies inside the method, declare them directly
#KTI-1349 In Progress
2023-09-06 22:47:34 +00:00
Alexander.Likhachev ef0fb557a5 [Build] Split junit-jupiter into api and engine
#KTI-1349 In Progress
2023-09-06 22:47:33 +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
Dmitriy Novozhilov d8b542c68d [Test] Allow testcases with number 0 in spec test
There was a hidden bug which was uncovered by KT-58936
2023-05-26 18:26:45 +03: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
Kirill Rakhman 3b9724d20e [FIR] Desugar increment/decrement in body resolve phase
The expression needs to be resolved first to determine if there is a
receiver that needs to be extracted to a temporary variable. Also, the
special case for prefix increment/decrement on local variable without
delegates requires resolution to check if the variable is local.

^KT-56771 Fixed
^KT-56659 Fixed
2023-03-02 10:19:57 +00:00
Kirill Rakhman 5ecf9cce25 [FIR] Don't resolve already resolved qualified access
^KT-30507 Fixed
2023-03-02 10:19:53 +00:00
Dmitriy Novozhilov da581f38e1 [Test] Require specifying parser for FIR test. Unify names for FIR tests
Now all tests with `Fir` in name are named accordingly to parser which
  is used in them -- `FirPsi` or `FirLightTree`. This is needed to keep
  consistency between different types of tests, because there is no
  single default in parser mode between different scenarios of using FIR
2023-02-24 11:15:26 +00:00
Denis.Zharkov 8ac39dc284 K2: Adjust spec test data behavior with KT-55725
^KT-55725 Related
2023-02-15 08:13:55 +00:00
Denis.Zharkov 7b6c6fceb6 K2: Adjust test data for KT-55698
It started being reported after we stopped ignoring diagnostics
on synthetic calls.
2023-02-15 08:13:54 +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
Denis.Zharkov dcdc48a233 K2: Support callable references adaptation on top-level
^KT-45989 In progress
^KT-54709 Related
^KT-55217 Fixed
2023-02-15 08:13:44 +00:00