Commit Graph

1227 Commits

Author SHA1 Message Date
Dmitrii Gridin 2cac922cd0 [FIR] add tests on external annotations
Tests are excluded in COMPILED_JAVA mode because in this
mode external annotations are not present at all

^KT-62310
2023-10-13 12:16:12 +00:00
Marco Pennekamp b9e3d848a6 [AA] Add KotlinPackageProviderMerger
- In parallel to Kotlin declaration provider merging, we need a proper
  merging strategy for package providers as well, because resolve
  extensions may define additional package providers.
- Additionally, other non-scope-based package providers may be added in
  the future, and the merger preserves these out of the box.

^KT-61791
2023-10-12 16:10:32 +00:00
Jaebaek Seo a6c432587f K2: Add extension point for additional KDoc resolution
Similar to K1 KDocLinkResolutionService used by Fe10KDocReference (to
support additional KDoc resolution), this commit adds K2 counterpart
AdditionalKDocResolutionProvider and uses it for KDocReferenceResolver.

^KT-62187
2023-10-12 15:17:31 +00:00
Roman Efremov a05b37c652 [K2] Support reporting of SUPERTYPE_INITIALIZED_IN_EXPECTED_CLASS
...on regular classes and enum entries.

^KT-59979 Fixed
2023-10-12 13:01:40 +00:00
Anna Kozlova 1f4d985b7b [AA] include inferred types in functional exp expected type
Fixed for K2 only, k1 remains as is

^KT-62466 fixed
2023-10-10 14:06:48 +00:00
Ilya Kirillov c32e7c723d [Analysis API] resolve [this] in KDoc to extension receiver
^KT-62407 fixed
2023-10-10 14:03:49 +00:00
Marco Pennekamp ab717c25d7 [AA] Avoid duplicate inner classes in Java declared member scopes
- Java combined declared member scopes are implemented as a composition
  of the non-static and static scope, so we have to exclude inner
  classes from the non-static scope to avoid duplicates.
- This is not an issue for Kotlin combined declared member scopes,
  because the combined scope is already the base scope.

^KT-61800
2023-10-10 13:38:00 +00:00
Marco Pennekamp 17b8d59e4b [AA] Include inner classes in non-static Java declared member scopes
- `FirNoClassifiersScope` erroneously filtered out inner classes from
  non-static Java declared member scopes.

^KT-61800
2023-10-10 13:38:00 +00:00
Marco Pennekamp 17e181885f [AA] Restrict FirJavaDeclaredMembersOnlyScope to non-local classes
- Comparing the callable ID with the owner's class ID is the simplest
  way to check whether a callable is declared inside an owner class.
  However, this does not work for local classes, because they do not
  have proper class IDs. The same issue occurs when trying to get the
  containing class, because it is a lookup tag search in symbol
  providers.
- Given that the scope is only needed for Java classes and local Java
  classes cannot leak from function bodies, the easiest solution is to
  disallow creating this scope for local classes.

^KT-61800
2023-10-10 13:38:00 +00:00
Marco Pennekamp 3d1262140d [AA] Add member scope tests for inner classes
^KT-61900
2023-10-10 13:38:00 +00:00
Marco Pennekamp 9fa0dfe4bc [AA] Allow inner classes in non-static declared member scopes
- An inner class `Inner` in a class `Outer` is accessible as
  `Outer().Inner()` and should thus be part of the non-static declared
  member scope.
- Related issue containing a discussion about inner classes in use-site
  scopes: KT-62023.

^KT-61800
2023-10-10 13:38:00 +00:00
Marco Pennekamp 239cfa6d29 [AA] Add tests for combined declared member scopes
^KT-61800
2023-10-10 13:38:00 +00:00
Marco Pennekamp 5679acbbdb [AA] Remove classifiers from non-static declared member scopes
- The semantics of a non-static declared member scope should be as
  follows: For a variable `c: C` of class type `C`, the declared member
  scope should contain all members `x` accessible as `c.x` (visibility
  notwithstanding) which are *also* explicitly declared in `C`.
- Classifiers are not accessible as properties of a variable `c`, only
  as static members of the class `C` itself, so non-static declared
  member scopes should not contain any classifiers.

