Skip to content

Commit 1f2e314

Browse files
committed
Drop redundant Widen operator from RHS of subtyping rule
Statement 1: if (Widen(X) <: Widen(Y)) is true expression then Widen(X) <: Y stays true expression Statement 2: There is no such X and Y that the both following expressions evaluate to true Widen(X) <: Widen(Y) is false Widen(X) <: Y is true In general case, statement 2 is not valid In our specific case where Widen is defined the way it's defined, statement 2 is valid Given that in our case statement 1 and statement 2 are both valid, Widen is redundant in the RHS and confuses readers Informally: the intention is to make the widened type more appealing for the overload resolution, so only LHS should be widened
1 parent 6906848 commit 1f2e314

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

docs/src/md/kotlin.core/builtins.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ $\Widen(T)$ for a built-in integer type $T$ is defined as follows:
111111
- $\Widen(T) = T$ for any other $T$
112112

113113
> Informally: $\Widen$ means, for the purposes of overload resolution, $\Int$ is preferred over any other built-in integer type and $\Short$ is preferred to $\Byte$.
114-
> Using $\Widen$, we can reduce this priority to subtyping: $T$ is more preferred than $U$ if $\Widen(T) <: \Widen(U)$; this scheme allows to handle built-in integer types transparently when selecting the [most specific overload candidate][Algorithm of MSC selection].
114+
> Using $\Widen$, we can reduce this priority to subtyping: $T$ is more preferred than $U$ if $\Widen(T) <: U$; this scheme allows to handle built-in integer types transparently when selecting the [most specific overload candidate][Algorithm of MSC selection].
115115
>
116116
> For example, consider the following two functions:
117117
>
@@ -125,7 +125,7 @@ $\Widen(T)$ for a built-in integer type $T$ is defined as follows:
125125
> ```
126126
>
127127
> As the integer literal 2 has a type that is applicable for both versions of `foo` (see [Overload resolution section][Overload resolution] for details) and the types `kotlin.Int` and `kotlin.Short` are not related w.r.t. subtyping, it would not be possible to select a more specific candidate out of the two.
128-
> However, if we consider $\Widen(\Int)$ and $\Widen(\Short)$ respectively as the types of `value`, first candidate becomes more specific than the second, because $\Widen(\Int) <: \Widen(\Short)$.
128+
> However, if we consider $\Widen(\Int)$ and $\Short$ respectively as the types of `value`, first candidate becomes more specific than the second, because $\Widen(\Int) <: \Short$.
129129
130130
### Built-in floating point arithmetic types
131131

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ The selection process uses the [type constraint][Kotlin type constraints] facili
427427
For every two distinct members of the candidate set $F_1$ and $F_2$, the following constraint system is constructed and solved:
428428
429429
- For every non-default argument of the call and their corresponding declaration-site parameter types $X_1, \ldots, X_N$ of $F_1$ and $Y_1, \ldots, Y_N$ of $F_2$, a type constraint $X_K <: Y_K$ is built **unless both $X_K$ and $Y_K$ are [built-in integer types][Built-in integer types].**
430-
If both $X_K$ and $Y_K$ are built-in integer types, a type constraint $\Widen(X_K) <: \Widen(Y_K)$ is built instead, where $\Widen$ is the [integer type widening] operator.
430+
If both $X_K$ and $Y_K$ are built-in integer types, a type constraint $\Widen(X_K) <: Y_K$ is built instead, where $\Widen$ is the [integer type widening] operator.
431431
During construction of these constraints, all declaration-site type parameters $T_1, \ldots, T_M$ of $F_1$ are considered bound to fresh type variables $T^{\sim}_1, \ldots, T^{\sim}_M$, and all type parameters of $F_2$ are considered free;
432432
- If $F_1$ and $F_2$ are extension callables, their extension receivers are also considered non-default arguments of the call, even if implicit, and the corresponding constraints are added to the constraint system as stated above.
433433
For non-extension callables, only declaration-site parameters are considered;

0 commit comments

Comments
 (0)