Commit Graph

551 Commits

Author SHA1 Message Date
Dmitry Petrov d27593aeda PSI2IR: SAM conversion in method arguments of out-projected Java classes
It uses the same logic as an old back-end
(see SamType#createByValueParameter and genericSamProjectedOut.kt),
split into two parts:

1. When inserting SAM casts, use SamType#createByValueParamerer to get
the target SAM type.

2. When inserting implicit casts, cast SAM conversions as arguments of
methods of out-projected types to the original type of value parameter
instead of 'Nothing'.
2020-01-03 15:32:44 +03:00
Dmitry Petrov 8054e2960e PSI2IR: Post-process return expressions based on expected return type
Consider the following example:

Java:
  public class J {
    public static String foo() { return null; }
  }

Kotlin:
  fun check(fn: () -> Any) = fn()
  fun test() = check { J.foo() }

When a lambda expression returns a value of platform type ('String!'),
corresponding lambda has platform type in its return type, which is
approximated to corresponding nullable type ('String?') in IR.
However, the lambda itself could occur in position with a functional
expected type ('() -> Any'). This implies an extra implicit cast on a
return value of lambda expression ('J.foo()'), although it conforms to
the return type of lambda.
2019-12-31 13:30:23 +03:00
Dmitry Petrov d622542824 PSI2IR: Fix delegated members generation
When generating bodies for members implemented by delegation, invoke
corresponding delegate member, not an interface member. Otherwise we
might lose platform-specific nullability information in case of mixed
Kotlin-Java hierarchies, as in
implicitNotNullOnDelegatedImplementation.kt
2019-12-30 18:36:16 +03:00
Mikhail Glukhikh 6da3c2fa4e FIR2IR: set parent correctly (~) for anonymous functions 2019-12-27 16:13:02 +03:00
Mikhail Glukhikh 1cf582e9ed FIR2IR: set extension receiver for anonymous functions 2019-12-27 15:31:36 +03:00
Mikhail Glukhikh e4b2c238c7 FIR2IR: temporarily allow null receivers & use findIr*Receiver also for fields 2019-12-27 13:46:06 +03:00
Mikhail Glukhikh 15f373a864 FIR2IR: support object receiver case (this fixes 24 black box tests) 2019-12-27 13:46:05 +03:00
Mikhail Glukhikh f3b5ee4cba FIR2IR: fix assertion in getIrFunctionSymbol (anonymous function case) 2019-12-27 13:46:05 +03:00
simon.ogorodnik 5e426fdc71 [FIR] Optimization & checking fix: remove usage of dispatchReceiverValue 2019-12-27 13:45:59 +03:00
Mikhail Glukhikh 0c88ecdc56 FIR resolve: introduce builtInExtensionFunctionReceiverValue
This commit allows us to distinguish extension lambda receivers
from simple extension receivers thus fixing some resolve problems.
2019-12-27 09:57:36 +03:00
Mikhail Glukhikh de50f8aef3 FIR resolve: add partial support of extension lambda calls
Here we introduce ONLY_IMPLICIT_RECEIVER tower level
to support extension lambda calls on local variables,
and soften extension receiver checks to make such extensions visible & applicable.
Also here we try to map arguments twice for functional types
2019-12-27 09:57:36 +03:00
Pavel Kirpichenkov 7ee71450bc [NI] Discriminate Nothing? result type from nullability constraints
Nullability constraints should not be chosen when proper
argument constraints for variables in contravariant position present.

^KT-32106 Fixed
^KT-33166 Fixed
2019-12-25 14:59:06 +03:00
Dmitry Petrov fefdce0406 KT-35550 Generate type parameters for delegating property accessors 2019-12-23 10:10:16 +03:00
pyos 1f55b59fa3 Unmute a fixed Fir2IrText test 2019-12-20 15:12:37 +03:00
pyos 26822a0cde Minor: IGNORE_BACKEND: ANY_FIR -> IGNORE_BACKEND_FIR: ANY
for consistency with blackbox tests.
2019-12-20 15:12:36 +03:00
Mikhail Glukhikh 38a3797325 Unmute FIR2IR test (due to fixed bug in FIR) 2019-12-20 14:44:46 +03:00
pyos 2adcb5dec4 Add the ANY_FIR target for muting Fir2IrText tests 2019-12-20 13:03:39 +03:00
pyos a4b005fd5d PSI2IR: generate field writes for all val property assignments
Assuming the frontend is correct, and it hopefully is, all of them are
initializations even if not done in the owner class directly.
2019-12-20 13:03:39 +03:00
Dmitry Petrov 09c3279cc7 PSI2IR: Infer smart cast on dispatch receiver of FAKE_OVERRIDE calls
NB here we have use derived class type with type arguments replaced
with star-projections. This emulates JVM erasure (to some degree),
but, unfortunately, that's best we can offer here at the moment.
2019-12-19 12:24:58 +03:00
Mikhail Glukhikh 684bdc44bb FIR: add implementation of reified type parameter references
This adds support of T::class.java for reified type parameters
2019-12-17 17:28:01 +03:00
Georgy Bronnikov e92985458b JVM_IR: skip private declarations in imported classes 2019-12-17 15:53:29 +03:00
Mikhail Glukhikh 737eaebee6 FIR resolve: fold flexible types whenever possible #KT-31528 Fixed 2019-12-16 12:06:10 +03:00
Victor Petukhov 07269661b4 NI: Allow to resolve to functions with SAM conversion and passing array without spread as vararg (with warning)
^KT-35224 Fixed
2019-12-12 23:46:16 +03:00
Alexander Udalov 5f367278c1 Psi2ir: support generic properties in class delegation
Since property accessor descriptors (unlike corresponding IR elements)
do not have type parameters, we need to take them from the corresponding
property to ensure the correct IR for delegated property accessors.
2019-12-12 15:02:32 +03:00
Dmitriy Novozhilov 53480c2266 [FIR] Fix fir2ir testdata broken in 4777dd6 2019-12-12 10:04:12 +03:00
Mark Punzalan 4777dd652b [FIR] Add tests to catch issues with smartcasting of accesses to functions
and properties (type information is stored for the symbol and ALL accesses
to the same symbol are smartcasted).
2019-12-11 16:57:41 +03:00
Mark Punzalan 692a83f7bb [FIR] Add FirCheckNotNullCall converted to CHECK_NOT_NULL intrinsic
function call.
2019-12-11 16:54:15 +03:00
Dmitriy Novozhilov e281d224a3 [FIR] Fix testdata broken in b76c984b 2019-12-10 12:25:42 +03:00
Dmitriy Novozhilov b76c984b26 [FIR] Support IntegerLiteralTypes 2019-12-09 17:24:26 +03:00
Dmitry Petrov c83f68151c Support @EnhancedNullability in psi2ir 2019-12-06 11:03:07 +03:00
Dmitry Petrov 429bf78afa Add 'Collection#contains' as a special case to psi2ir tests 2019-12-06 11:03:07 +03:00
Dmitry Petrov 89e1941dfd Update testData for argument nullability assertion tests 2019-12-06 11:03:06 +03:00
Dmitry Petrov 20fb519f1a PSI2IR: Generate IMPLICIT_NOTNULL casts for platform type values 2019-12-06 11:03:06 +03:00
Dmitriy Novozhilov 38c1a50c1d [FIR] Resolve delegating constructor calls 2019-12-05 17:47:15 +03:00
Dmitriy Novozhilov d840671620 [FIR] Don't create delegating super constructor call to kotlin.Enum for enums 2019-12-05 17:47:14 +03:00
Denis Zharkov e58711cde3 FIR: Select most specific members from supertypes scope 2019-12-05 17:35:33 +03:00
Denis Zharkov b8984d154b FIR: Do not copy type parameters from class to constructors
Use the same instances from class declaration instead

Otherwise, primary constructor value parameter types when used
in the class body are considered as different from types
based on the class type parameters

See the test genericConstructors.kt, before this commit
"id" call was reported in inapplicable
2019-12-05 13:08:51 +03:00
Denis Zharkov fa7bd3dd2e FIR: Support SAM constructors for type aliases 2019-12-03 15:49:22 +03:00
Dmitry Petrov 2435b8d9fa Update testData for enum constructor result type in IR 2019-12-03 11:54:41 +03:00
pyos 35c2573b33 PSI2IR: generate IrEnumConstructorCalls with correct return type
Normally, the fact that is was Unit was not visible as enum constructors
are lowered to normal class constructors anyway. The exception is when
the arguments are reordered, causing the incorrect return type to leak
into the block that holds temporary variables.
2019-12-03 11:54:41 +03:00
Mikhail Glukhikh f1eb0dff1f FIR: disable synthetic scope, make accessor symbols synthetic
Before this commit, we had two methods to do generally the same synthetic thing.
It's an attempt to keep only one of them.
Accessor symbols are generated in Java use-site member scopes,
at this place we know better whether we are in Java class or not.
However, we have to do this at every use-site level, which is relatively slow.
Also we could encounter problems when accessor function is overridden in Kotlin,
and accessor symbol can still contain reference to Java accessor.
2019-11-29 18:09:07 +03:00
pyos fa8cb7b6e0 PSI2IR: support NewInference + SamConversionPerArgument
except for SAM conversions of varargs (which aren't implemented in the
non-IR JVM backend either btw)
2019-11-29 15:25:32 +03:00
Dmitry Petrov cb1b9c2ccf IR testData: IrSimpleFunction.isOperator 2019-11-29 13:53:05 +03:00
Simon Ogorodnik dbf0742c00 [FIR] Fix self-type for enum 2019-11-28 17:23:05 +03:00
Mikhail Glukhikh f58af2e4c3 FIR2IR: fix constructor referencing in return statement 2019-11-28 13:50:10 +03:00
Denis Zharkov 3b7ad066fc FIR: Substitute type alias constructors properly 2019-11-27 11:20:52 +03:00
Denis Zharkov f68929fe74 FIR: Leave functions type parameters in subsituting scope 2019-11-27 11:20:52 +03:00
Dmitriy Novozhilov 43e621530f [FIR] Add type parameters to FirQualifierExpression
It is needed for resolving qualifiers with type arguments
  like `Array<String>::class`
2019-11-25 14:44:44 +03:00
Mark Punzalan 5afab1ac2b [FIR] FIR2IR: Populate calls with type arguments and function type
parameters with bounds/supertypes.
2019-11-25 09:37:47 +03:00
Mikhail Glukhikh d39a36ee25 FIR declared member scope: remove constructors from callable index
This removes constructor resolve ambiguity in some cases.
Now constructors are resolved only via classifiers
2019-11-19 22:41:17 +03:00