Skip to content

Commit 238a752

Browse files
authored
Adjusted "Type Aliases" paragraph to outlaw explicit type arguments in F.staticMethod() (#1672)
The old text in the section 'Type Aliases' in the language specification implies that it is possible to invoke a static method staticMethod of a class C via a type alias F with type arguments: ```dart class C<X> { void staticMethod() {} } typedef F<X> = C<X>; void main() { F<int>.staticMethod(); // Not an error previously, now an error. } ``` With this commit, this is an error, which makes the spec consistent with the intentions and the language tests. This PR also changes the grammar such that a type alias can denote a <type> rather than just a <functionType>, hence "enabling" non-function type aliases in general.
1 parent e5d6c97 commit 238a752

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

specification/dartLangSpec.tex

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
% publishing a stable version of the specification).
3232
% - Add rule that a top-level pair of declarations with the same basename
3333
% is a compile-time error except when it is a getter/setter pair.
34+
% - Change grammar to enable non-function type aliases. Correct rule for
35+
% invoking `F.staticMethod()` where `F` is a type alias.
3436
%
3537
% 2.8 - 2.10
3638
% - Change several warnings to compile-time errors, matching the actual
@@ -20117,10 +20119,9 @@ \subsection{Type Aliases}
2011720119
because of the prominent occurrence of the token \TYPEDEF.%
2011820120
}
2011920121

20120-
%%TODO(eernst): With non-function type aliases, change <functionType> to <type>.
2012120122
\begin{grammar}
2012220123
<typeAlias> ::= \gnewline{}
20123-
\TYPEDEF{} <typeIdentifier> <typeParameters>? `=' <functionType> `;'
20124+
\TYPEDEF{} <typeIdentifier> <typeParameters>? `=' <type> `;'
2012420125
\alt \TYPEDEF{} <functionTypeAlias>
2012520126

2012620127
<functionTypeAlias> ::= <functionPrefix> <formalParameterPart> `;'
@@ -20333,23 +20334,24 @@ \subsection{Type Aliases}
2033320334
\code{\TYPEDEF{} $F$<\TypeParametersStd> = $T$;}
2033420335

2033520336
\noindent
20336-
and let \DefineSymbol{U} be a parameterized type of the form
20337-
\code{$F$<\List{U}{1}{s}>}
20338-
in a scope where $F$ denotes $D$.
20339-
Assume that the transitive alias expansion of $U$ is
20340-
a type of the form $C$ or \code{$p$.$C$}
20341-
where $C$ is an identifier denoting a class or mixin,
20342-
and $p$ is an identifier denoting an import prefix,
20343-
optionally followed by \synt{typeArguments}.
20337+
and let \DefineSymbol{U} be a type of the form $F$ or \code{$p$.$F$}
20338+
in a scope where this term denotes $D$.
20339+
Assume that the transitive alias expansion of \code{$F$<\List{X}{1}{s}>} is
20340+
\BlindDefineSymbol{C, q}%
20341+
a type of the form $C$ or \code{$q$.$C$},
20342+
optionally followed by \synt{typeArguments},
20343+
where $q$ is an identifier denoting an import prefix,
20344+
and $C$ respectively \code{$q$.$C$} denotes a class or mixin
20345+
(\commentary{in particular, $C$ can not be a type variable}).
2034420346
Assume that $U$ occurs in an expression $e$ of the form
2034520347
`\code{$U$.\id\;\metavar{args}}'
2034620348
where \metavar{args} is derived from \syntax{<argumentPart>?},
2034720349
such that \id{} is the name of
20348-
a static member of $C$ respectively \code{$p$.$C$}.
20350+
a static member of $C$ respectively \code{$q$.$C$}.
2034920351
The expression $e$ is then treated as
2035020352
`\code{$C$.\id\;\metavar{args}}'
2035120353
respectively
20352-
`\code{$p$.$C$.\id\;\metavar{args}}'.
20354+
`\code{$q$.$C$.\id\;\metavar{args}}'.
2035320355

2035420356
\commentary{%
2035520357
This means that it is possible to use a type alias

0 commit comments

Comments
 (0)