Commit Graph

2612 Commits

Author SHA1 Message Date
Dmitry Petrov 5d44e095c8 Nullability assertions for extension receiver
In Kotlin 1.1 and before, there were no nullability assertions on
extension receivers, because receiver is resolved with NO_EXPECTED_TYPE.
So, if an expression of platform type is passed as an extension receiver
to a non-private function, it would fail with IllegalArgumentException.
However, if the function is private, then we generated no parameter
assertions under assumption that such function can be called from Kotlin
only, and all arguments are checked on the call site. Thus 'null' could
propagate indefinitely.

In Kotlin 1.2, we do the following:
- Generate nullability assertions for expression receivers.
NB nullability assertions are stored for ReceiverValue instances, not
for expressions: given expression can act as receiver in different
calls, each with an expected receiver type of its own.
- Generate nullability assertions for extension receivers of private
operator functions.
NB it still can throw NPE for some particular "optimized" cases, but at
least those nulls would not propagate indefinitely.

This behavior is disabled by an "advanced" command-line option
'-Xno-receiver-assertions'.
2017-09-01 09:49:21 +03:00
Denis Zharkov ed79891ee6 Fix type mapping for parameter of Collection<Int>::remove override
In the case the single parameter of override has `Integer` type instead
of `int` type (while in common case it would be just `int`)

See the comment inside forceSingleValueParameterBoxing for clarification

 #KT-19892 Fixed
2017-08-31 12:38:08 +03:00
Denis Zharkov 80a90572d6 Fix target for annotations/metadata on open suspend functions
Get rid of rewriting of vars in FunctionCodegen::generateMethod,
just extracted generateMethodBody instead

 #KT-19814 Fixed
2017-08-31 12:27:28 +03:00
Dmitry Petrov c8d25c587a Do not use reflection it local/top-level lateinit tests 2017-08-31 11:28:08 +03:00
Dmitry Petrov bbf9bf91fc Check language feature support for local and top-level lateinit vars 2017-08-31 11:28:08 +03:00
Dmitry Petrov 01cce59c35 Make sure lateinit top-level properties work in JVM BE 2017-08-31 11:28:08 +03:00
Dmitry Petrov 78b69cad77 Support lateinit local vars in redundant null check elimination
Lateinit local vars are guaranteed to be non-null after store.
So we mark such stores as storing non-null value
(could be useful for some other constructs, too),
and optimize null checks accordingly.
2017-08-31 11:28:08 +03:00
Dmitry Petrov d0b0fdd732 Ignore lateinit local vars tests in JS and Native 2017-08-31 11:28:08 +03:00
Dmitry Petrov c5b9d500bc Support lateinit local vars in JVM BE 2017-08-31 11:28:08 +03:00
Denis Zharkov aef5911c7e Obtain original suspend function view for inline codegen
It's necessary for generic inline suspend as a codegen
for it uses binding slice SUSPEND_FUNCTION_TO_JVM_VIEW
to generate fake continuation parameter, so all the
descriptors that are used for body generation must be
obtained from the SUSPEND_FUNCTION_TO_JVM_VIEW

 #KT-19528 Fixed
2017-08-30 16:19:43 +03:00
Stanislav Erokhin 2ceb8cef36 [NI] Use same ResolvedCall when run completion
It is necessary, because some clients store this ResolvedCall to other
places, for example for get call it stored to INDEXED_LVALUE_GET
2017-08-25 03:38:49 +03:00
Mikhail Zarechenskiy f31c48017b [NI] Don't process lambda until expected type will be fixed 2017-08-25 02:47:46 +03:00
Mikhail Zarechenskiy 3f8a685ace [NI] Make return type of !! operator definitely not-null 2017-08-24 13:50:11 +03:00
Mikhail Zarechenskiy d18a14b717 [NI] Eliminate special intersection type from result type 2017-08-24 13:50:10 +03:00
Mikhail Zarechenskiy 9f2bf066b9 [NI] Transform anonymous types of expected type for delegation 2017-08-24 13:50:09 +03:00
Mikhael Bogdanov 1a05df204e Properly check expression nullability on attempt to apply == optimizations
#Fix KT-19767
2017-08-24 09:51:55 +02:00
Mikhail Zarechenskiy c45f86a2fc [NI] Resolve function literals in block as lambda expression 2017-08-23 15:53:52 +03:00
Mikhail Zarechenskiy 08964006de [NI] Avoid type capturing for types that can contain type variables 2017-08-23 15:53:51 +03:00
Stanislav Erokhin 9f71de5f66 Add test for lambda as last expression in lambda 2017-08-23 15:53:45 +03:00
Stanislav Erokhin 74e07b6580 Add regression test for no resolution recursion 2017-08-23 15:53:44 +03:00
Denis Zharkov ad9fe53ee2 Avoid local var entry for continuation parameter in suspend function
The primary reason is getting rid of redundant stack spilling, but also
it's not very sensible to have such entry since the parameter
is synthetic
2017-08-22 18:43:31 +03:00
Denis Zharkov fcd7677a3f Fix compatibility of suspend functions with strict bytecode analyzers
In short, some of the bytecode analyzers assume that there could be
no stores instructions into parameter vars with value of different
types (even when the value type is a subtype)

See the issue for details

 #KT-19713 Fixed
