Skip to content

Commit d69a9c9

Browse files
Small fixes to be squashed later
1 parent cc0cef0 commit d69a9c9

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

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

+11-11
Original file line numberDiff line numberDiff line change
@@ -1786,27 +1786,27 @@ See [the type system section][Mixed-site variance] for details.
17861786
17871787
We would consider a type expression `E` to be **covariant** in type parameter `X` if for every concrete type expressions `T1` and `T2` such that `T1 <: T2` it holds that `E[T1 / X] <: E[T2 / X]`. One could also say, that the *position* `X` takes in `E` is **covariant**.
17881788
1789-
Not nested covariant cases are the following:
1789+
Base covariant cases are the following:
17901790
17911791
- A type expression is covariant in type parameter `X`, if this parameter is explicitly declared as `out` either [in the expression itself][Use-site variance] or [in the type declaration][Declaration-site variance];
17921792
- Types of functions are covariant in their return type parameter, since functions have [types of kind][Function types] `FN<in A1, ..., in AN, out R>`);
17931793
- Types of read-only properties are effectively in covariant position;
17941794
17951795
In the same way, we would consider a type expression `E` to be **contravariant** in type parameter `X` if for every concrete type expressions `T1` and `T2` such that `T1 <: T2` it holds that `E[T2 / X] <: E[T1 / X]`.
17961796
1797-
Not nested contravariant cases are the following:
1797+
Base contravariant cases are the following:
17981798
17991799
- A type expression is contravariant in type parameter `X`, if this parameter is explicitly declared as `in` either [in the expression itself][Use-site variance] or [in the type declaration][Declaration-site variance];
18001800
- Types of functions are contravariant in their argument types, since functions have [types of kind][Function types] `FN<in A1, ..., in AN, out R>`;
18011801
18021802
Lastly, we would consider a type expression `E` to be **invariant** in type parameter `X` if for every concrete type expressions `T1` and `T2`, `E[T1 / X] <: E[T2 / X]` holds if and only if `T1 = T2` (`T1 <: T2` and `T2 <: T1`).
18031803
1804-
Not nested invariant cases are the following:
1804+
Base invariant cases are the following:
18051805
18061806
- A type expression is invariant in type parameter `X`, if this parameter is not declared as either `in` or `out` [in the expression itself][Use-site variance] or [in the type declaration][Declaration-site variance];
18071807
- Types of mutable properties are effectively in invariant position;
18081808
1809-
We will use `+` as a symbol denoting contravariance, `-` as a symbol denoting covariance and `o` as a symbol denoting invariance.
1809+
We will use `+` as a symbol denoting covariance, `-` as a symbol denoting contravariance and `o` as a symbol denoting invariance.
18101810
18111811
To infer variance of a complex type expression in a type parameter, variance composition is used, which is defined as follows:
18121812
@@ -1815,7 +1815,7 @@ To infer variance of a complex type expression in a type parameter, variance com
18151815
\begin{align*}
18161816
\texttt{+} \otimes x &= x \text{, where $x$ is any variance} \\
18171817
\texttt{-} \otimes \texttt{+} &= \texttt{-} \\
1818-
\texttt{-} \otimes \texttt{-} &= \texttt{-} \\
1818+
\texttt{-} \otimes \texttt{-} &= \texttt{+} \\
18191819
\texttt{o} \otimes x &= \texttt{o} \text{, where $x$ is any variance} \\
18201820
x \otimes \texttt{o} &= \texttt{o} \text{, where $x$ is any variance}
18211821
\end{align*}
@@ -1834,14 +1834,14 @@ When a type parameter has declared variance, and is used in a position of a diff
18341834
- A covariant type parameter is used as an argument to a contravariant position;
18351835
- A contravariant type parameter is used as an argument to a covariant position;
18361836
1837-
Important remark: variance conflict does not occur if the containing declaration is private to the type parameter owner (in which case its visibility is restricted, see the [visibility][Declaration visibility] section for details).
1837+
> Important remark: variance conflict does not occur if the containing declaration is private to the type parameter owner (in which case its visibility is restricted, see the [visibility][Declaration visibility] section for details).
18381838
18391839
This applies only to member declarations of the corresponding class, extensions are not subject to this limitation.
18401840
1841-
This restrictions may be lifted in particular cases by [annotating][Annotations] the corresponding type parameter usage with a special built-in annotation `kotlin.UnsafeVariance`.
1841+
These restrictions may be lifted in particular cases by [annotating][Annotations] the corresponding type parameter usage with a special built-in annotation `kotlin.UnsafeVariance`.
18421842
By supplying this annotation the author of the code explicitly declares that safety features that variance checks provide are not needed in this particular declarations.
18431843
1844-
> Basic Examples:
1844+
> Basic examples:
18451845
>
18461846
> ```kotlin
18471847
> interface Holder<T>
@@ -1888,13 +1888,13 @@ By supplying this annotation the author of the code explicitly declares that saf
18881888
> ```kotlin
18891889
> class Foo<in T>() // T is contravariant
18901890
>
1891-
> class Bar<in S>() { // T is contravariant
1891+
> class Bar<in S>() { // S is contravariant
18921892
> fun bar(x: Foo<S>) {} // ERROR, contravariant parameter in covariant usage
18931893
> // bar has type F1<in Foo<S>, out Unit>
18941894
> // Need to find variance of F1<in Foo<S>, out Unit> in S
18951895
> // F1<in P1, out R> is contravariant (-) in P1
18961896
> // Foo<S> is contravariant (-) in S
1897-
> // Applying variance composition: - $\otimes$ - = + (covariance)
1897+
> // Applying variance composition: - \text{$\otimes$} - = + (covariance)
18981898
> // Variance of F1<in Foo<S>, out Unit> in S -- covariance
18991899
> }
19001900
>
@@ -1911,7 +1911,7 @@ By supplying this annotation the author of the code explicitly declares that saf
19111911
> }
19121912
> ```
19131913
>
1914-
> Remark: cases `e`, `f`, `f2`, `g`, `g2` in Basic Examples are also examples of variance composition, since they are read-only fields. However, since read-only fields are of covariance (`+`) and for any variance $x$, $\texttt{+} \otimes x = x$, it was ommited at that point.
1914+
> Remark: cases `e`, `f`, `f2`, `g`, `g2` in "Basic examples" are also examples of variance composition, since they are read-only fields. However, since read-only fields are of covariance (`+`) and for any variance $x$, $\texttt{+} \otimes x = x$, it was omitted at that point.
19151915
>
19161916
> Any of these restrictions may be lifted using `@UnsafeVariance` annotation on the type argument:
19171917
>

0 commit comments

Comments
 (0)