Commit Graph

105170 Commits

Author SHA1 Message Date
Marco Pennekamp dab06c0942 [AA] Cover both static and inner classes in Java member scope tests
^KT-61900
2023-10-10 13:38:00 +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 7a7a923197 [AA] Add getCombinedMemberScope to KtScopeProvider
- The function is mostly for convenience, but scope providers will be
  able to optimize this scope if needed (similar to how combined
  declared member scopes are already optimized).
- `getCombinedMemberScope` will be used by `KDocReferenceResolver`.

^KT-61900
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 4ba0aef23b [AA] Refactoring: Simplify member scope test classes
^KT-61900
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 e5bfcfc9fc [AA] Refine documentation of getMemberScope and getStaticMemberScope
^KT-61900
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
Vyacheslav Gerasimov 8b5f87f15f Build: Fix verification-metadata.xml 2023-10-10 13:53:18 +02:00
Brian Norman ccda8ae23d [FIR] Comparison to String implies smart cast to String
When the left-hand side of an equality comparison is known to be a
String, and the equality condition resolves to true, then the right-hand
side can be smart-cast to a String as well. This was working for String
expressions on the left-hand side but not for String constants.

^KT-57513 Fixed
2023-10-10 11:20:40 +00:00
Artem Daugel-Dauge c19fc3ced3 [Gradle] Fix some macOS Gradle IT 2023-10-10 10:57:08 +00:00
vladislav.grechko f71a731b6b Temporary do not check bytecode listings for some tests
Removing nullability directives from the methods of anonymous classes
affects some bytecode listing tests, but the changes will take effect
only after the advancing of the bootstrap compiler version.

See ^KT-62044
2023-10-10 10:34:33 +00:00
vladislav.grechko 29eb1c7a63 Do not add nullability annotations to the methods of anonymous classes
Nullability annotations are useless for the methods of anonymous classes
due to their restricted scope.

^KT-62044: Fixed
2023-10-10 10:34:33 +00:00
Ilya Goncharov ed247a3892 [JS] Remove kotlin-archetype-js
^KT-54868 fixed
2023-10-10 09:16:14 +00:00
Dmitrii Krasnov 9bda7571fd [Gradle IT] Removed old configuration for K/N IT
#KT-51553 Fixed
2023-10-10 09:10:14 +00:00
Nikita Bobko ad6680d128 Cleanup: return empty Map instead of null
Motivation: nullable collections are an anti-pattern
Review: https://jetbrains.team/p/kt/reviews/12279/timeline
2023-10-10 09:02:07 +00:00
Nikita Bobko 91a337074e Refactoring: Improve createExpectActualTypeParameterSubstitutor API
Review: https://jetbrains.team/p/kt/reviews/12279/files

Motivation: make sure that cases like KT-62027 won't happen again
Review: https://jetbrains.team/p/kt/reviews/12279/files

Now it's responsibility of the
`createExpectActualTypeParameterSubstitutor` calller to think about the
case when parameters size isn't equal. You must not be able to create a
substitutor if type parameters sizes are not equal

Improvement in `createExpectActualTypeParameterSubstitutor` API also
improves
`AbstractExpectActualCompatibilityChecker.getCallablesCompatibility`
API.

Because suppose that you accidentally created a redundant wrapping
substitutor => you need to handle the case of not equal type parameters
size on the call site => you start thinking why you should do that on
the call site? It must be a responsibility of
`getCallablesCompatibility` => you realize that you created a redundant
wrapping substitutor
2023-10-10 09:02:07 +00:00
Nikita Bobko 211102569c K2 KMP: Don't create invalid ConeSubstitutor when type parameters size doesn't match
When type parameters size doesn't match, it's better to pass `null`
instead of a parentSubstitutor. Before this commit we were creating an
invalid substitutor. Who knows what can go wrong because of that further
along the execution

Related issue: KT-54827
Related test: compiler/testData/diagnostics/tests/multiplatform/kt54827.kt
Review: https://jetbrains.team/p/kt/reviews/12279/files

Motivation for the commit: There is no user report or anything. It's not
known whether these invalid substitutors were causing problems. I just
noticed this problem while doing substitutor API refactoring (see the
next commit).

Note: `ExpectedActualResolver.matchActualCallableAgainstPotentialExpects`
has the same problem. But since it's K1 I won't touch it
2023-10-10 09:02:07 +00:00
Dmitrii Gridin 5ebef0dfd1 [LL FIR] simplify common library symbol provider
createCommonLibrarySymbolProvider is simplified to avoid module clashes
and extra search

^KTIJ-27159
^KT-58325
2023-10-09 22:47:32 +00:00
Brian Norman 79303ab2db [FIR] Ignore anonymous functions during annotation argument phase
Anonymous functions (lambdas) are not allowed as annotation arguments.
However, because it is still possible to parse code written this way, it
must be handled without exception. So ignore these expressions when
processing annotation arguments.

