Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 68f77fa

Browse files
lrhncommit-bot@chromium.org
authored andcommitted
Specify that extending or implementing Function does nothing.
Change-Id: I0008f74c75da28fbf38a959e2925b72dd1dfd38f Reviewed-on: https://dart-review.googlesource.com/c/88563 Commit-Queue: Lasse R.H. Nielsen <[email protected]> Reviewed-by: Erik Ernst <[email protected]>
1 parent 0f1b943 commit 68f77fa

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

docs/language/dartLangSpec.tex

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
% - Specify that a getter/setter and a method with the same basename is
3333
% an error, also in the case where a class obtains both from its
3434
% superinterfaces.
35+
% - Specify the Dart 2.0 rule that you cannot implement, extend or mix-in
36+
% Function.
3537
%
3638
% 2.1
3739
% - Remove 64-bit constraint on integer literals compiled to JavaScript numbers.
@@ -8799,7 +8801,7 @@ \subsubsection{Getter Access and Method Extraction}
87998801
Let $T$ be the static type of $e$.
88008802
It is a compile-time error if $T$ does not have a method or getter named \id{}
88018803
unless $T$ is \DYNAMIC{},
8802-
or $T$ is \FUNCTION{} and \id{} is \code{call}.
8804+
or $T$ is \FUNCTION{} and \id{} is \CALL{}.
88038805
The static type of $i$ is:
88048806

88058807
\begin{itemize}
@@ -13722,13 +13724,46 @@ \subsection{Function Types}
1372213724
}
1372313725

1372413726
\LMHash{}%
13725-
A function object is always an instance of some class that implements the class \FUNCTION{}.
13727+
A function object is always an instance of some class that implements the class \FUNCTION{} (\ref{functionType}).
1372613728
\commentary{%
1372713729
Consequently, all function types are subtypes of \FUNCTION{}
1372813730
(\ref{subtypes}).
1372913731
}
1373013732

1373113733

13734+
\subsection{Type \FUNCTION{}}
13735+
\LMLabel{functionType}
13736+
13737+
\LMHash{}%
13738+
The built-in class \FUNCTION{} is a supertype of all function types
13739+
(\ref{functionTypes}).
13740+
It is impossible to extend, implement, or mix in the class \FUNCTION{}.
13741+
13742+
\LMHash{}%
13743+
If a class declaration or mixin application has \FUNCTION{} as super-class,
13744+
it instead uses \OBJECT{} as super-class.
13745+
13746+
\LMHash{}%
13747+
If a class or mixin declaration implements \FUNCTION{}, it has no effect.
13748+
It is as if the \FUNCTION was removed from the \code{implements} clause (and if it's the only implemented interface, the entire clause is removed).
13749+
The resulting class or mixin interface does not have \FUNCTION{} as a super-interface.
13750+
13751+
\LMHash{}%
13752+
If a mixin application mixes \FUNCTION{} onto a super-class, it follows the
13753+
normal rules for mixin-application, but since the result of that mixin
13754+
application is equivalent to a class with \code{implements Function}, and
13755+
that clause has no effect, the resulting class also does not
13756+
implement \FUNCTION{}. \commentary{The \FUNCTION{} class declares no
13757+
concrete instance members, so the mixin application creates a sub-class
13758+
of the superclass with no new members and no new interfaces.}
13759+
13760+
\rationale{Since using \FUNCTION{} in these ways has no effect, it would be
13761+
reasonable to disallow it completely, like we do extending, implementing or
13762+
mixing in types like \code{int} or \code{String}.
13763+
For backwards compatibility with Dart 1 programs, the syntax is allowed to remain,
13764+
even if it has no effect. Tools may choose to warning users that their code
13765+
has no effect.}
13766+
1373213767
\subsection{Type \DYNAMIC{}}
1373313768
\LMLabel{typeDynamic}
1373413769

@@ -13826,7 +13861,7 @@ \subsection{Type \DYNAMIC{}}
1382613861
function expression invocation where an entity of static type \code{Type} is
1382713862
invoked. Note that it could actually succeed: An overriding implementation
1382813863
of \code{runtimeType} could return an instance whose dynamic type is a subtype
13829-
of \code{Type} that has a \code{call} method.
13864+
of \code{Type} that has a \CALL{} method.
1383013865
We decided to make it an error because it is likely to be a mistake,
1383113866
especially in cases like \code{$d$.hashCode()}
1383213867
where a developer might have forgotten that \code{hashCode} is a getter.

0 commit comments

Comments
 (0)