Commit Graph

797 Commits

Author SHA1 Message Date
Ilya Goncharov 3673dff959 [FIR] Only one specific diagnostic for data class without parameters left
^KT-60042 fixed
2023-11-01 13:58:44 +00:00
Kirill Rakhman ac203591e5 [FE, Java resolve] Support inheritors of sealed Java type without permits clause
This fixes a false negative NO_ELSE_IN_WHEN in K2 and incidentally
also fixes a false positive NO_ELSE_IN_WHEN in K1 since the fix is in
the common code.

#KT-62491 Fixed
2023-10-31 13:41:56 +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
Kirill Rakhman 2613a337ae [FIR] Improve symbol rendering in *_NOT_IMPLEMENTED diagnostics 2023-10-27 13:27:35 +00:00
Kirill Rakhman 44a4498ee5 [FIR] Report ABSTRACT_MEMBER_NOT_IMPLEMENTED_BY_ENUM_ENTRY on enum entries with initializer
#KT-59577 Fixed
2023-10-27 13:27:35 +00:00
Evgeniy.Zhelenskiy a77349edb4 [FIR] Report INAPPLICABLE_INFIX_MODIFIER on vararg parameter, position INAPPLICABLE_INFIX_MODIFIER on infix keyword
#KT-59974
2023-10-26 20:07:50 +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
Dmitriy Novozhilov 0325ffaa01 [FIR] Properly handle nested annotations on compiler-required annotation phase
There was a case when we visited the same declaration multiple times
  because of forward-referencing and visiting with designation
