Skip to content

Commit 7bb3bfc

Browse files
committed
Merge branch 'develop' into release
2 parents 45db764 + b7e13e2 commit 7bb3bfc

File tree

917 files changed

+242669
-9815
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

917 files changed

+242669
-9815
lines changed

docs/src/md/commands.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<#mode quote>
22

3-
\newcommand{\currentKotlinMajorVersion}{\textrm{1.8}}
3+
\newcommand{\currentKotlinMajorVersion}{\textrm{1.9}}
44

55
\newcommand{\opMathTT}[2]{%
66
\expandafter\newcommand{#1}{\operatorname{\texttt{#2}}}%
@@ -82,6 +82,7 @@
8282
\opMathIT{\nested}{nested}
8383
\opMathIT{\dataClass}{dataClass}
8484
\opMathIT{\dataClassParam}{dp}
85+
\opMathIT{\dataObject}{dataObject}
8586

8687
\opMathIT{\name}{name}
8788
\opMathIT{\type}{type}

docs/src/md/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: Kotlin language specification
44
author:
55
- Marat Akhin
66
- Mikhail Belyaev
7-
subtitle: Version 1.8-rfc+0.1
7+
subtitle: Version 1.9-rfc+0.1
88
---
99

1010
<#include "commands.md">

docs/src/md/kotlin.core/annotations.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ An annotation type is a special kind of class type which is allowed to include r
1717
- Other annotation types;
1818
- [Arrays][Array types] of any type listed above.
1919

20+
> Important: when we say "other annotation types", we mean an annotation type cannot reference itself, either directly or indirectly.
21+
> For example, if annotation type `A` references annotation type `B` which references an array of `A`, it is prohibited and reported as a compile-time error.
22+
2023
Annotation classes are not allowed to have any member functions, constructors or mutable properties.
2124
They are also not allowed to have declared supertypes and are considered to be implicitly derived from `kotlin.Annotation`.
2225

docs/src/md/kotlin.core/declarations.md

Lines changed: 68 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,8 @@ As such, data classes allow Kotlin to reduce the boilerplate and generate a numb
403403
- `equals(that)` returns true iff:
404404
- `that` has the same runtime type as `this`;
405405
- `this.prop == that.prop` returns `true` for every data property `prop`;
406-
- `hashCode()` returns the same numbers for objects `A` and `B` if they are equal w.r.t. the generated `equals`;
407-
- `toString` returns a string representations which is guaranteed to include the class name along with all the data properties' string representations.
406+
- `hashCode()` returns the same numbers for values `A` and `B` if they are equal w.r.t. the generated `equals`;
407+
- `toString()` returns a string representations which is guaranteed to include the class name along with all the data properties' string representations.
408408
* A `copy()` function for shallow object copying with the following properties:
409409
- It has the same number of parameters as the primary constructor with the same names and types;
410410
- It calls the primary constructor with the corresponding parameters at the corresponding positions;
@@ -499,6 +499,35 @@ Data classes have the following restrictions:
499499
>
500500
> Disclaimer: the implementations of these methods given in this examples are not guaranteed to exactly match the ones generated by kotlin compiler, please refer to the descriptions of these methods above for guarantees
501501
502+
##### Data object declaration
503+
504+
> Note: as of Kotlin $\currentKotlinMajorVersion{}$, this feature is experimental.
505+
506+
A data object $\dataObject$ is a special kind of [object][Object declaration], which extends the [data class][Data class declaration] abstraction (product type of one or more data properties) to a case of unit type: product type of zero data properties.
507+
508+
> Note: unit type has only one possible value, thus it is also known as singleton type.
509+
510+
Similarly to data classes, there are a number of functions with predefined behaviour generated for data objects.
511+
512+
* `equals() / hashCode() / toString()` functions compliant with [their contracts][`kotlin.Any`-builtins]:
513+
- `equals(that)` returns true iff `that` has the same runtime type as `this`;
514+
- `hashCode()` returns the same numbers for values `A` and `B` if they are equal w.r.t. the generated `equals`;
515+
- `toString()` returns a string representations which is guaranteed to include the object name.
516+
517+
> Note: `copy()` and `componentN()` functions are not generated, as they are not relevant for a unit type.
518+
>
519+
> * `copy()` function is not needed as unit type has a single possible value;
520+
> * `componentN()` functions are not needed as unit type has no data properties.
521+
522+
Unlike data classes, however, for data objects the only generated function which can be exemplified or inherited is `toString()`; `equals()` and `hashCode()` for a data object always work as specified above.
523+
This is to ensure data objects do not violate the unit type invariant of "being inhabited by only one value", which would be possible if one were to provide a custom `equals()` implementation.
524+
525+
If either `equals()` or `hashCode()` function would be exemplified or inherited by a data object, it is a compile-time error.
526+
527+
Data objects have the same restrictions are regular [objects][Object declaration].
528+
529+
> Note: [companion objects][Class declaration] and [object literals][Object literals] cannot be data objects.
530+
502531
#### Enum class declaration
503532
504533
Enum class $E$ is a special kind of class with the following properties:
@@ -510,6 +539,8 @@ Enum class $E$ is a special kind of class with the following properties:
510539
- It cannot have type parameters of any kind;
511540
- It has special syntax to accommodate for the properties described above.
512541
542+
> Note: for the purposes of overload resolution, enum entries are considered to be [static member callables][Call with an explicit type receiver] of the enum class type
543+
513544
Enum class body uses special kind of syntax (see grammar) to declare enum entries in addition to all other declarations inside the class body.
514545
Enum entries have their own bodies that may contain their own declarations, similar to [object declarations][Classifier declaration].
515546
@@ -542,27 +573,41 @@ Every enum entry of class `E` implicitly overrides members of `kotlin.Enum<E>` i
542573
543574
(a member of `kotlin.Any`) defined by default to return the entry name, but may be overridden to have different behaviour both in the enum class declaration and in entry declarations.
544575
545-
In addition to these, every enum class type `E` has the following **static** member functions declared implicitly:
576+
In addition to these, every enum class type `E` has the following **static** members declared implicitly:
577+
578+
- ```kotlin
579+
public final static val entries: EnumEntries<E>
580+
```
581+
582+
This property returns an instance of a special immutable `EnumEntries<E>` list of all possible enum values in the order they are declared;
546583
547584
- ```kotlin
548585
public final static fun valueOf(value: String): E
549586
```
550587
551-
returning an object corresponding to the entry with the name equal to `value` parameter of the call or throws an exception otherwise;
588+
This function returns an object corresponding to the entry with the name equal to `value` parameter of the call or throws an exception otherwise.
589+
590+
> Important: `static` is not a valid Kotlin keyword and is only used here for clarity.
591+
> The static members are handled differently by the [overload resolution][Call with an explicit type receiver].
592+
593+
Kotlin standard library also introduces a function to access all enum values for a specific enum class called `kotlin.enumEntries<T>`.
594+
Please refer to the standard library documentation for details.
595+
596+
> Note: the `entries` property is available since Kotlin 1.9.
597+
598+
For backwards compatibility, in addition to the `entries` property, every enum class type `E` has the following **static** member function declared implicitly.
552599
553600
- ```kotlin
554601
public final static fun values(): kotlin.Array<E>
555602
```
556-
557-
returning an [array][Array types] of all possible enum values in the order they are declared.
558-
Every invocation of this function returns a new array to disallow changing its contents.
559603
560-
> Important: `static` is not a valid Kotlin keyword and is only used here for clarity
604+
This function returns an [array][Array types] of all possible enum values in the order they are declared.
605+
Every invocation of this function returns a new array to disallow changing its contents.
561606
562-
> Note: these static member functions are handled differently by the [overload resolution][Overload resolution].
607+
> Important: `values` function is effectively deprecated and `entries` property should be used instead.
563608
564-
> Note: Kotlin standard library introduces another function to access all enum values for a specific enum class called `kotlin.enumValues<T>`.
565-
> Please refer to the standard library documentation for details.
609+
Kotlin standard library also introduces another function to access all enum values for a specific enum class called `kotlin.enumValues<T>` (which is deprecated for subsequent removal).
610+
Please refer to the standard library documentation for details.
566611
567612
> Example:
568613
>
@@ -622,6 +667,9 @@ Annotation classes have the following properties:
622667
- Other annotation types;
623668
- Arrays of any other allowed type.
624669
670+
> Important: when we say "other annotation types", we mean an annotation type cannot reference itself, either directly or indirectly.
671+
> For example, if annotation type `A` references annotation type `B` which references an array of `A`, it is prohibited and reported as a compile-time error.
672+
625673
> Note: annotation classes can have type parameters, but cannot use them as types for their primary constructor parameters.
626674
> Their main use is for various annotation processing tools, which can access the type arguments from the source code.
627675
@@ -796,6 +844,8 @@ Similarly to interfaces, we shall specify object declarations by highlighting th
796844
> Note: this section is about declaration of _named_ objects.
797845
> Kotlin also has a concept of _anonymous_ objects, or object literals, which are similar to their named counterparts, but are expressions rather than declarations and, as such, are described in the [corresponding section][Object literals].
798846
847+
> Note: besides regular object declarations, Kotlin supports [data object declarations][Data object declaration].
848+
799849
#### Local class declaration
800850
801851
A class (but not an interface or an object) may be declared *locally* inside a [statement scope][Scopes and identifiers] (namely, inside a function).
@@ -1130,6 +1180,8 @@ They may also be passed to other functions as `noinline` or `crossinline` argume
11301180
11311181
Particular platforms may introduce additional restrictions or guarantees for the inlining mechanism.
11321182
1183+
> Important: for extension functions, the extension receiver is considered to be effectively `noinline`.
1184+
11331185
> Examples:
11341186
>
11351187
> ```kotlin
@@ -1385,7 +1437,9 @@ Properties without backing fields are not allowed to have initializer expression
13851437
13861438
Read/write access to the property is replaced with getter/setter invocation respectively.
13871439
Getters and setters allow for some modifiers available for function declarations (for example, they may be declared `inline`, see grammar for details).
1440+
13881441
Properties themselves may also be declared `inline`, meaning that both getter and setter of said property are `inline`.
1442+
Additionally, `inline` properties are not allowed to have backing fields, i.e., they must have custom accessors which do not use the `field` property.
13891443
13901444
#### Delegated property declaration
13911445
@@ -1706,7 +1760,6 @@ The following declarations are not allowed to have type parameters:
17061760
- Constructor declarations;
17071761
- Getters and setters of property declarations;
17081762
- Enum class declarations;
1709-
- Annotation class declarations;
17101763
- Classifier declarations inheriting from `kotlin.Throwable`.
17111764
17121765
Type parameters are allowed to specify *subtyping restrictions* on them in the form `T : U`, meaning $T <: U$ where $T$ is a type parameter and $U$ is some other type available in the scope the declaration is declared in.
@@ -1791,9 +1844,9 @@ By supplying this annotation the author of the code explicitly declares that saf
17911844
17921845
#### Reified type parameters
17931846
1794-
Type parameters of inline function declarations (and only those) can be declared `reified` using the corresponding keyword.
1795-
A reified type parameter is a [runtime-available][Runtime-available types] type inside the function scope, see the corresponding section for details.
1796-
Reified type parameters can only be substituted by other [runtime-available types][Runtime-available types] when using such functions.
1847+
Type parameters of inline function or property declarations (and only those) can be declared `reified` using the corresponding keyword.
1848+
A reified type parameter is a [runtime-available][Runtime-available types] type inside their declaration's scope, see the corresponding section for details.
1849+
Reified type parameters can only be substituted by other [runtime-available types][Runtime-available types] when using such declarations.
17971850
17981851
> Example:
17991852
>

docs/src/md/kotlin.core/expressions.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ If when expression is not [exhaustive][Exhaustive when expressions], it has type
418418
> }
419419
> ```
420420
421-
When with bound value also allows for an inline property declaration of the form `when (val V = E) { ... }` inside the parentheses.
421+
When with bound value also allows for an in-place property declaration of the form `when (val V = E) { ... }` inside the parentheses.
422422
This declares a new property (see [declaration sections][Property declaration] for details) alongside the usual mechanics of the *when-expression*.
423423
The scope of this property is limited to the `when` expression, including both conditions and control structure bodies of the expression.
424424
As its form is limited to a simple "assignment-like" declaration with an initializer, this property does not allow getters, setters, delegation or destructuring.
@@ -711,15 +711,16 @@ The type of elvis operator expression is the [least upper bound][Least upper bou
711711
:::{.paste target=grammar-rule-rangeExpression}
712712
:::
713713
714-
A *range expression* is a binary expression which uses a range operator `..`.
715-
It is an [overloadable][Operator overloading] operator with the following expansion:
714+
A *range expression* is a binary expression which uses a range operator `..` or a range-until operator `..<`.
715+
These are [overloadable][Operator overloading] operators with the following expansions:
716716
717717
- `A..B` is exactly the same as `A.rangeTo(B)`
718+
- `A..<B` is exactly the same as `A.rangeUntil(B)`
718719
719-
where `rangeTo` is a valid operator function available in the current scope.
720+
where `rangeTo` or `rangeUntil` is a valid operator function available in the current scope.
720721
721-
The return type of this function is not restricted.
722-
A range expression has the same type as the return type of the corresponding `rangeTo` overload variant.
722+
The return type of these functions is not restricted.
723+
A range expression has the same type as the return type of the corresponding operator function overload variant.
723724
724725
### Additive expressions
725726

docs/src/md/kotlin.core/overload-resolution.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,8 @@ They mostly follow the same rules as [calls with an explicit value receiver][Cal
230230
However, for a callable `f` with an explicit type receiver `T` the following sets are analyzed (**in the given order**):
231231
232232
1. Static member callables named `f` of type `T`;
233-
2. The overload candidate sets for call `T.f()`, where `T` is a companion object of type `T`.
233+
2. Static member callables named `f` of type `T` declared implicitly;
234+
3. The overload candidate sets for call `T.f()`, where `T` is a companion object of type `T`.
234235
235236
##### Call with an explicit super-form receiver
236237
@@ -730,6 +731,14 @@ TODO: more examples
730731
731732
> Note: this is different from the overload resolution for regular calls in that no most specific candidate selection process is performed inside the sets
732733
734+
> Important: when the callable reference resolution for `T::f` requires building overload candidate sets for both [type][Call with an explicit type receiver] and [value][Call with an explicit receiver] receiver candidates, they are considered in the following order.
735+
>
736+
> 1. Static member callables named `f` of type `T`;
737+
> 2. The overload candidate sets for call `t::f`, where `t` is a value of type `T`;
738+
> 3. The overload candidate sets for call `T::f`, where `T` is a companion object of type `T`.
739+
>
740+
> Callable references to members of companion objects are deprioritized, as you could always use the `T.Companion::f` syntax to reference them.
741+
733742
> Important: when building the OCS for a callable reference, `invoke` operator convention does not apply, and all property references are treated equally as function references, being placed in the same sets.
734743
> For example, consider the following code:
735744
>

grammar/scripts/compareActuals.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
TEST_DATA="$1"
44

55
for fo in `find ${TEST_DATA} -name "*.antlrtree.txt"`; do
6-
fa="$i.actual";
6+
fa="$fo.actual";
77
if [[ -e $fa ]]; then
88
meld $fa $fo;
99
fi

grammar/scripts/processModified.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
REF="$1"
44

5-
for i in `git status -s | grep "^M.*\.antlrtree.txt$" | cut -d ' ' -f 3`; do
5+
for i in `git status -s | grep "^ M.*\.antlrtree.txt$" | cut -d ' ' -f 3`; do
66
git diff --numstat HEAD $i | grep -q "$REF";
77
if [[ $? == 0 ]]; then
88
echo $i;

grammar/src/main/antlr/KotlinLexer.g4

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ MOD_ASSIGNMENT: '%=';
6868
ARROW: '->';
6969
DOUBLE_ARROW: '=>';
7070
RANGE: '..';
71+
RANGE_UNTIL: '..<';
7172
COLONCOLON: '::';
7273
DOUBLE_SEMICOLON: ';;';
7374
HASH: '#';
@@ -417,6 +418,7 @@ Inside_MOD_ASSIGNMENT: MOD_ASSIGNMENT -> type(MOD_ASSIGNMENT);
417418
Inside_ARROW: ARROW -> type(ARROW);
418419
Inside_DOUBLE_ARROW: DOUBLE_ARROW -> type(DOUBLE_ARROW);
419420
Inside_RANGE: RANGE -> type(RANGE);
421+
Inside_RANGE_UNTIL: RANGE_UNTIL -> type(RANGE_UNTIL);
420422
Inside_RESERVED: RESERVED -> type(RESERVED);
421423
Inside_COLONCOLON: COLONCOLON -> type(COLONCOLON);
422424
Inside_DOUBLE_SEMICOLON: DOUBLE_SEMICOLON -> type(DOUBLE_SEMICOLON);

0 commit comments

Comments
 (0)