Commit Graph

43 Commits

Author SHA1 Message Date
Mikaël Peltier
a2a3043607 KT-18731 Use reference equality to compare enums
Fix of https://youtrack.jetbrains.com/issue/KT-18731
2018-02-05 18:34:44 +03:00
Dmitry Petrov
3431a1445c Fix enum entry class delegating constructor call generation
When the enum entry requires a specific class, its constructor should
invoke proper supertype constructor (from the corresponding enum class).
Corresponding resolved call should be passed from the front-end in
CONSTRUCTOR_RESOLVED_DELEGATION_CALL slice.
In case of enum entries without explicit supertype initializer, this
information was missing.
2017-12-04 10:29:33 +03:00
Dmitry Petrov
28535a57d8 Fix issues with enum entry self-reference
Given a singleton class 'S' with possibly uninitialized static instance
(enum entry, interface companion object).
Such singleton can be referenced by name, or as an explicit or implicit
'this'.
For a given singleton class 'S' we
either use 'this@S' from context (local or captured),
or 'S' as a static instance.

Local or captured 'this@S' should be used if:
  - we are in the constructor for 'S',
    and corresponding instance is initialized
        by super or delegating constructor call;
  - we are in any other member of 'S' or any of its inner classes.

Otherwise, a static instance should be used.
2017-10-26 16:11:58 +03:00
Dmitry Petrov
82a9c35194 Fix self-reference to singleton in initializer
Singleton instance is "initialized" by delegating constructor call,
which is superclass constructor call in case of singletons (because
singletons can't have more than one constructor).

Singleton constructor is effectively split into two stages:
- before a super constructor call;
- after a super constructor call.

Before super constructor call, singleton instance can't be used directly
(see KT-20662), because neither 'this' nor static instance is
initialized yet. However, it can be used in closures, in which case a
static instance should be used (escaping uninitialized this is
prohibited by JVM). Actually using this static instance before it is
initialized (e.g., invoking a method that uses this singleton) will
cause a correct ExceptionInInitializerError.

After a super constructor call, static instance of a singleton may be
not initialized yet (in case of enum entries and interface companion
objects). However, we already have an initialized 'this', which we
should use for singleton references.

 #KT-20651 Fixed
2017-10-09 16:27:34 +03:00
Anton Bannykh
49bc9249a1 JS: add support for the ::foo syntax (callable reference with empty LHS) 2017-09-13 20:12:48 +03:00
Dmitry Petrov
6b6d1e80f8 Fix enum entry reference from enum entry initialization context
Enum entries are "special" kind of singletons that should be
referenced as a captured 'this' instance inside during entry
initialization, because corresponding static fields in enum class
are not initialized yet.

 #KT-7257 Fixed
2017-09-12 11:00:24 +03:00
Dmitry Petrov
66ece54b25 Fix initialization of inner class instances in enum entries
In an inner class of the enum entry class, enum entry reference should
be generated as an outer 'this', not as a enum entry access, because
enum entry itself may be not initialized yet.
2017-09-11 09:42:18 +03:00
Alexey Andreev
8fe96664b7 Fix initialization order of enum with companion object in JS BE
Make enum entries initialize before companion object. This helps
in situation when companion object initializer refers to enum fields.
JVM be generates <clinit> method which first initializes all enum fields
and then runs companion object initializer. This commit introduces the
similar behaviour in JS BE. The old behaviour was: initialize companion
object in constructor. In enum, constructor is called to initialize
enum fields, so previously companion object was initialized first,
which is incorrect.

See KT-16745
2017-03-28 11:32:46 +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
Denis Zharkov
ecec87cbc7 Refine signature calculation for methods with default parameters
The problem was that he number of mask parameters for defaults when
generating methods declaration was being calculated upon resulting signature
(with additional parameters: extension receivers, enum name/ordinal),
while on call-sites the masks number was calculated by the arguments number
in resolved call, i.e. by the number of real value parameters.

And because of the additional synthetic parameters (like enum.ordinal) these
two numbers could be different.

The solution is just to use value parameters number in both places.
Note, that we only count value parameters from the original sourse
declaration, ignoring synthetic ones generated by backend (e.g.
Continuation for suspend functions)

 #KT-14565 Fixed
2017-02-28 10:42:07 +03:00
Alexey Andreev
1c8478e46b JS: fix translation of enum entries without parentheses that call secondary constructors, constructors with default parameters and varargs. See KT-15900, KT-14097 2017-01-25 18:09:23 +03:00
Dmitry Petrov
ee9a174c1f KT-7897 Do not require to call enum constructor for each entry if all parameters have default values
Do not report an error on enum entry without initializer if all parameters have default values
(error is still reported if there is no such constructor, or if the constructor call is ambiguous).

Record resolved call on KtEnumEntry.

NB is the enum entry has a corresponding subclass, we still have to generate the "default" constructor call,
because FE doesn't know about the platform-specific representation of that class and its constructors.

See also KT-14097, KT-15900
2017-01-24 16:59:47 +03:00
Anton Bannykh
1957ac347a JS: make enum valueOf() throw if not found. 2016-12-15 17:58:40 +03:00
Zalim Bashorov
596f3364c6 Automatically mute failed tests 2016-11-09 21:41:12 +03:00
Mikhail Glukhikh
1a8181bdc4 Only private constructors for sealed / enum classes #KT-12377 Fixed
Also #KT-8497 Fixed
2016-05-23 13:08:57 +03:00
Alexander Udalov
bab127ad33 Remove some legacy codegen tests, move some to generated 2016-03-09 10:25:38 +03:00
Alexander Udalov
06a67e6602 Merge boxWithStdlib testData into box, delete BoxWithStdlib test 2016-03-09 10:25:38 +03:00
Mikhail Glukhikh
02fb19c3ea Inner classes are no more allowed inside enum entries #KT-9750 Fixed
Forbidden use-case deleted from codegen tests
2015-11-16 10:44:20 +03:00
Michael Bogdanov
b0efcec392 Fix for KT-9711: Exception in thread "main" java.lang.NoSuchFieldError: INSTANCE
#KT-9711 Fixed
2015-10-27 13:22:07 +03:00
Denis Zharkov
bd37a10677 Transform *Array.size to properties 2015-10-16 18:16:02 +03:00
Mikhail Glukhikh
f8a356747e Stdlib rename: 'name' and 'ordinal' are now properties in Enum, same name functions are deprecated 2015-10-14 20:40:13 +03:00
Mikhail Glukhikh
fa292ec0e0 Enum entries now can have no initializer if default secondary constructor is available. #KT-8484 Fixed 2015-09-02 18:23:07 +03:00
Mikhail Glukhikh
b2653ad1e9 Deprecated enum syntax removed: most compiler tests 2015-08-10 16:24:12 +03:00
Alexander Udalov
4de2c5a5c8 Don't generate default no-args constructor for enums
#KT-8438 Fixed
2015-07-13 11:59:35 +03:00
Alexander Udalov
df4d5a3ae2 Fix initialization order of enum entries and companion
#KT-5761 Fixed
2015-06-01 19:23:08 +03:00
Mikhail Glukhikh
1a312140e9 New enum syntax: Short constructor syntax introduced for entries, optional commas between entries, semicolon after entries. #KT-7605 Fixed.
Grammar changed accordingly.
Semicolons prohibited after an entry except the last one.
Only one initializer is allowed per entry.
EnumReferenceExpression AST node introduced.
Some tests fixed, a pair of new tests written. Kotlin code inside project fixed.
Formatter and intendation tests fixed accordingly.
Stub version is incremented.
2015-05-15 16:13:32 +03:00
Mikhail Glukhikh
cf741cb868 Enum parsing changed: first entries, then members. Grammar fixed accordingly.
A set of compiler tests and some plugin tests changed accordingly.
Compiler Kotlin code changed accordingly.
2015-05-15 16:13:27 +03:00
Dmitry Jemerov
4bdf598bfe compiler testdata: s/trait/interface 2015-05-12 19:43:17 +02:00
Pavel V. Talanov
06916d98c6 default -> companion: replace all mentions of default and default object 2015-03-17 15:47:39 +03:00
Pavel V. Talanov
59f192ef90 Replace 'class object' with 'default object' in renderers and test data
Includes changes to decompiled text
Old syntax is used in builtins and project code for now
2015-03-06 19:36:54 +03:00
Pavel V. Talanov
ffabe19229 Prohibit accessing nested classes/objects of class object using class literal
The fqname of class should be clear from code
Example: can't shorten A.Default.B.Default.C to A.B.C
Also fixes problem when nested class of enum class could be accessed via enum entry
2015-03-03 13:04:29 +03:00
Alexander Udalov
128c938965 Make Array.size() a function instead of a property
Also add a deprecated extension property to help migration. This is done to
unify getting size of arrays and collections
2014-11-17 15:02:38 +03:00
Alexander Udalov
6ec71b3fd1 Generate lambdas in enum entry super calls
#KT-4423 Fixed
2014-10-17 21:27:22 +04:00
Pavel V. Talanov
b2c288b62a Test super calls in enum literals 2014-10-10 18:12:56 +04:00
Pavel V. Talanov
8e6618920d Minor: rename test data file 2014-10-10 18:05:36 +04:00
Pavel V. Talanov
bb5998048f Test code generation for enum deriving from a trait 2014-10-10 17:43:33 +04:00
Alexander Udalov
e0ee890486 Move properties of enum class object to the enum class
Similar to how it's done for usual classes
2014-09-11 17:56:43 +04:00
Alexander Udalov
b52f337f7f Drop enum class object hack
Place valueOf() and values() into the static scope of the corresponding enum
class

 #KT-5580 Fixed
 #KT-2410 Fixed
2014-09-09 20:42:37 +04:00
Svetlana Isakova
9d366cb896 Prohibit local objects and enum classes
#KT-5402 Fixed
  #KT-4838 Fixed

Resolve type of object inside local object as special, not supertype('Any').
Changed visibility of constructor of anonymous object to 'internal' to be able to resolve the following:
fun box(): String {
    var foo = object {
        val bar = object {
            val baz = "ok"
        }
    }
    return foo.bar.baz
}
The containing declaration of property initializers is constructor, so 'baz' was invisible inside private constructor.
2014-09-01 12:32:52 +04:00
Alexander Udalov
3a0aac4857 Simplify type mapping logic in CodegenBinding
- inline asmType to calling getAsmType, which does something more
- refactor getJvmInternalName to use getAsmType as well
- simplify getAsmType and fix a probable bug in mapping singletons nested in
  enums (which wasn't reproduced, though a test is added)
- delete unnnecessary ASM_TYPE recording for enum entries in
  CodegenAnnotatingVisitor
2014-05-08 16:45:15 +04:00
Alexander Udalov
f7235e9d82 Fix abstract nested class in enums in JVM back-end
It caused InstantiationError because the enum had an incorrect ACC_ABSTRACT
flag
2014-04-24 16:10:13 +04:00
Alexander Udalov
5a1daaa4b6 Generate values()/valueOf() even for empty enums 2013-10-17 19:01:45 +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