2017-08-22 18:43:26 +03:00
Mikhael Bogdanov 8af7a25f8e Update maxStack on synthetic instruction insertion
#KT-19723 Fixed
2017-08-17 20:02:29 +02:00
Alexander Udalov 4d2fbf1801 Fix reflection for local delegated properties inside interface
#KT-19690
2017-08-17 15:35:11 +02:00
Mikhael Bogdanov 97d46e76f5 Use 'DefaultImpls' as owner for interface local delegated properties
#KT-19690 Fixed
2017-08-17 15:35:10 +02:00
Mikhael Bogdanov 79ecc7fd5c Don't recognize nullable function types as inlinable
#KT-19679 Fixed
2017-08-17 14:24:00 +02:00
Yan Zhulanow 57d209f599 Kapt: Do not use awkward ('$' -> '/') logic for KAPT3 class builder mode
So (for the most often reproduction case) #KT-19433 Fixed

Before this commit, internal names for nested classes were written as test/Foo/Bar (comparing to test/Foo$Bar in the normal mode), as getting qualified names from such internal names was trivial. But, because of IC, we needed to write class files to the disk, so our decompiler could find such "broken" classes and read it in a wrong way.
2017-08-15 17:48:51 +03:00
Mikhael Bogdanov 6ca06265cf Rename and disable test on JS 2017-08-10 16:16:28 +02:00
Mikhael Bogdanov 3fd6dd3572 Add test for quoted class name 2017-08-10 12:10:25 +02:00
Denis Zharkov ff0736f09e Fix exception after combination of while (true) + stack-spilling
FixStack transformation divides on phases:
- Fixing stack before break/continue
- Fixing stack for inline markers/try-catch blocks

After the first stage all ALWAYS_TRUE markers are replaced
with simple GOTO's and if we're skipping break/continue edges
we won't reach the code after while (true) statement.

At the same time it's fine to not to skip them in the second phase
as the stack for them is already corrected in the first phase

 #KT-19475 Fixed
2017-08-08 18:52:21 +07:00
Denis Zharkov 45d5f6a950 Add test for obsolete issue
#KT-19467 Obsolete
2017-08-08 18:52:21 +07:00
Mikhael Bogdanov 15f401a473 Copy annotation and attributes on class transformation during inline 2017-08-08 09:50:42 +02:00
Mikhail Zarechenskiy e7cd615450 [NI] Introduce type depth in CS calculator to avoid SOE 2017-08-07 18:01:13 +03:00
Mikhail Zarechenskiy cf75afba66 [NI] Fix type intersection for equal types 2017-08-07 18:01:12 +03:00
Mikhail Zarechenskiy 0d464f06d1 [NI] Consider CS as nullable if one of the types isn't subtype of Any
Note that this isn't fully correct, consider the following situation:

S : T, T : Any?
=> CS(S, T) = T, but for now it will be T?, which is reliable but not so specific as just T
2017-08-07 18:01:09 +03:00
Mikhail Zarechenskiy 39349abd39 [NI] Preserve name of parameters for functional types 2017-08-07 18:01:07 +03:00
Stanislav Erokhin d58c6e245f Minor. rename type parameters for debug purposes. 2017-08-07 18:00:43 +03:00
Dmitry Petrov 756f7d6e9c [NI] Fix tests (was a type checker bug, see KT-18380) 2017-08-07 18:00:38 +03:00
Dmitry Petrov 6facdcb7ea Minor: lambda arguments formatting 2017-08-07 18:00:20 +03:00
Dmitry Petrov f637ebe9ff Minor: formatting for lambda arguments 2017-08-07 18:00:14 +03:00
Dmitry Petrov 2ed5a5e368 'when' should use intrinsics for '=='
#KT-19029 Fixed Target versions 1.1.5
 #KT-18818 Fixed Target versions 1.1.5
2017-08-07 10:31:02 +03:00
Dmitry Petrov c5613888eb Look into proper context when generating backing field access
Problem manifests when a class property name matches a companion object
property name, and class property is referenced in closure context.

 #KT-19367 Fixed Target versions 1.1.5
2017-08-02 11:24:35 +03:00
Dmitry Petrov 9e6b706a03 Unwrap property imported from object on property access
#KT-18982 Fixed Target versions 1.1.5
2017-07-28 17:01:04 +03:00
Dmitry Petrov 67336653e0 Generate SAM wrappers only if they are required for a given argument
SAM interface wrapper for an argument is required,
if in the function descriptor for SAM adapter
type for the corresponding value parameter
doesn't match type of the corresponding value parameter
in the original (Java) descriptor.

 #KT-19251 Fixed Target versions 1.1.5
2017-07-28 08:24:46 +03:00
Dmitry Petrov 5df461c7e0 Add test for KT-19246
The issue was fixed by
https://github.com/jetbrains/kotlin/commit/904c7f9c640ccb38c0becb40bd3b5dad3ac921bd
2017-07-28 08:24:46 +03:00
Dmitry Petrov b81ca31aae Record resolved delegation call for primary ctor if single result
Do the same thing as for secondary constructor (looks like it was a
workaround for R&I bug that was used only for secondary constructors
for some reason).

 #KT-17464 Fixed Target versions 1.1.5
2017-07-27 09:24:48 +03:00
Dmitry Petrov c9ad290ad5 Do not store null for temporary in destructuring assignment
#KT-19256 Fixed Target versions 1.1.5
2017-07-27 09:02:26 +03:00
Dmitry Petrov b867c46f72 Generate for-in-range loop as counter loop when possible
If an upper bound is a compile-time constant != Int.MAX_VALUE,
we can generate 'for (i in x..N)' as 'for (i in x until N+1)'.
2017-07-27 09:02:26 +03:00
Mikhael Bogdanov ff676c050f Properly generate inner classes when compiling source for inline
KT-19175: Compiler generates different bytecode when classes are compiled separately or together

 #KT-19175 Fixed
2017-07-26 20:31:14 +02:00
Dmitry Petrov f558b4238c Use counter loop in intrinsic array constructors
#KT-19149 Fixed Target versions 1.1.5
2017-07-24 10:17:30 +03:00