#KT-59565 Fixed
2023-10-09 20:03:33 +00:00
Marco Pennekamp 223c793258 [SLC] Order parent classes before nested classes in structure test results
- This improves the readability of the result files.
2023-10-09 19:46:51 +00:00
Marco Pennekamp 9ac639e0d3 [PSI] Add forEachDescendantOfTypeInPreorder
- `forEachDescendantOfTypeInPreorder` is a preorder variant of
  `forEachDescendantOfType`, which operates in postorder.
2023-10-09 19:46:51 +00:00
Marco Pennekamp cd8143af7b [SLC] Fix nested classes missing in SLC structure tests for libraries
^KT-62038 fixed
2023-10-09 19:46:51 +00:00
Marco Pennekamp 315573d99f [SLC] Add SLC structure tests for nested classes
^KT-62038
2023-10-09 19:46:51 +00:00
Pavel Kunyavskiy 4175a0d258 [K/N] Enable test muted because of wrong test infra setup
^KT-61773
2023-10-09 16:52:15 +00:00
Dave MacLachlan c820e82db3 Native: remove linker warning when building libllvmstubs
Building with macOS gave the linker warning
`ld: warning: ignoring duplicate libraries: '/Users/foo/.konan/dependencies/apple-llvm-20200714-macos-aarch64-1/lib/libclangEdit.a'`

Remove duplication from the build script to get rid of the warning.

Co-authored-by: Dave MacLachlan <dmaclach@gmail.com>
2023-10-09 16:49:16 +00:00
Alexander Udalov 9164b7d405 K2 kapt: remove reference to "kapt 4" from the warning
#KT-62438 Fixed
2023-10-09 16:08:45 +00:00
Anna Kozlova 79193006ce [LC] light methods should provide type parameters for on the fly resolve
References inside LC apis are build over `ClsJavaCodeReferenceElement`,
which simplifies resolve by providing precalculated data.
When refactorings or quick fixes do on the fly resolve,
giving only text and LC context,
such precalculated data is not available and normal resolve starts.
In order for this resolve to work correctly,
LC should provide available declarations

Corresponding test in monorepo: `KotlinSymbolOnAirResolveTest`

^ KT-62440 fixed
2023-10-09 15:42:52 +00:00
Alexander.Likhachev afdd8466cc [Gradle] Introduce KotlinBuildStatsServicesRegistry to manage FUS services
KT-57371 introduced a legacy JMX service without proper management.
#KT-62318 Fixed
2023-10-09 13:44:29 +00:00
Alexander.Likhachev bb23602cb3 [Gradle] Do not hold a reference to Gradle objects in FUS services
Despite the FUS services are intended to be scoped to a build, the legacy compatibility service wasn't properly managed and that caused a significant memory leak together with changes in KT-59826.
#KT-62318 In Progress
2023-10-09 13:44:29 +00:00
Ilmir Usmanov 197f0112b4 Minor. Add regression test for KT-62127
#KT-62127 Fixed
2023-10-09 12:43:27 +00:00
Evgenii Mazhukin 203b7a4da3 [KGP] Treat friendPaths as non-incremental Input property
When friendPaths change, internal symbols from other modules become hidden
or visible. This might change which functions are called, which types
are returned, etc. So we should recompile the affected classes.

Gradle doesn't allow Input policy on FileCollection properties, so we
introduce friendPathsSet. It allows us to keep the ABI of BaseKotlinCompile
unchanged, detect non-incremental configuration changes on Gradle side,
and use normal incremental compilation for everything else.

^KT-61918 Fixed


Merge-request: KT-MR-12372
Merged-by: Evgenii Mazhukin <evgenii.mazhukin@jetbrains.com>
2023-10-09 11:23:02 +00:00
Dmitriy Novozhilov d9ddac5571 Advance bootstrap to 2.0.0-dev-4562 2023-10-09 09:30:38 +00:00
Dmitriy Novozhilov 91667d4e00 [Build] Fix update-bootstrap script 2023-10-09 09:30:37 +00:00
Dmitriy Novozhilov b9744f5315 [Build] Remove incorrect dependency from :kotlin-compiler for JPS build 2023-10-09 07:46:50 +00:00
Nikolay Lunyak 2e7dcd6096 [FIR] Require overrides to have matching isSuspend flag value
^KT-57100 Fixed
2023-10-09 06:55:43 +00:00
Nikolay Lunyak 4e58715760 [FIR] Check conflicting overloads via scopes
Scopes may return private symbols from
supertypes, they should not clash with
symbols from the current class.

For example, see:
`FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated.FakeOverride#testPrivateFakeOverrides1`

Lombok shouldn't generate functions if the
user has defined explicit ones.

In K1 generated functions are not really
added to the declared members scope.

^KT-61243 Fixed
2023-10-09 06:55:43 +00:00
Nikolay Lunyak 973248f432 [FIR] Reproduce KT-57100 2023-10-09 06:55:43 +00:00
Alexander Udalov 3116e26204 CLI: update jansi to 2.4.0 to support colors on arm macs
#KT-62350 Fixed
2023-10-08 20:55:23 +00:00