So because of this there were two changes required:
- remove assertion about visiting the same declaration twice (it's fine
  since we don't actually resolve annotations twice)
- not skipping resolution of class children if annotations on this class
  are already resolved

^KT-61388 Fixed
KT-62854
2023-10-24 11:44:21 +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
Nikolay Lunyak fedadfb8db [FIR] Show ARGUMENTS_MAPPING_ERROR diagnostics along with INAPPLICABLE
K1 reports `ARGUMENT_TYPE_MISMATCH`
and `TOO_MANY_ARGUMENTS` together, and
one way to do it in K2 is to say that
their kinds of inapplicability difference
is not relevant to the user.

Note that K1 doesn't do such filtering,
so this change "makes K2 closer to K1",
but still different.

^KT-62541 Fixed

fixup! [FIR] Show ARGUMENTS_MAPPING_ERROR diagnostics along with INAPPLICABLE
2023-10-19 09:27:45 +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
Ivan Kochurkin 2d61b9a477 [FIR] Elvis operator: flexible rhs type implies flexible type of whole elvis
It's required for further removing of enhancement of final static fields

Also, it's k2-potential feature

^KT-62467 Fixed
2023-10-16 17:16:56 +00:00
Nikolay Lunyak 41c3f98419 [FIR] Make resolution of classes in FirProvider more reasonable.
See the `privateInFile.fir.kt` test.
Type mismatches are simply confusing.

`inheritorOfExpectSealedClass.out`
reports unresolved reference probably
because now it resolves into the expect
declaration, rather than the actual one.
K1 doesn't report UNRESOLVED_REFERENCE
in this case. But this is red code
anyway. And this behavior still
depends on the order in which the compiler
receives both the declarations.

^KT-59927
^KT-62567
2023-10-13 11:56:54 +00:00
Nikolay Lunyak 09436d0480 [FIR] Report conflicts for constructors of top-level classes
^KT-59880
2023-10-11 08:54:09 +00:00
Evgeniy.Zhelenskiy feed3a57d0 [FIR] Report wrong modifiers in function type arguments and types of value parameters
#KT-59955
2023-10-06 12:22:57 +00:00
Mikhail Glukhikh ae19cd91bf K2: fix "private to this" determination logic in accordance with K1
#KT-61844 Fixed
2023-09-22 12:23:46 +00:00
Ilya Kirillov 252c59a8a3 [FIR] Render k2-specific flexible types in a more compact way in diagnostic messages
^KT-62031 fixed
2023-09-22 10:48:31 +00:00
Ilya Kirillov e2252f5e6b [FIR] add testcase for KT-62031 2023-09-22 10:48:31 +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
Kirill Rakhman 4e1dfcd2a8 [FIR] Improve readability of rendered types in diagnostics
#KT-61824 Fixed
#KT-61688 Fixed
2023-09-21 07:18:19 +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
Kirill Rakhman 9949de36c9 [FIR] Fix false negative ARRAY_EQUALITY_OPERATOR_CAN_BE_REPLACED_WITH_EQUALS
... in presence of typealiases.

#KT-61921
2023-09-18 12:13:02 +00:00
Kirill Rakhman 9475bc250c [FIR] Fix false negative REDUNDANT_CALL_OF_CONVERSION_METHOD
... in presence of typealiases.

#KT-61921
2023-09-18 12:13:01 +00:00
Kirill Rakhman e788c7166a [FIR] Fix false negative REDUNDANT_SINGLE_EXPRESSION_STRING_TEMPLATE
... in presence of typealiases.

#KT-61921
2023-09-18 12:13:01 +00:00
Kirill Rakhman ce65d3c7b8 [FIR] Set source on callee reference of implicit invoke receiver
This fixes an IllegalArgumentException when a diagnostic was reported on
it because no source was set.

#KT-61829 Fixed
2023-09-13 12:20:57 +00:00
Kirill Rakhman 2566dabfce [FIR] Report INVISIBLE_REFERENCE on the first unresolved qualifier
#KT-61719 Fixed
2023-09-11 14:23: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
Kirill Rakhman 393a5d6c14 [FIR] Fix IAE in TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM
IllegalArgumentException: class
org.jetbrains.kotlin.psi.KtLambdaArgument is not a subtype of class
org.jetbrains.kotlin.psi.KtExpression for factory
TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM
was reported when TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM was
reported on a FirLambdaArgumentExpression, report it on its
`expression` instead.

#KT-60380 Fixed
2023-09-06 07:38:34 +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
Kirill Rakhman 10f7989af6 [FIR] Report UNRESOLVED_REFERENCE on the first unresolved qualifier
#KT-55471 Fixed
2023-09-04 08:05:07 +00:00
Nikolay Lunyak 0d19942d2c [FIR] Make reporting of local class diagnostics more consistent with K1
It would be nice to report more appropriate diagnostics at the
corresponding places, but right now it's more important to
fix greenness-redness problems. Plus, this is already how K1 works.

^KT-59900 Fixed
2023-08-31 13:07:00 +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
Brian Norman 833072e1fb [FIR] Add checker for MISSING_DEPENDENCY_CLASS
#KT-59371 Fixed
2023-08-28 15:00:04 +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
Kirill Rakhman 8d7c5b375e [FIR] Replace usages of FirExpression.typeRef with coneTypeOrNull
#KT-59855 Fixed
2023-08-24 07:54:57 +00:00
Brian Norman 7db551c452 [FIR] Property accessors are not part of class initialization
When checking for class val property reassignment diagnostic, property
initializers should be treated as part of the class initialization.
However, property accessors should not. Previously, only the property
itself was checked for both of these situations and resulted in not
reporting diagnostic within property accessors.

#KT-59744 Fixed
2023-08-22 13:28:36 +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 2c16c9a35b [FIR] Remove a hack about local classes
^KT-54390 Fixed
2023-08-18 13:31:04 +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
Kirill Rakhman 5b9c35de2e [Tests] Update test data with error suppression warnings
#KT-61129 Fixed
2023-08-18 13:29:20 +00:00
Nikolay Lunyak 71cc634a7c [FIR] Prevent missing diagnostics on free lambdas
The change in `FirPsiDiagnosticTestGenerated.Resolve#testCast`
only highlights the existing
problem that we don't assign a
valid type to `_`.

^KT-58906 Fixed
2023-08-08 11:00:04 +00:00
Nikolay Lunyak 7151e6a41c [FIR] Report UNSUPPORTED_CONTEXTUAL_DECLARATION_CALL
^KT-59969 Fixed
2023-08-04 15:17:21 +00:00
Nikolay Lunyak c2ad475153 [FIR] Render outer type parameters differently 2023-08-04 11:20:40 +00:00
Nikolay Lunyak 97b00793b4 [FIR] Prevent duplicate direct overridden-s from substitution overrides
This change prevents going up the scopes once we find a
substitution override. Whatever we'd find by going further is not
going to be a direct overridden anymore, so it would lead to incorrect
results when collecting direct overridden-s. Without this change, we get
error modules in FT intellij.
2023-08-04 11:20:40 +00:00
Nikolay Lunyak bca44e5d8c [FIR] Prepend type variables with '+' rather than '_'
'++' is easier to notice than '__'.
'++++++' is easier to count than '######'.
2023-08-04 11:20:39 +00:00
Kirill Rakhman ade1354a84 [FIR] If callable reference can't be resolved with expected type, try resolving with Any
In positions outside of calls (e.g. property initializers)
we resolve callable references using a synthetic outer call with the
expected type as parameter type.
If this fails, we previously returned an unresolved reference.
After this commit, we additionally try to resolve the callable reference
with expected type Any.
This lets us report more precise diagnostics like type mismatches or
when multiple overloads exist NONE_APPLICABLE.

#KT-55373 Fixed
#KT-55955 Fixed
2023-08-02 08:00:33 +00:00
Dmitriy Novozhilov 69a35970eb [FIR] Introduce different synthetic origins for FIR declarations
This is needed to be able to precisely distinguish different synthetic
  declarations (like fields for delegates and functions for data classes)
  in fir2ir
2023-07-28 13:59:38 +00:00