^KT-61800
2023-10-10 13:38:00 +00:00
Marco Pennekamp 8b24baade9 [AA] Refactoring: Simplify JavaClassDeclaredMembersEnhancementScope
- `JavaClassDeclaredMembersEnhancementScope` actually had nothing to do
  with Java enhancement, so it is easily replaceable with a more general
  `FirDeclaredMembersOnlyScope`.

^KT-61800
2023-10-10 13:38:00 +00:00
Marco Pennekamp 1408556511 [AA] Refactoring: Rename AbstractMemberScopeByFqNameTest to AbstractMemberScopeTest
^KT-61900
2023-10-10 13:38:00 +00:00
Marco Pennekamp 9db9f58fba [AA] KtFirSymbolProviderByJavaPsi: Remove workaround for missing static callables in Java declared member scopes
- Now that combined declared member scopes for Java classes contain
  static callables, we don't need to search symbols in the static member
  scope. (Note that the static member scope is too broad for this use
  case, as it contains symbols from superclasses, but we only need to
  look at declared members because the correct `containingClass` is
  already chosen.)

^KT-61901
^KTIJ-25126
2023-10-10 13:38:00 +00:00
Marco Pennekamp df54540a81 [AA] Update usages of declared member scopes
- Now that non-static declared member scopes don't contain static
  callables anymore, we have to update some usages in the Analysis API.
- In symbol light classes, many usages of `getDeclaredMemberScope` can
  be kept as-is because Kotlin classes/objects generally cannot declare
  static callables (and we do not need to create symbol light classes
  for Java classes). The only exception are enum classes, which
  implicitly declare some static callables.

^KT-61800
2023-10-10 13:38:00 +00:00
Marco Pennekamp 21efd6aff3 [AA] Add tests for *static* (declared) member scopes
^KT-61900
^KT-61800
2023-10-10 13:38:00 +00:00
Marco Pennekamp c2d08b9462 [AA] Add additional tests for declared member scopes and member scopes
^KT-61800
2023-10-10 13:37:59 +00:00
Marco Pennekamp dc689952cb [AA] Fix isDeclared for static callables in Java declared member scope
- Static callables don't have a `dispatchReceiverType`, but certainly a
  `CallableId`.

^KT-61800
2023-10-10 13:37:59 +00:00
Marco Pennekamp 71017298d9 [AA] Provide separate non-static and static declared member scopes
- Member scopes already don't contain static callables, only their
  static member scope counterparts. However, declared member scopes
  contained both non-static and static callables, which was confusing to
  users. See for example KT-61255.
- Now declared member scopes only contain non-static callables and
  static declared member scopes only contain static callables.
- In `KtFirScopeProvider`, the new implementation is different for
  Kotlin and Java classes, because the standard declared member scope
  doesn't work for Java. Instead, we have to get the Java *enhancement*
  scopes from `JavaScopeProvider`. Unfortunately, `JavaScopeProvider`
  doesn't have a direct enhancement declared member scope. This results
  in a somewhat complex scope structure with the declared members filter
  scope around the use-site/static Java enhancement scope, but since the
  declared members filtering scope properly reduces the set of callable
  names and scopes in general are cached, this shouldn't be an issue.
- `getCombinedDeclaredMemberScope` is introduced as a separate public
  function because for Kotlin scopes, we don't actually have to create a
  combined scope, as the non-static and static scopes are just filters
  around a combined declared member scope provided by the compiler. It's
  also important to have a convenient function to get the combined
  declared member scope, because some usages explicitly want access to
  all declared members (such as symbol light classes).
- This commit also fixes KT-61901, because
  `getFirJavaDeclaredMemberScope` now provides a proper static scope for
  Java classes, which will be accessible via the combined declared
  member scope as well.

^KT-61800 fixed
^KT-61901 fixed
^KT-61255 fixed
2023-10-10 13:37:59 +00:00
Ivan Kochurkin ec5fd02ab9 [FIR] Enable FirSuperCallWithDefaultsChecker for Native
It's enabled for JVM and Native in K1
2023-10-06 12:29:01 +00:00
Ilya Kirillov 9dcd142f0d fixup! [Analysis API] implement an API to get a substitution based on a inheritance relationship between classes 2023-10-06 11:39:33 +00:00
Ilya Kirillov 15e4cbc10d [Analysis API] implement an API to get a substitution based on an inheritance relationship between classes
^KT-62090 fixed
2023-10-06 11:39:33 +00:00
Ilya Kirillov 49cfbb0576 [Analysis API] remove duplicating logic for building KtSubstitutor by ConeSubstitutor 2023-10-06 11:39:33 +00:00
Ilya Kirillov 1107e728a2 [Analysis API] implement better rendering for chained KtSubstitutor 2023-10-06 11:39:33 +00:00
Ilya Kirillov 68c7673cb3 [Analysis API FIR] fix ISE "Status should be resolved for a declaration to create it fake override"
on calling completion on an instance of `kotlin.Pair`.

