Commit Graph

47 Commits

Author SHA1 Message Date
Alexey Andreev 6ab87ad66a Fix failing JS tests 2017-11-27 17:01:15 +03:00
Dmitry Petrov 4365084645 Lookup for local variables taking into account uninitialized this
Consider a context with uninitialized this, e.g.:

  fun foo() {
    val x = "..."
    class Local(y: String) : Base(L@{ x + y })
  }

Lambda 'L' is an argument of a super class constructor call.
Here 'this@Local' is not initialized yet. Thus local variables captured
in 'Local' can't be used. Instead, they should be captured by lambda 'L'
itself.

Note that lambda 'L' sees both 'x' and 'y' as local variables that
should be captured.

When in context with uninitialized this (generating arguments for super
type constructor or delegating constructor call), and a variable in
question is not found in the current context, use enclosing local lookup
to determine whether a local variable should be captured by a closure.
2017-11-14 09:33:28 +03:00
Dmitry Petrov bbb0389c51 Fix determining enclosing class for closure
Enclosing class for closure is a class whose instance is captured by
closure as an outer 'this', and stored in a field 'this$0'.
Usually enclosing class for closure is an immediate outer class,
including classes for nested closures. For example:

  class C {
    fun foo() {}
    val example1 = L1@ { foo() }
    // Enclosing class for lambda 'L1' is 'C'
    val example2 = L2a@ { L2b@ { foo() } }
    // Enclosing class for nested lambda 'L2b'
    // is a closure class for outer lambda 'L2a'
  }

However, if the closure is created in a super type constructor call for
the outer class, corresponding instance is considered "uninitialized",
and can't be used as a proper class instance, and can't be referenced:
corresponding code is rejected by front-end.

  class Outer {
    fun foo() {}
    inner class Inner : Base(L3@ { foo() })
    // Enclosing class for lambda 'L3' is 'Outer',
    // because 'Inner' is uninitialized in super type constructor call.
  }

In CodegenAnnotatingVisitor, we maintain a stack of currently
uninitialized classes, and chose enclosing class for closure
as an inner-most surrounding class with initialized instance.

When generating code for this or outer class instance, we skip
contexts corresponding to classes with uninitialized instances.

This fixes a number of bytecode verification errors caused by incorrect
enclosing class for closure.

 #KT-4174 Fixed Target versions 1.2.20
 #KT-13454 Fixed Target versions 1.2.20
 #KT-14148 Fixed Target versions 1.2.20
2017-11-14 09:33:28 +03:00
Denis Zharkov d92c403f9e Move helpers for coroutine tests in separate package
It will help to skip their content when rendering bytecode listing
for box tests
2017-05-05 14:01:50 +03:00
Mikhael Bogdanov b9409523b0 Fix for KT-17588: Compiler error while optimizer tries to get rid of captured variable
#KT-17588 Fixed
2017-04-25 15:06:41 +02:00
Mikhael Bogdanov b51cb9a911 Delete clean reference instructions on dereferencing captured variables
Codegen generates clean instructions for ref values (captured vars)
on block exit so we should delete them on dereferencing captured values.

  #KT-17200 FIXED
2017-04-10 16:35:03 +05:00
Dmitry Petrov 3c09a26e16 KT-5248 Don't wrap variable if it is captured only in inlined closures
Remove non-escaping Ref's on bytecode postprocessing pass.
2017-03-13 09:04:31 +03:00
Ilya Matveev a5e4e0284e Mute some box tests for native backend
This patch mutes the following test categories:
   * Tests with java dependencies (System class,
     java stdlib, jvm-oriented annotations etc).
   * Coroutines tests.
   * Reflection tests.
   * Tests with an inheritance from the standard
     collections.
2017-03-10 19:59:37 +03:00
Alexander Udalov 9d11f0b92f Minor, check every deserialized value in refsAreSerializable.kt 2017-02-16 18:00:19 +03:00
Alexander Udalov 8e3cb912c7 Make Ref classes for shared vars Serializable
#KT-14566 Fixed
2017-02-15 10:46:48 +03:00
Alexey Andreev 1db4765801 JS: unmute shared box test that now passes 2016-12-12 14:30:43 +03:00
Ilya Gorbunov 49756a897e Just refactor tests that require further investigation 2016-11-21 18:20:33 +03:00
Zalim Bashorov 596f3364c6 Automatically mute failed tests 2016-11-09 21:41:12 +03:00
Denis Zharkov a9fcee098d Support single-underscore named variables in JVM backend
There are mainly two kind of changes:
- skipping 'componentX' calls for destructuring entries named _
- fixing local variable table for them
 - skip entries for destructuring entries named _
 - use $noName_<i> format for lambda parameters named _

 #KT-3824 Fixed
 #KT-2783 Fixed
