Commit Graph

313 Commits

Author SHA1 Message Date
Yan Zhulanow 34d1611ed4 Add Pill support to compiler and IDE modules 2018-03-02 03:15:17 +03:00
Dmitry Savvinov d570b863ce Introduce deprecation of companion objects nested classes
Introdude deprecation as per KT-21515. Warning is reported on type
usage, that soon will became invisible. Quickfix by adding explicit
import is added.

Idea behind implementation is to mark scopes that are deprecated (see
ClassResolutionScopesSupport).

Then, during walk along hierarchy of scopes, look at deprecation status
of the scope that has provided this classifier.
Note that we also have to check if there are *some* non-deprecated
visibility paths (because we can see classifier by two paths, e.g. if
we've added explicit import) -- then this type reference shouldn't be
treated as deprecated.
2018-02-21 16:04:49 +03:00
Mikhail Zarechenskiy c4cfd07fe9 [NI] Fix infinite completion of arguments in AllCandidates mode
See AutoImports#testFactoryFunctionFromLambda for example
2018-02-13 15:06:34 +03:00
Denis Zharkov 5c81d9fd6b Minor. Make function private 2018-02-08 17:47:37 +03:00
Alexander Udalov 97314d010d Serialize default argument values presence for actual declarations correctly
When default argument value was present in the expected declaration, we
did not correctly serialize that fact to the metadata for the actual
declaration (`declaresDefaultValue` was used). Therefore, it was
impossible to use that actual declaration without passing all parameter
values in another module, where it was seen as a deserialized descriptor

 #KT-21913
2018-02-08 14:11:57 +01:00
Alexander Udalov 22595acbfd Fix AssertionError on overloading function with property in actual class
#KT-22352 Fixed
2018-02-08 14:11:56 +01:00
Alexander Udalov 9e500831dd Allow expect/actual annotation constructors to have default values
When a parameter has a default argument value both in the expected
annotation and in the actual annotation, they must be equal. This check
has been only implemented for the case when actual annotation is Kotlin
source code, and NOT a Java class coming from an actual typealias. The
latter case would require a bit more work in passing a platform-specific
annotation-value-reading component to ExpectedActualDeclarationChecker,
and is therefore postponed.

For now, Java annotations that are visible through actual type aliases
cannot have default argument values for parameters which already have
default values in the expected annotation declaration

 #KT-22703 Fixed
 #KT-22704 Open
2018-02-05 14:13:32 +01:00
Alexander Udalov db4ce703a6 Support default arguments for expected declarations
#KT-21913 Fixed
2018-02-05 13:38:05 +01:00
Alexander Udalov d465f5fd8e Extract ExpectedActualResolver out of ExpectedActualDeclarationChecker
The point is that it's placed in module 'resolution' where it can be
accessed for example in ArgumentsToParametersMapper to load default
argument values from expected function
2018-02-05 13:38:05 +01:00
Alexander Udalov ac5444ef7c Add declaresOrInheritsDefaultValue, move hasDefaultValue to 'resolution'
'hasDefaultValue' needs to be adapted to support locating default values
in 'expect' functions, and this is not possible in module 'descriptors',
where it was originally declared. Therefore, move it to module
'resolution' and copy its current logic to a separate function
'declaresOrInheritsDefaultValue' which is used in 5 places.
'hasDefaultValue' itself is updated in subsequent commits.

Besides changing imports, also use a simpler declaresDefaultValue in
some places, which does not include default values inherited from
supertypes: this is OK for constructors, and in LazyJavaClassMemberScope
for functions from built-ins which do not have default argument values
at all
2018-02-05 13:38:04 +01:00
Ilya Chernikov 4eb557724c Convert compiler projects to the new intellij deps 2018-01-30 17:06:13 +03:00
Ilya Chernikov a4f28cd94f Make all dependencies to idea sdk intransitive 2018-01-30 17:06:11 +03:00
Mikhail Zarechenskiy c80beea6fd [NI] Refactoring: extract method to create resolution result out 2018-01-30 13:01:21 +03:00
Mikhail Zarechenskiy 0e31162df4 [NI] Fix substitution for receiver when resolving constructor super call 2018-01-30 13:00:44 +03:00
Mikhail Zarechenskiy 2a0bb68e1c [NI] Fix substitution of NotNullTypeParameter 2018-01-30 13:00:43 +03:00
Mikhail Zarechenskiy 4cd07f59a0 [NI] Don't fail on captured type that contains type variable 2018-01-30 13:00:42 +03:00
Mikhail Zarechenskiy 145c04e7e2 [NI] Fix substitution of incorporation constraint type 2018-01-30 13:00:40 +03:00
Dmitry Savvinov 44920f42d8 [NI] Fix unit coercion
Consider following case:

fun foo(): Unit = run { "hello" }

Previously, NI would analyze lambda body without expected type, because
it is a type variable 'R' from 'run', which hasn't been fixed yet. This
leads to treating "hello" as lambda-return argument and adding bogus
'String' constraint on 'R', and, consequently, type mismatch.

Now, we peek into current constraint system and check if return-type of
lambda is type variable with upper-Unit constraint (which is exactly
condition for its body to be Unit-coerced). If so, then we provide
expected Unit-type for body explicitly, and the rest will be done
automatically (in particular, in aforementioned example "hello" wouldn't
be treated as lambda return argument).
2018-01-18 15:13:45 +03:00
Dmitry Savvinov c704f2de9a Reformat 'resolution' module according to new codestyle 2018-01-17 16:47:45 +03:00
Mikhail Zarechenskiy c6d8b39b4f [NI] Prioritize type variables related to output type for fixation 2017-12-19 15:11:04 +03:00
Mikhail Zarechenskiy d47130eff8 [NI] Don't check type for constants too early to avoid mismatch 2017-12-07 14:18:20 +03:00
Mikhail Zarechenskiy 6c27a49114 [NI] Use effective variance for equal approximated type
It's totally safe from the point of type system and reduces extra `out` projections that can add problems with subtyping
2017-12-07 14:18:17 +03:00
Dmitry Savvinov 874267b79d Report cyclic scopes properly
This commit introduces proper handling of recursion in scopes, which
could occur when some of companion object supertypes are members of
that companion owner:

```
class Container {
  open class Base
  companion object : Base()
}
```

To resolve `Base`, we have to build member scope for `Container`.
In the member scope of `Container`, we see all classifiers from
companion and his supertypes
So, we have to resolve companion objects supertype, which happens to be
`Base` again - therefore, we encounter recursion here.

Previously, we created `ThrowingLexicalScope` for such recursive calls,
but didn't checked for loop explicitly, which lead to a wide variety of
bugs (see https://jetbrains.quip.com/dc5aABhZoaQY and KT-10532).

To report such cyclic declarations properly, we first change
`ThrowingLexicalScope` to `ErrorLexicalScope` -- the main difference is
that latter doesn't throws ISE when someone tries to resolve type in it,
allowing us to report error instead of crashing with exception.

Then, we add additional fake edge in supertypes graph (from
host-class to companion object) which allows us to piggyback on existing
supertypes loops detection mechanism, and report such cycles for user.
2017-12-07 14:14:08 +03:00
Dmitry Savvinov aaee401240 [NI] Minor renaming
Use words 'returnArgument' instead of 'resultArgument' when talking
about values, which can be possibly returned from lambda.

Correct 'addSubsystemForArgument' -> 'addSubsystemFromArgument'
2017-12-07 12:49:56 +03:00
Dmitry Savvinov 30a51af931 [NI] Minor: rename typo KotlinCallDiagnistics.kt -> KotlinCallDiagnostics.kt 2017-12-07 12:49:56 +03:00
Dmitry Savvinov 957bbe291d [NI] Don't approximate error types
Previously, we did approximation of error types to Any?/Nothing in some
contexts (e.g. non-local declarations).

There are several reasons why it is not desired:
- OI doesn't approximate ErrorType
- This behaviour is inconsistent with ourselves (i.e. sometimes we *do*
  infer errortype for top-level declaration)
- It causes different digressions from OI in reported diagnostics

This commit turns off error type approximation. It causes large testdata
shift, which is deliberately split into several parts and commited in a
separate commits.
2017-12-07 12:49:56 +03:00
Dmitry Savvinov eadd1355c2 [NI] Add ErrorType constraint
Previously, constraint wasn't added if bound was ErrorType. That could
cause TypeVariable to be inferred to Any?/Nothing instead of ErrorType,
which could influence other parts of analysis (in particular, inferring
Nothing instead of ErrorType can cause bogus UNREACHABLE_CODE diagnostics)

Because of that fix, intersection type can be added to CS as supertype,
which provokes AssertionError. This commit also relaxes this assertion,
as it seems that it's valid that supertype is an intersection type.
2017-12-07 12:49:56 +03:00
Dmitry Savvinov 9f63818bd3 [NI] Introduce INAPPLICABLE_ARGUMENTS_MAPPING_ERROR for some NI diagnostics 2017-12-07 12:49:56 +03:00
Dmitry Savvinov e2d65adc7e [NI] Fix KotlinResolutionCandidate.isSuccessfull
Check if ConstrainSystem has any contradiction in 'isSuccessful'.
Otherwise we may erroneously think that there are some successful
candidates in 'TowerResolver.SuccessfullResultCollector.pushCandidates()'
and clear other unsuccessful ones (while they actually may have higher
applicability).
2017-12-07 12:49:56 +03:00
Mikhail Zarechenskiy 1d736f59b6 [NI] Refine nullability for CST of types with undefined nullability 2017-12-06 18:36:20 +03:00
Mikhail Zarechenskiy b9d390449c [NI] Refactor constraints transformations, update comments 2017-12-06 18:36:19 +03:00
Mikhail Zarechenskiy 351c592c83 [NI] Drop hack that was used before DefinitelyNotNull types 2017-12-06 18:36:17 +03:00
Mikhail Zarechenskiy 64f0688b71 [NI] Introduce DefinitelyNotNullType as type for T!! or {T & Any} 2017-12-06 18:36:11 +03:00
Mikhail Zarechenskiy 8e0171d475 [NI] Don't loose platform types on simplifying lower constraints 2017-12-06 18:08:52 +03:00
Mikhail Zarechenskiy bee7ed1431 [NI] Fix mapping of type arguments to parameters for inner classes 2017-11-22 10:22:41 +03:00
Mikhail Zarechenskiy e526a87d54 [NI] Make model more robust: remove diagnostics from resolution atoms
Currently there are two major phases in NI that report diagnostics: resolution parts and completion. They connected in method `KotlinCallCompleter.runCompletion` and previously diagnostics were collected in several places, from resolution atoms, partly from constraint system and partly from `CallResolutionResult`, some of them were lost.

 To mitigate this problem, now diagnostics are not bind to the intermediate candidate, only to the result resolution candidate (overloaded or usual one). And all diagnostics are now collected in method `runCompletion`
2017-11-22 10:22:39 +03:00
Mikhail Zarechenskiy 20e1caaab1 [NI] Use refined expected type by smartcasts in CS 2017-11-17 15:04:20 +03:00
Mikhail Zarechenskiy 66064345e9 [NI] Support fallback resolution for refined sams priority feature 2017-11-16 18:07:54 +03:00
Mikhail Zarechenskiy e42f07b031 [NI] Wait for proper constraints to fix type for callable reference
If expected type is a type variable, then we'll wait for proper constraints, but previously we resolved callable reference as it didn't have expected type at all, because type variable isn't a functional type

 Consider the following example:

 fun foo(i: Int) {}
 fun foo(s: String) {}
 fun <T> id(x: T): T = x

 fun test() {
     val x1: (Int) -> Unit = id(id(::foo))
 }

 Here we shouldn't resolve callable reference until we get constraint from expected type of `x1`
2017-11-16 18:07:51 +03:00
Alexander Udalov 7ace303add Fix ambiguity on callable reference for expect members
Expect members should always lose in resolution to non-expect members,
be it simple calls or callable references. Note that there should be
exactly one actual member for each expect member in correct code, so
both ways to check for expect vs non-expect are correct: either before
signature comparison, or after.

 #KT-20903 Fixed
2017-11-15 11:02:29 +01:00
Mikhail Zarechenskiy fbe274ff09 [NI] Use less specific type for captured type approximation
This is needed to be more compatible with the old NI
2017-11-14 14:40:47 +03:00
Mikhail Zarechenskiy f3ef961be6 [NI] Report error about non-spread parameter from arguments mapper 2017-11-14 13:55:48 +03:00
Mikhail Zarechenskiy 2aa8ceb005 [NI] Fix state for named arguments in arguments to parameters mapper 2017-11-14 13:54:51 +03:00
Mikhail Zarechenskiy 519e5c33d8 [NI] Support assigning single array elements in named form to varargs 2017-11-13 16:47:05 +03:00
Mikhail Zarechenskiy fe2499b47f [NI] Approximate flexible types with enhancement as usual ones
This is temporary and should be fixed later
2017-11-13 16:35:24 +03:00
Mikhail Zarechenskiy f51f7a0fe4 [NI] Report diagnostic about receiver as super expression 2017-11-13 16:33:08 +03:00
Mikhail Zarechenskiy 1d6e9c244b [NI] Report diagnostic about spread argument to non vararg parameter 2017-11-13 16:32:58 +03:00
Mikhail Zarechenskiy 73b4e24d54 Introduce language feature for NI, remove old setting 2017-11-13 16:23:04 +03:00
Alexander Udalov 02981038f3 Split core into descriptors, descriptors.jvm, deserialization, descriptors.runtime 2017-11-10 18:58:31 +01:00
Dmitry Savvinov d20c770a25 Effects: add test on (de)serialization of contracts
- Add ContractDescriptorRenderer
- Add option to dump function contracts in DescriptorRendererOptions
- Add parsing of LANGUAGE_VERSION directive in AbstractLoadJava
- Add tests on serialization-deserializaton identity of contracts

==========
Introduction of EffectSystem: 13/18
2017-10-12 11:55:26 +03:00