Caused by unresolved status for `copy` created for data classes from a library.

^KT-62268 fixed
2023-10-05 17:01:40 +00:00
Anna Kozlova da385210d8 [AA] provide psiType#asKtType conversion
it's useful for IDE's features such as write UAST or refactorings

^KT-62302 fixed

Merge-request: KT-MR-12414
Merged-by: Anna Kozlova <Anna.Kozlova@jetbrains.com>
2023-10-05 15:18:55 +00:00
Brian Norman 365ce2a6a5 [FIR] Implement checker for missing dependency supertypes
#KT-60778 Fixed
2023-10-04 21:57:43 +00:00
Egor Kulikov 057973f4bb [FIR] Fix NPE on invalid gets with index
^KT-60342 fixed
2023-10-03 22:34:46 +00:00
Ivan Kochurkin 319fb967ec [FIR] Add TYPE_ARGUMENTS_FOR_OUTER_CLASS_WHEN_NESTED_REFERENCED diagnostics
Report TYPE_ARGUMENTS_FOR_OUTER_CLASS_WHEN_NESTED_REFERENCED instead of
WRONG_NUMBER_OF_TYPE_ARGUMENTS where it's appropriate

^KT-59393 Fixed

Simplify FirTypeResolverImpl
2023-10-03 19:49:56 +00:00
Alejandro Serrano Mena 310e89f100 [FIR] Report type-aliased 'Nothing' as return type
This warning was issued in K1, but lost in K2

^KT-59420 Fixed
^KT-59429 Fixed
2023-10-03 06:22:35 +00:00
Roman Efremov 81fd9a679d [FIR] Prohibit expect class members with default values actualized
...by fake-override.
It is error without deprecation cycle because `expect` and `actual`
classes are still in Beta and expected impact of change is negligible.

^KT-62036 Fixed
2023-10-02 15:50:37 +00:00
Yan Zhulanow bd6d492b0c [LL API] Compile code fragment together with its context file
Recently, 'KtFirCompilerFacility' started to compile files from
dependent modules separately. Until recently, the code fragment was
in the same module as its context, so they naturally went in the same
compilation round. Now a separate 'KtCodeFragmentModule' is created,
so the code fragment case has to be handled explicitly.

This fixes the following groups of tests:
- FirIdeNormalAnalysisLibrarySourceModuleCompilerFacilityTestGenerated
- K2IdeK2CodeKotlinEvaluateExpressionTestGenerated (in IntelliJ)
2023-09-22 19:26:21 +00:00
Ilya Kirillov 1ace71a907 [Analysis API] allow completion from non-physical files
Needed for injection

^KTIJ-21127
2023-09-22 17:42:51 +00:00
Yan Zhulanow 0f33f82ffc [LL API] Fix reflective patching for field accesses
Implement the same behavior as in K1 evaluator. Also see
'IRFragmentCompilerCodegen#codegenFactory' in the IntelliJ project.

