Commit Graph

10161 Commits

Author SHA1 Message Date
eugenpolytechnic f6e564ffa6 FIR: introduce inline classes checks 2021-03-06 09:22:34 +03:00
Ilya Gorbunov 9cc8f44390 Support mod and floorDiv extensions in constant evaluator
Ignore evaluation tests for floorDiv and mod with FIR for now.
2021-03-05 23:46:57 +03:00
Mikhael Bogdanov 8ff0b1e243 Reports warning on super calls in public-api inline functions 2021-03-05 18:45:07 +00:00
Br0mm dd3bc1a964 FIR: Introduce CONST_VAL_NOT_TOP_LEVEL_OR_OBJECT diagnostic 2021-03-04 16:13:50 +03:00
Vladimir Dolzhenko 72322646cc Temporary disable assertion
Relates to #KT-37702
2021-03-03 14:15:50 +01:00
Andrey Zinovyev b128577508 [KAPT] Some optimizations for stubs generation
* Add index to resolve compiled class by name
* Disable full property resolution
2021-03-03 12:05:49 +03:00
Andrei Klunnyi f45af5ea0e KT-44821 [Sealed Interfaces]: when-exhaustiveness failure in IDE
Compiler check for 'when' exhaustiveness requires that module
descriptors of a sealed class and its inheritors are the same (reference
identity matters). Prior to this commit and under some conditions they
were not. Details follow below.

Resolution related data structures (resolution facades) are organized
into trees (sdks, libs, and modules have their own nodes/facades,
module/class descriptors are stored inside). And the trees themselves
are put into a map associating so called PlatformAnalysisSettings and
GlobalFacades (plays a role of a root). PlatformAnalysisSettings is an
abstraction describing target platform and sdk of a module. The more
combinations exist for a project the more facades are used. Please, see
KotlinCacheService for more details.

So why a module can have multiple ModuleDescriptor-s?
Every tree mentioned above is an isolated resolution environment
containing its own instances of the outer world descriptors. Say, if a
project has modules X, Y, Z and we consider X then all three might have
their own vision of X, i.e. 3 descriptors exist at a time.

