Skip to content

Commit 98d7d32

Browse files
committed
More typeType fixes
1 parent 0146316 commit 98d7d32

File tree

1 file changed

+52
-45
lines changed

1 file changed

+52
-45
lines changed

specification/dartLangSpec.tex

Lines changed: 52 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4971,9 +4971,11 @@ \subsection{Superinterfaces}
49714971
is not a class building type
49724972
(\ref{classBuildingTypes}).
49734973
It is a \Error{compile-time error} if two elements in said type list
4974-
specifies the same type.
4975-
It is a \Error{compile-time error} if the superclass of a class $C$ is
4976-
one of the elements of the type list of the \IMPLEMENTS{} clause of $C$.
4974+
denotes the same type
4975+
(\ref{typeType}).
4976+
It is a \Error{compile-time error} if the superclass of a class $C$ denotes
4977+
the same type as one of the elements of
4978+
the type list of the \IMPLEMENTS{} clause of $C$.
49774979

49784980
\rationale{%
49794981
One might argue that it is harmless to repeat a type in the superinterface list,
@@ -7799,15 +7801,9 @@ \subsubsection{Auxiliary Concepts for Instantiation to Bound}
77997801
Meta-variables
78007802
(\ref{metaVariables})
78017803
like $S$ and $T$ are understood to denote types,
7802-
and they are considered to be equal (as in `$S$ is $T$')
7803-
in the same sense as in the section about subtype rules
7804-
(\ref{subtypeRules}).
7805-
%
7806-
In particular,
7807-
even though two identical pieces of syntax may denote two distinct types,
7808-
and two different pieces of syntax may denote the same type,
7809-
the property of interest here is whether they denote the same type
7810-
and not whether they are spelled identically.
7804+
and they are considered to be or not be the same type
7805+
in the same sense as in the section about the type \code{Type}
7806+
(\ref{typeType}).
78117807

78127808
The intuition behind the situation where a type raw-depends on another type is
78137809
that we need to compute any missing type arguments for the latter
@@ -11300,9 +11296,10 @@ \subsubsection{Sets}
1130011296
$o_2$ with contents $o_{21}, \ldots, o_{2n}$ and actual type argument $t_2$
1130111297
be the result of evaluating them.
1130211298
Then \code{identical($o_1$, $o_2$)} evaluates to \TRUE{} if{}f
11303-
%% TODO(eernst): Refer to nnbd notion of 'same type'.
11304-
\code{$t_1$ == $t_2$} and \code{identical($o_{1i}$, $o_{2i}$)}
11305-
evaluates to \TRUE{} for all $i \in 1 .. n$.
11299+
\code{identical($T_1$, $T_2$)} evaluates to \TRUE{}
11300+
(\ref{typeType}),
11301+
and \code{identical($o_{1i}$, $o_{2i}$)} evaluates to \TRUE{}
11302+
for all $i \in 1 .. n$.
1130611303

1130711304
\commentary{%
1130811305
In other words, constant set literals are canonicalized if they have
@@ -15043,9 +15040,9 @@ \subsubsection{Instance Method Closurization}
1504315040

1504415041
\LMHash{}%
1504515042
If $T$ is a non-generic class then for $j \in 1 .. n+k$,
15046-
%% TODO(eernst): Refer to nnbd notion of 'same type'.
15047-
$T_j$ is a type annotation that denotes the same type as that
15048-
which is denoted by the type annotation on
15043+
$T_j$ is a type annotation that denotes the same type
15044+
(\ref{typeType})
15045+
as that which is denoted by the type annotation on
1504915046
the corresponding parameter declaration in $D$.
1505015047
If that parameter declaration has no type annotation then $T_j$ is \DYNAMIC.
1505115048

@@ -15197,9 +15194,9 @@ \subsubsection{Super Closurization}
1519715194

1519815195
\LMHash{}%
1519915196
If $S$ is a non-generic class then for $j \in 1 .. n+k$,
15200-
%% TODO(eernst): Refer to nnbd notion of 'same type'.
15201-
$T_j$ is a type annotation that denotes the same type as that
15202-
which is denoted by the type annotation on
15197+
$T_j$ is a type annotation that denotes the same type
15198+
(\ref{typeType})
15199+
as that which is denoted by the type annotation on
1520315200
the corresponding parameter declaration in $D$.
1520415201
If that parameter declaration has no type annotation then $T_j$ is \DYNAMIC.
1520515202

@@ -15458,8 +15455,7 @@ \subsubsection{Generic Method Instantiation}
1545815455
Consider the situation where the program evaluates
1545915456
two invocations of this method with the same receiver $o$,
1546015457
and with actual type arguments whose actual values are
15461-
%% TODO(eernst): Refer to nnbd notion of 'same type'.
15462-
the same types \List{t}{1}{s} for both invocations,
15458+
the same types (\ref{typeType}) \List{t}{1}{s} for both invocations,
1546315459
and assume that the invocations returned
1546415460
the instances $o_1$ respectively $o_2$.
1546515461
%
@@ -21771,7 +21767,8 @@ \subsubsection{Subtype Rules}
2177121767
\IndexCustom{instantiating}{instantiation!subtype rule}
2177221768
it, that is, by consistently replacing
2177321769
each occurrence of a given meta-variable by
21774-
concrete syntax denoting the same type.
21770+
concrete syntax denoting the same type
21771+
(\ref{typeType}).
2177521772

2177621773
\commentary{%
2177721774
In general, this means that two or more occurrences of
@@ -22271,7 +22268,7 @@ \subsection{Type Nullability}
2227122268
so it cannot be non-nullable.
2227222269

2227322270
It follows that all four concepts are distinct:
22274-
The same type $X$ is potentially nullable, but not nullable,
22271+
The given type $X$ is potentially nullable, but not nullable,
2227522272
and $X$ is also potentially non-nullable, but not non-nullable.%
2227622273
}
2227722274

@@ -22411,7 +22408,7 @@ \subsection{Functions Dealing with Extreme Types}
2241122408
\TopMergeTypeName{} of the first two,
2241222409
and then recursively taking \TopMergeTypeName{} of the rest.
2241322410
\commentary{The ordering of the arguments makes no difference.}
22414-
22411+
2241522412
\LMHash{}%
2241622413
The \Index{\IsTopTypeName} predicate is true for any type which is in
2241722414
the equivalence class of top types.
@@ -22427,7 +22424,7 @@ \subsection{Functions Dealing with Extreme Types}
2242722424
\end{itemize}
2242822425

2242922426
\noindent
22430-
The \Index{\IsObjectTypeName} predicate is true if{}f
22427+
The \Index{\IsObjectTypeName} predicate is true if{}f
2243122428
the argument is a subtype and a supertype of \code{Object}.
2243222429

2243322430
\begin{itemize}
@@ -23136,17 +23133,27 @@ \subsection{Type Type}
2313623133
We define what it means for two types to be the same as follows:
2313723134
Let $T_1$ and $T_2$ be types.
2313823135
Let $U_j$ be the transitive alias expansion
23139-
(\ref{typedef}) of $T_j$, for $j \in 1 .. 2$.
23140-
We say that $T_1$ and $T_2$ are the \Index{same type}
23141-
if{}f \NormalizedTypeOf{$U_1$} and \NormalizedTypeOf{$U_2$}
23142-
(\ref{typeNormalization})
23143-
are syntactically equal,
23136+
(\ref{typedef}) of $T_j$, for $j \in 1 .. 2$,
23137+
and let $S_j$ be \NormalizedTypeOf{$U_j$}, for $j \in 1 .. 2$
23138+
(\ref{typeNormalization}).
23139+
We then say that $T_1$ and $T_2$ are the \Index{same type}
23140+
if{}f $S_1$ and $S_2$ are syntactically equal,
2314423141
up to equivalence of bound variables,
2314523142
and up to replacement of identifiers or qualified identifiers
2314623143
resolving to the same type declaration
2314723144
(\commentary{%
2314823145
e.g., \code{C} and \code{prefix.C} could resolve to
2314923146
the same class declaration%
23147+
}),
23148+
and excluding the case where two identifiers or qualified identifiers
23149+
occurring at corresponding positions in $S_1$ and $S_2$
23150+
are syntactically identical,
23151+
but resolve to different declarations
23152+
(\commentary{%
23153+
e.g., one occurrence of \code{C} could resolve to a
23154+
class declaration imported from a library $L_1$,
23155+
and another occurrence of \code{C} could resolve to a
23156+
class declaration imported from a different library $L_2$%
2315023157
}).
2315123158

2315223159
\LMHash{}%
@@ -23194,9 +23201,9 @@ \subsection{Type Type}
2319423201
(\ref{constants})
2319523202
evaluating to $o_1$ respectively $o_2$,
2319623203
which are reified types reifying the types $T_1$ respecively $T_2$.
23197-
Let $v_1$ and $v_2$ be fresh variables bound to $o_1$ respectively $o_2$
23204+
Let $v_1$ and $v_2$ be fresh variables bound to $o_1$ respectively $o_2$.
2319823205
We then have \code{identical($v_1$, $v_2$)} if{}f
23199-
\code{$T_1$\,\,==\,\,$T_2$}.
23206+
\code{$v_1$\,\,==\,\,$v_2$}.
2320023207

2320123208
\commentary{%
2320223209
In other words, constant reified types are canonicalized.
@@ -23816,22 +23823,22 @@ \subsubsection{Void Soundness}
2381623823
\ABSTRACT{} \CLASS A<X> \{
2381723824
final X x;
2381823825
A(this.x);
23819-
Object foo(X x);
23826+
Object? foo(X x);
2382023827
\}
2382123828
\\
2382223829
\CLASS{} B<X> \EXTENDS{} A<X> \{
2382323830
B(X x): super(x);
23824-
Object foo(Object x) => x;
23831+
Object? foo(Object? x) => x;
2382523832
\}
2382623833
\\
23827-
Object f<X>(X x) => x;
23834+
Object? f<X>(X x) => x;
2382823835
\\
2382923836
\VOID{} main() \{
2383023837
\VOID x = 42;
2383123838
print(f(x)); // \comment{(1)}
2383223839
\\
2383323840
A<\VOID{}> a = B<\VOID{}>(x);
23834-
A<Object> aObject = a;
23841+
A<Object?> aObject = a;
2383523842
print(aObject.x); // \comment{(2)}
2383623843
print(a.foo(x)); // \comment{(3)}
2383723844
\}
@@ -23848,25 +23855,25 @@ \subsubsection{Void Soundness}
2384823855
which is or contains a type variable whose value could be \VOID,
2384923856
so we are allowed to return \code{x} in the body of \code{f},
2385023857
even though this means that we indirectly get access to the value
23851-
of an expression of type \VOID, under the static type \code{Object}.
23858+
of an expression of type \VOID, under the static type \code{Object?}.
2385223859

2385323860
At (2), we indirectly obtain access to the value of
2385423861
the variable \code{x} with type \VOID,
2385523862
because we use an assignment to get access to the instance of \code{B}
2385623863
which was created with type argument \VOID{} under the type
23857-
\code{A<Object>}.
23858-
Note that \code{A<Object>} and \code{A<\VOID{}>} are subtypes of each other,
23864+
\code{A<Object?>}.
23865+
Note that \code{A<Object?>} and \code{A<\VOID{}>} are subtypes of each other,
2385923866
that is, they are equivalent according to the subtype rules,
2386023867
so neither static nor dynamic type checks will fail.
2386123868

2386223869
At (3), we indirectly obtain access to the value of
2386323870
the variable \code{x} with type \VOID{}
23864-
under the static type \code{Object},
23871+
under the static type \code{Object?},
2386523872
because the statically known method signature of \code{foo}
2386623873
has parameter type \VOID,
2386723874
but the actual implementation of \code{foo} which is invoked
23868-
is an override whose parameter type is \code{Object},
23869-
which is allowed because \code{Object} and \VOID{} are both top types.%
23875+
is an override whose parameter type is \code{Object?},
23876+
which is allowed because \code{Object?} and \VOID{} are both top types.%
2387023877
}
2387123878

2387223879
\rationale{%
@@ -23887,7 +23894,7 @@ \subsubsection{Void Soundness}
2388723894
from one variable or parameter to the next one, all with type \VOID,
2388823895
explicitly, or as the value of a type parameter.
2388923896
In particular, we could require that method overrides should
23890-
never override return type \code{Object} by return type \VOID,
23897+
never override return type \code{Object?} by return type \VOID,
2389123898
or parameter types in the opposite direction;
2389223899
parameterized types with type argument \VOID{} could not be assigned
2389323900
to variables where the corresponding type argument is anything other than

0 commit comments

Comments
 (0)