@@ -13820,7 +13820,65 @@ \subsubsection{Ordinary Invocation}
13820
13820
Otherwise, the static analysis of $i$ is performed
13821
13821
as specified in Section~\ref{bindingActualsToFormals},
13822
13822
considering $F$ to be the static type of the function to call,
13823
- and the static type of $i$ is as specified there.
13823
+ and the static type of $i$ is as specified there,
13824
+ except that invocations of methods named \code{remainder}
13825
+ or \code{clamp} on subtypes of \code{num} that are not subtypes of \code{Never}
13826
+ have special rules similar to those for additive (\ref{additiveExpressions})
13827
+ and multipliative (\ref{multiplicativeExpressions}) operators.
13828
+
13829
+ \LMHash{}%
13830
+ Let $i$ be an invocation of the form \code{$e$.remainder($e_2$)}
13831
+ and let $C$ be the context type of $i$.
13832
+ The context type of $e_2$ is then determined as follows:
13833
+ If \SubtypeNE{T}{\code{num}} and not \SubtypeNE{T}{\code{Never}}, then:
13834
+ \begin{itemize}
13835
+ \item{} If \SubtypeNE{\code{int}}{C} and not \SubtypeNE{\code{num}}{C},
13836
+ and \SubtypeNE{T}{\code{int}}
13837
+ then the context type of $e_2$ is \code{int}.
13838
+ \item{} If \SubtypeNE{\code{double}}{C} and not \SubtypeNE{\code{num}}{C},
13839
+ and not \SubtypeNE{T}{\code{double}}
13840
+ then the context type of $e_2$ is \code{double}.
13841
+ \item{} Otherwise the context type of $e_2$ is \code{num}.
13842
+ \end{itemize}
13843
+ Let further $S$ be the static type of $e_2$.
13844
+ If \SubtypeNE{T}{\code{num}} and not \SubtypeNE{T}{\code{Never}}
13845
+ and $S$ is assignable to \code{num},
13846
+ then the static type of $i$ is determined as follows:
13847
+ \begin{itemize}
13848
+ \item{} If \SubtypeNE{T}{\code{double}}
13849
+ then the static type of $i$ is $T$.
13850
+ \item{} Otherwise, if \SubtypeNE{S}{\code{double}}
13851
+ and not \SubtypeNE{S}{\code{Never}},
13852
+ then the static type of $i$ is \code{double}.
13853
+ \item{} Otherwise, if \SubtypeNE{T}{\code{int}},
13854
+ \SubtypeNE{S}{\code{int}} and not \SubtypeNE{S}{\code{Never}},
13855
+ then the static type of $i$ is \code{int}.
13856
+ \item{} Otherwise the static type of $i$ is \code{num}.
13857
+ \end{itemize}
13858
+
13859
+ \LMHash{}%
13860
+ Let $i$ be an invocation of the form \code{$e$.clamp($e_2$,\,\,$e_3$)},
13861
+ where \SubtypeNE{T}{\code{num}} and not \SubtypeNE{T}{\code{Never}},
13862
+ and let $C$ be the context type of $i$.
13863
+ The context type of $e_2$ and $e_3$ is then determined as follows:
13864
+ \begin{itemize}
13865
+ \item{} If \SubtypeNE{T}{\code{int}},
13866
+ \SubtypeNE{\code{int}}{S} and not \SubtypeNE{\code{num}}{S},
13867
+ then the context type of $e_2$ and $e_3$ is \code{int}.
13868
+ \item{} If \SubtypeNE{T}{\code{double}},
13869
+ \SubtypeNE{\code{double}}{S} and not \SubtypeNE{\code{num}}{S},
13870
+ then the context type of $e_2$ and $e_3$ is \code{double}.
13871
+ \item{} Otherwise the context type of $e_2$ and $e_3$ is \code{num}.
13872
+ \end{itemize}
13873
+ Let further $T_2$ be the static type of $e_2$ and $T_3$ be the static type
13874
+ of $e_3$.
13875
+ \begin{itemize}
13876
+ \item{} If all of $T$, $T_2$ and $T_3$ are subtypes of \code{int}, but
13877
+ not subtypes of \code{Never}, then the static type of $i$ is \code{int}.
13878
+ \item{} If all of $T$, $T_2$ and $T_3$ are subtypes of \code{double}, but
13879
+ not subtypes of \code{Never}, then the static type of $i$ is \code{double}.
13880
+ \item{} Otherwise the static type of $i$ is \code{num}.
13881
+ \end{itemize}
13824
13882
13825
13883
\LMHash{}%
13826
13884
It is a compile-time error to invoke an instance method on a type literal
@@ -15913,19 +15971,43 @@ \subsection{Additive Expressions}
15913
15971
the method invocation \code{\SUPER.$op$($e_2$)}.
15914
15972
15915
15973
\LMHash{}%
15916
- The static type of an additive expression is usually determined by
15917
- the signature given in the declaration of the operator used.
15918
- However, invocations of the operators \code{+} and \code{-} of class \code{int}
15974
+ The static type of an additive expression is usually determined
15975
+ by the signature given in the declaration of the operator used.
15976
+ However, invocations of the operators \code{+} and \code{-} of
15977
+ class \code{int}, \code{double} and \code{num}
15919
15978
are treated specially by the typechecker.
15920
- The static type of an expression $e_1 + e_2$
15921
- where $e_1$ has static type \code{int}
15922
- is \code{int} if the static type of $e_2$ is \code{int},
15923
- and \code{double} if the static type of $e_2$ is \code{double}.
15924
- The static type of an expression $e_1 - e_2$
15925
- where $e_1$ has static type \code{int}
15926
- is \code{int} if the static type of $e_2$ is \code{int},
15927
- and \code{double} if the static type of $e_2$ is \code{double}.
15928
15979
15980
+ \LMHash{}%
15981
+ Let $e$ be an additive expression of the form \code{$e_1$ $op$ $e_2$},
15982
+ let $T$ be the static type of $e_1$,
15983
+ and let $C$ be the context type of $e$.
15984
+
15985
+ If \SubtypeNE{T}{\code{num}} and not \SubtypeNE{T}{\code{Never}}, then
15986
+ the context type of $e_2$ is determined as follows:
15987
+ \begin{itemize}
15988
+ \item{} If \SubtypeNE{\code{int}}{C} and not \SubtypeNE{\code{num}}{C},
15989
+ and \SubtypeNE{T}{\code{int}}
15990
+ then the context type of $e_2$ is \code{int}.
15991
+ \item{} If \SubtypeNE{\code{double}}{C} and not \SubtypeNE{\code{num}}{C},
15992
+ and not \SubtypeNE{T}{\code{double}}
15993
+ then the context type of $e_2$ is \code{double}.
15994
+ \item{} Otherwise the context type of $e_2$ is \code{num}.
15995
+ \end{itemize}
15996
+ Let further $S$ be the static type of $e_2$.
15997
+ If \SubtypeNE{T}{\code{num}} and not \SubtypeNE{T}{\code{Never}}
15998
+ and $S$ is assignable to \code{num},
15999
+ then the static type of $e$ is determined as follows:
16000
+ \begin{itemize}
16001
+ \item{} If \SubtypeNE{T}{\code{double}}
16002
+ then the static type of $e$ is $T$.
16003
+ \item{} Otherwise, if \SubtypeNE{S}{\code{double}}
16004
+ and not \SubtypeNE{S}{\code{Never}},
16005
+ then the static type of $e$ is \code{double}.
16006
+ \item{} Otherwise, if \SubtypeNE{T}{\code{int}},
16007
+ \SubtypeNE{S}{\code{int}} and not \SubtypeNE{S}{\code{Never}},
16008
+ then the static type of $e$ is \code{int}.
16009
+ \item{} Otherwise the static type of $e$ is \code{num}.
16010
+ \end{itemize}
15929
16011
15930
16012
\subsection{Multiplicative Expressions}
15931
16013
\LMLabel{multiplicativeExpressions}
@@ -15958,18 +16040,44 @@ \subsection{Multiplicative Expressions}
15958
16040
the method invocation \code{\SUPER.$op$($e_2$)}.
15959
16041
15960
16042
\LMHash{}%
15961
- The static type of an multiplicative expression is usually determined by
15962
- the signature given in the declaration of the operator used.
15963
- However, invocations of the operators \code{*} and \code{\%} of class \code{int}
16043
+ The static type of an multiplicative expression is usually determined
16044
+ by the signature given in the declaration of the operator used.
16045
+ However, invocations of the operators \code{*} and \code{\%} of
16046
+ class \code{int}, \code{double} and \code{num}
15964
16047
are treated specially by the typechecker.
15965
- The static type of an expression $e_1 * e_2$
15966
- where $e_1$ has static type \code{int}
15967
- is \code{int} if the static type of $e_2$ is \code{int},
15968
- and \code{double} if the static type of $e_2$ is \code{double}.
15969
- The static type of an expression $e_1 \% e_2$
15970
- where $e_1$ has static type \code{int}
15971
- is \code{int} if the static type of $e_2$ is \code{int},
15972
- and \code{double} if the static type of $e_2$ is \code{double}.
16048
+
16049
+ \LMHash{}%
16050
+ Let $e$ be a multiplicative expression of the form \code{$e_1$ $op$ $e_2$}
16051
+ where $op$ is one of \code{*} or \code{\%},
16052
+ let $T$ be the static type of $e_1$,
16053
+ and let $C$ be the context type of $e$.
16054
+
16055
+ If \SubtypeNE{T}{\code{num}} and not \SubtypeNE{T}{\code{Never}}, then
16056
+ the context type of $e_2$ is determined as follows:
16057
+ \begin{itemize}
16058
+ \item{} If \SubtypeNE{\code{int}}{C} and not \SubtypeNE{\code{num}}{C},
16059
+ and \SubtypeNE{T}{\code{int}}
16060
+ then the context type of $e_2$ is \code{int}.
16061
+ \item{} If \SubtypeNE{\code{double}}{C} and not \SubtypeNE{\code{num}}{C},
16062
+ and not \SubtypeNE{T}{\code{double}}
16063
+ then the context type of $e_2$ is \code{double}.
16064
+ \item{} Otherwise the context type of $e_2$ is \code{num}.
16065
+ \end{itemize}
16066
+ Let further $S$ be the static type of $e_2$.
16067
+ If \SubtypeNE{T}{\code{num}} and not \SubtypeNE{T}{\code{Never}}
16068
+ and $S$ is assignable to \code{num},
16069
+ then the static type of $e$ is determined as follows:
16070
+ \begin{itemize}
16071
+ \item{} If \SubtypeNE{T}{\code{double}}
16072
+ then the static type of $e$ is $T$.
16073
+ \item{} Otherwise, if \SubtypeNE{S}{\code{double}}
16074
+ and not \SubtypeNE{S}{\code{Never}},
16075
+ then the static type of $e$ is \code{double}.
16076
+ \item{} Otherwise, if \SubtypeNE{T}{\code{int}},
16077
+ \SubtypeNE{S}{\code{int}} and not \SubtypeNE{S}{\code{Never}},
16078
+ then the static type of $e$ is \code{int}.
16079
+ \item{} Otherwise the static type of $e$ is \code{num}.
16080
+ \end{itemize}
15973
16081
15974
16082
15975
16083
\subsection{Unary Expressions}
0 commit comments