What descriptor instance does compiler get?
The path starts when the user opens a file in the editor and
highlighting pass starts (see usages of
ResolutionUtils#analyzeWithAllCompilerChecks). Module descriptor stored
in the resolution tree of the file's module gets injected into the
compiler's context. Starting from this moment compiler sees other
modules through the prism of a single resolution facade (tree).
Descriptors residing outside are alien.

This commit allows IdeSealedClassInheritorsProvider to figure out what
PlatformAnalysisSettings are associated with the resolution facade (read
ModuleDescriptor) seen by the compiler. Later on the same facade is used
to provide correct instances of sealed inheritors back to the compiler.
2021-03-01 12:12:00 +01:00
Dmitry Savvinov 42345b9c49 Minor: use more clear and specific naming for LazyClassContext.typeChecker (relevant for MPP with type refinement) 2021-02-26 12:37:02 +03:00
Dmitry Savvinov 168c692a27 Use overriding util with proper typechecker for overriding in LazyClassMemberScope
Note that LazyClassMemberScope actually has a separate field for
KotlinTypeRefiner, and it might be actually different from the one in
c.kotlinTypeChecker.

The one in c.kotlinTypeChecker is the refiner of *owner* module, i.e. a
module in which the class has been declared. If we have a class Foo :
Expect in common, then the refiner will be from common, and thus it
won't be able to refine supertypes to their platform-dependent values.

The one passed in constructor is actual refiner of dependant-module.
Say, if we're looking at Foo from the point of view of jvmMain, then
we'll create a (view-dependent) LCMS for that, and it will contain
refiner for jvmMain.

It is important to use proper refiner, otherwise the idea of having
"module-dependent view" breaks, and we might suddenly mismatch some
overrides with expect-classes in their signatures.

^KT-44898 Fixed
2021-02-26 12:37:01 +03:00
Dmitry Savvinov e3d4c440b5 Minor: rename createMemberScope -> createScopesHolderForClass 2021-02-26 12:37:01 +03:00
Ilmir Usmanov 62123d72e2 IC: Add inline class -> @JvmInline value class warning 2021-02-25 16:06:47 +01:00
Dmitriy Novozhilov 4222bb9af2 [FE] Make whens on expect sealed classes and enums not exhaustive 2021-02-25 14:56:08 +03:00
Ilya Kirillov f19a9af7b3 Unify WhenMissingCase from FIR and FE1.0 2021-02-24 20:13:43 +01:00
Alexander Udalov 837eb739ea IR: move CompilationErrorException to frontend.common 2021-02-24 19:07:37 +01:00
Alexander Udalov 2e2caae05c Extract control flow analysis to separate module
Extract a service interface out of ControlFlowInformationProviderImpl
and register its implementation in two "leaf" modules: 'cli',
'idea-core'.

This improves parallel build, since a lot of modules depend on
'frontend' but only these two modules reference the implementation and
thus depend on the full CFA implementation now.
2021-02-24 17:17:04 +01:00
Alexander Udalov c744515832 Minor, pass CliSealedClassInheritorsProvider explicitly in some places
Do not use default parameter value for functions with only 1 or 2 call
sites, since it doesn't add much value but provides a dangerous
possibility to forget to pass the real implementation.
2021-02-24 17:17:03 +01:00
Alexander Udalov ca5a35b4b3 Move CompilerEnvironment from 'frontend' to 'cli'
This is needed in order to have a single convenient place where to
register frontend services implemented _outside_ of the 'frontend'
module, such as the control flow analysis, extracted to a separate
module in a subsequent commit.
2021-02-24 17:17:03 +01:00
Alexander Udalov 3efbca85ea Minor, rename file ControlFlowInformationProvider{ -> Impl}.kt 2021-02-24 17:17:03 +01:00
Alexander Udalov 5ad0033d42 Extract some cfg utilities into separate files
These utilties are used not only within CFG, but from the frontend and
idea as well. Therefore upon extraction of CFG into another module,
these two new files will remain in 'frontend'.
2021-02-24 17:17:03 +01:00
Victor Petukhov 4e5647090e Approximate captured types in contravariant positions properly
^KT-43802 Fixed
2021-02-20 16:57:07 +03:00
Mikhail Glukhikh 54139b83ce FIR: fix EXPRESSION_REQUIRED positioning 2021-02-19 18:24:47 +03:00
Mikhail Glukhikh 34c90aab3b FIR: introduce & use REFERENCE_BY_QUALIFIER positioning strategy 2021-02-19 18:24:46 +03:00
Mikhail Glukhikh 5ffa72f1fa FIR: change DOT_BY_SELECTOR to DOT_BY_QUALIFIED strategy 2021-02-19 18:24:46 +03:00
Mikhail Glukhikh 5ca3ce9e37 FIR: introduce & use SELECTOR_BY_QUALIFIED positioning strategy 2021-02-19 18:24:45 +03:00
Dmitriy Novozhilov 88c43e7f7b [FE] Assume that effective visibility of sealed class constructor is internal
#KT-45033 Fixed
#KT-45043
2021-02-19 14:06:49 +03:00
Dmitriy Novozhilov 5ce36a528e [FE] Prohibit sealed fun interfaces
#KT-44947 Fixed
2021-02-17 13:54:10 +03:00
Dmitriy Novozhilov cdf7de5524 [FE] Change message for sealed interfaces with language target < 1.5 2021-02-17 13:51:14 +03:00
Ilmir Usmanov bad197e075 Raise RESERVED_VAR_PROPERTY_OF_VALUE_CLASS to error 2021-02-16 20:59:21 +01:00
Mikhail Glukhikh 940588a9bb FE: commonize throw-related annotation FQ names 2021-02-16 12:38:46 +03:00
Mark Punzalan 4e44804c77 FIR IDE: Add quickfix for INAPPLICABLE_LATEINIT_MODIFIER.
Also changed FE1.0 checker and all related fix factories to report error
on the declaration instead of the lateinit modifier. This is consistent
with the direction of all checkers in FIR (no reporting on modifiers).
2021-02-15 19:37:14 +01:00
Victor Petukhov 0d40022d6d Add reporting of the warnings based on Java annotations for expanded type aliases
Before that, such warnings weren't reported as the corresponding errors were reported during type inference (only original types took part there)
2021-02-15 12:13:55 +03:00
Victor Petukhov d783d99443 Use upper bound checker for typealias expansion 2021-02-15 12:13:53 +03:00
Victor Petukhov befe8599c4 Report warnings or errors for violated type parameter's upper bounds from Java annotated with nullability annotations
^KT-43262 Fixed
2021-02-15 12:13:50 +03:00
Victor Petukhov 6f64fd2fec Propagate inference session into declaration analyzers
It prevents missing inference session for local declaration (local functions, local classes or objects)

^KT-44801 Fixed
2021-02-15 11:12:58 +03:00
Victor Petukhov dae1f4c05d Remove redundant extension receiver substitution during lambda's completion 2021-02-15 11:12:56 +03:00
Dmitriy Novozhilov 7c61ddc72b [FE] Allow declaring protected constructors in sealed classes
#KT-44865 Fixed
2021-02-12 13:36:39 +03:00
Dmitriy Novozhilov 0c0c53cc2e [FE] Don't analyze members with CLASSIFIERS kind filter in AbstractLazyMemberScope
This commit introduces partial support of descriptorKindFilter in
  `AbstractPsiBasedDeclarationProvider`. Without it there may be an error
  in following case:

```
sealed class Base
class Derived : Base()

class Test<out V>(val x: Base) {
    private val y = when (x) {
        is Derived -> null
    }
}
```

Here we start to resolve type of `y`, then go to computation of inheritors
  of sealed class Base, which also may be inside Test, so we need get all
  nested classifiers in Test. But without this filtration we will start
  computing descriptor for `y` again, which leads to ReenteringLazyComputationException

#KT-44316 Fixed
2021-02-10 16:56:49 +03:00
Dmitriy Novozhilov 8dd9d98129 [FIR] Implement checker for exhaustive when's in expression position 2021-02-09 16:04:40 +03:00
Andrei Klunnyi e3c1aa599d KT-44487 [Sealed Interfaces]: sealed-inheritors-provider for MPP 2021-02-09 12:54:51 +00:00
Pavel Kirpichenkov 75954dd1a4 Minor: refactor extended compiler checks
Use an analysis flag instead of a stub language feature
2021-02-08 18:47:30 +03:00
Pavel Kirpichenkov 2a46da906c Provide additional information about missing supertypes
Add -X flag to report extra compiler diagnostics which migth break compatibility.
Use the flag to unconditionally check constructors without fear of
prematurely evaluating lazy supertypes.

KT-19234
KT-42404
KT-44583
2021-02-08 18:47:30 +03:00
Victor Petukhov f9e5584a3e Report error about uninferred type parameter for all CallForImplicitInvoke psi calls
^KT-44368 Fixed
2021-02-08 10:40:18 +03:00
Denis.Zharkov 29ac4cb9cc Minor. Simplify conditions in shouldRunCompletion 2021-02-03 15:05:21 +03:00
Nicola Corti e2b7aba086 Do not report UNNECESSARY_SAFE_CALL on ErrorType 2021-02-02 12:10:56 +03:00
Vladimir Dolzhenko 558338f997 Lazy diagnostics API in frontend
Relates to #KT-37702
2021-02-01 13:18:37 +00:00
Alexander Udalov adfa8c788c Light classes: use JVM target from the module
Using "JVM_1_8" always resulted in incorrect mapping of Kotlin
annotation targets to Java element types.

The change in AbstractKotlinRenderLogTest is needed because while
CliTraceHolder.module is technically a descriptor leak, it was never
detected by this test accidentally, because of the depth cutoff equal to
10, which started to not be enough after the minor refactoring of
replacing `Delegates.notNull` with `lateinit`.
2021-02-01 11:54:05 +01:00
Mikhail Glukhikh 7d4eaefd36 FIR: report UNSAFE_CALL on dot when possible 2021-01-29 16:55:26 +03:00
Denis.Zharkov aab85121e2 Minor. Add clarification comment to MainFunctionDetector 2021-01-29 10:50:22 +03:00
Victor Petukhov ba44ad1aa3 Approximate anonymous return types for private inline functions to explicit supertype or Any (KT-33917) 2021-01-28 13:19:32 +03:00
Mikhail Zarechenskiy d2ce73853d Report more specific diagnostic for variable + invoke calls
Do not report same set of diagnostics for variable call if actual
 error was happened with a function candidate. Here the candidate is
 invoke function on DeepRecursiveFunction

 ^KT-40991 Fixed
 ^KT-41491 Fixed
 ^KT-40926 In Progress
2021-01-22 13:57:47 +03:00