2016-10-24 10:19:25 +03:00
Michael Bogdanov 6f41e3b462 Fix for KT-11634: UOE in ConstructorContext.getOuterExpression for super call in delegation
#KT-11634 Fixed
2016-07-20 16:50:49 +03:00
Alexander Udalov bab127ad33 Remove some legacy codegen tests, move some to generated 2016-03-09 10:25:38 +03:00
Michael Bogdanov e1fa6491c1 Test for obsolete KT-10044: "Don't know how to generate outer expression for class" with lambda in init block
#KT-10044 Obsolete
2016-01-29 12:42:37 +03:00
Yan Zhulanow 9d1af5a17e Fix tests: "infix modifier required" and "operator modifier required" errors 2015-11-27 15:51:11 +03:00
Mikhail Glukhikh 4e44466cf9 Exposed visibility deprecation warnings made errors + relevant test fixes 2015-11-20 15:21:01 +03:00
Michael Bogdanov 9daa44566b Fix for KT-5589: VerifyError when default value for parameter of local function is obtained from closure
#KT-5589 Fixed
2015-11-03 15:40:16 +03:00
Denis Zharkov f0e3fd617d Adjust testData to CharSequence.length transformation 2015-10-14 20:39:35 +03:00
Dmitry Jemerov 1523d5bcbf removing static type assertions work in progress 2015-10-12 11:11:23 +02:00
Dmitry Jemerov 7c20630272 diagnostics for deprecated syntax of function type parameter list 2015-10-06 16:20:47 +02:00
Alexander Udalov 1a3209e1dc Drop traits with required classes
#KT-4771 Rejected
2015-06-17 16:23:58 +03:00
Michael Bogdanov 319c5aec60 Fix for KT-7557: NoSuchMethodError when capturing receiver in object expression
#KT-7557 Fixed
   #KT-7769 Fixed
2015-05-21 10:06:01 +03:00
Dmitry Jemerov 4bdf598bfe compiler testdata: s/trait/interface 2015-05-12 19:43:17 +02:00
Denis Zharkov 44a55e5bf6 Adjust testData to new labels syntax 2015-04-29 14:03:11 +03:00
Stanislav Erokhin 3de0dff575 Migrate testdata to new lambda syntax 2015-04-07 13:08:53 +03:00
Stanislav Erokhin b152211096 Added init keyword to testdata 2015-04-07 13:08:51 +03:00
Stanislav Erokhin 2c8cf05f7a Added backend tests with closure local function in local class 2015-03-12 17:11:42 +03:00
Denis Zharkov e65382e6ec Support secondary constructors in JVM backend
There is a lot of changes about closures calculating and generating.

1. As classes can have more than one constructor each of them should
have closure arguments.

2. Captured variables set is the same for all of them.

3. Within constructors bodies/delegating calls closure parameters
should be accessed through method arguments because fields may be
not initialized yet.
2015-03-11 17:45:27 +03:00
Svetlana Isakova 4771986b32 KT-4656 Wrong capturing a function literal variable.
#KT-4656 Fixed
 Reference for calleeExpression is recorded only in 'doResolveCallOrGetCachedResults'.
2014-03-08 20:55:45 +04:00
Alexander Udalov a98434263b Add regression test for outdated issue
#KT-3738 Obsolete
2014-02-12 19:17:55 +04:00
Alexander Udalov 35c7c4afd8 Fix capturing outer this in some cases in JVM codegen
When property initializer of some inner entity (e.g. anonymous object) contains
a reference to some outer entity (say, a property of the outer class), we need
to make sure we called "lookupInContext" on this entity's owner class, so that
"setCaptureThis" was called on the appropriate closure

 #KT-4176 Fixed
2014-02-12 19:17:55 +04:00
svtk 95ca2d8f98 Fixed bug with property and function name clash.
Complete type inference dependent on function literals and expected type
for variable as function calls not for 'invoke' calls
2013-11-25 19:42:07 +04:00
Mikhael Bogdanov c325dfffd9 KT-3523: VerifyError for invoke function in inner class
KT-4106: VerifyError: Can't access outer this in a lambda in inner class' constructor
KT-3152: VerifyError when accessing from a function of object to a field of outer outer class

  #KT-3523 Fixed
  #KT-4106 Fixed
  #KT-3152 Fixed
2013-10-31 16:42:53 +04:00
Mikhael Bogdanov e3882e2dfb KT-4137: Verify error
#KT-4137 Fixed
2013-10-25 16:43:25 +04:00
Mikhael Bogdanov 6ca3a581b0 Test fix for previous commit 2013-09-24 14:31:58 +04:00
Mikhael Bogdanov 7520ff1420 KT-3308: Support local generic functions in codegen
#KT-3308 Fixed
2013-09-24 12:59:57 +04:00
Andrey Breslav 55eb994502 KT-3919 Automatic labeling of lambdas by receiving functions
#KT-3919 Fixed
2013-08-22 14:27:01 +04:00
Andrey Breslav aa99c29d8d JVM backend test for local returns 2013-08-21 20:12:05 +04:00
Alexander Udalov 974df0ed8e Use FunctionImplN instead of FunctionN in codegen
Superclass of closures should now be FunctionImplN instead of FunctionN. Since
these -Impl classes are needed only in JVM, the corresponding descriptors and
types are created in the back-end only.
2013-04-22 17:59:29 +04:00
Evgeny Gerashchenko 0bc65321c2 KT-1547 Wrong layout of closure classes
#KT-1547 fixed
2013-03-28 15:54:51 +04:00
Mikhael Bogdanov ad4eeb3f8a Properly capture local functions
Local functions in local classed wasn't captured properly
2013-03-27 15:57:27 +04:00
Mikhael Bogdanov 932c1444a2 Fix for local closures 2013-03-26 15:43:25 +04:00
Alexander Udalov 9007a6214a Fix closure's reference to outer closure
#KT-3276 Fixed
2013-01-29 22:41:58 +04:00
Alexander Udalov 41a416da60 Move blackBoxFile() testData to box/ directory
Delete all test methods (and empty test classes), since they'll be
auto-generated
2013-01-28 18:20:17 +04:00