The commit fixes the following failing tests in the IntelliJ project:
- K2IdeK2CodeKotlinEvaluateExpressionTestGenerated$SingleBreakpoint$CompilingEvaluator$InaccessibleMembers.testPrivateAnnotationCompanionValue
- K2IdeK2CodeKotlinEvaluateExpressionTestGenerated$SingleBreakpoint$CompilingEvaluator$InaccessibleMembers.testSelfMembers
- K2IdeK2CodeKotlinEvaluateExpressionTestGenerated$SingleBreakpoint$CompilingEvaluator$InaccessibleMembers.testOuterMembers
- K2IdeK2CodeKotlinEvaluateExpressionTestGenerated$SingleBreakpoint$Uncategorized.testPrivateMember
- K2IdeK2CodeKotlinEvaluateExpressionTestGenerated$SingleBreakpoint$Uncategorized.testProperties
- K2IdeK2CodeKotlinEvaluateExpressionTestGenerated$SingleBreakpoint$Uncategorized.testPrivatePropertyWithExplicitDefaultGetter
- K2IdeK2CodeKotlinEvaluateExpressionTestGenerated$SingleBreakpoint$Uncategorized.testPrivateClass
2023-09-22 12:20:05 +00:00
Yan Zhulanow 9ef58f2bdb [LL API] Collect syntax errors in 'KtFirCompilerFacility'
^KTIJ-27167 Fixed
2023-09-22 11:39:49 +00:00
Dmitriy Novozhilov 9e5ee3afa0 [FE] Add isLocal name to ClassId constructor calls where it needed 2023-09-21 12:40:44 +00:00
Mikhail Glukhikh 326d68c1f4 Drop separate K1/K2 implementations of generateMetadataExtraFlags
Related to KT-62056
2023-09-21 11:14:09 +00:00
Nikolay Lunyak 8755cf75ac [FIR] Improve the messages of the multiple defaults diagnostics
Mention the base functions where the default
values come from.
2023-09-21 07:48:30 +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
Kirill Rakhman 99b852adf8 [FIR] Refactor constructors of ConeTypeRenders 2023-09-21 07:18:19 +00:00
Yan Zhulanow 834cbaac5a [LL API] Run fir2ir separately for files in different modules
Each module may have its own compiler configuration.

^KTIJ-27061 Fixed
2023-09-21 06:19:15 +00:00
Roman Efremov ad4d1a5ba8 [IR] Support ACTUAL_ANNOTATION_CONFLICTING_DEFAULT_ARGUMENT_VALUE in K2
It's implemented as IR checker because in K2 constant expressions are
evaluated on backend. FIR diagnostic removed because isn't needed.

"annotationViaActualTypeAlias" test has no `// FIR_IDENTICAL` because
diagnostic reported on entire typealias declaration instead of its name.
This is because in IR+LightTree we have only offsets, so can't navigate
to typealias name element.

^KT-59940 Fixed
2023-09-20 15:40:37 +00:00
Nikolay Lunyak ec9cb8beb6 [FIR] Rename JvmNames -> JvmStandardClassIds
This is more consistent with the code of
the common compiler checkers.

It would be nice to refactor the contents
of this object further, but it's out
of scope of the current branch.

^KT-54596
2023-09-19 22:14:09 +00:00
Nikolay Lunyak 986f1624ec [FIR] Remove jvm-specific annotations from common compiler code
^KT-54596 Fixed
2023-09-19 22:14:09 +00:00
Ilya Chernikov e5ee364419 IC: Implement expect/actual tracking
fixes NewMultiplatformIT.testIncrementalCompilation
also #KT-61590 fixed
2023-09-19 15:46:30 +00:00
Yan Zhulanow 40ecd4bc1e [fir2ir] Fix annotation conversion on partial module compilation
Backend requires annotation constructors to be fully resolved for the
'IrConst' default value lowering. However, in the IDE there is usually
no need in complete annotation class resolution.

^KTIJ-27061 Fixed
2023-09-18 19:48:08 +00:00
Roman Golyshev a78d631b16 KTIJ-27050 [Analysis API] Correctly handle type parameters in KtFirReferenceShortener
Make `FirShorteningContext` correctly return symbols for type
parameters, so they are not ignored when scopes are inspected

Add additional type of `PartialOrderOfScope` - `TypeParameter`, because
otherwise it would have been classified as `Unclassified`, and that
breaks scopes comparison

Add missing type parameters to the scope of class header in
`ContextCollector`, add testdata for that

There is a bug in the compiler with type parameters leaking to nested
classes headers (KT-61959). After it's fixed, the testData with
incorrect expected shortenings/scopes should be adjusted and fixed too

^KTIJ-27050 Fixed
2023-09-18 10:23:30 +00:00
Roman Golyshev e2019ceb95 KTIJ-27050 [Analysis API] Refactor FirShorteningContext
Use `AvailableSymbol<FirClassLikeSymbol<*>>` instead
of `AvailableSymbol<ClassId>`
2023-09-18 10:23:29 +00:00