Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce rules to say that missing formal parameter type means dynamic #2163

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
105 changes: 62 additions & 43 deletions specification/dartLangSpec.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1564,12 +1564,16 @@ \section{Functions}

\LMHash{}%
Functions can be introduced by function declarations
(\ref{functionDeclarations}),
(\ref{functionDeclarations}).
\commentary{%
This includes
method declarations (\ref{instanceMethods}, \ref{staticMethods}),
getter declarations (\ref{getters}),
setter declarations (\ref{setters}),
and constructor declarations (\ref{constructors});
and they can be introduced by function literals (\ref{functionExpressions}).
and constructor declarations (\ref{constructors}).%
}
Moreover, functions can be introduced by function literals
(\ref{functionExpressions}).

\LMHash{}%
A function is \IndexCustom{asynchronous}{function!asynchronous}
Expand Down Expand Up @@ -1759,45 +1763,26 @@ \subsection{Function Declarations}
\LMLabel{functionDeclarations}

\LMHash{}%
A \Index{function declaration} is a function that
is neither a member of a class nor a function literal.
Function declarations include exactly the following:
\IndexCustom{library functions}{function!library},
which are function declarations
%(including getters and setters)
at the top level of a library, and
\IndexCustom{local functions}{function!local},
which are function declarations declared inside other functions.
Library functions are often referred to simply as top-level functions.
A \Index{function declaration} is a library declaration derived from

\LMHash{}%
A function declaration consists of an identifier indicating the function's name,
possibly prefaced by a return type.
The function name is followed by a signature and body.
For getters, the signature is empty.
The body is empty for functions that are external.

\LMHash{}%
The scope of a library function is the scope of the enclosing library.
The scope of a local function is described
in section~\ref{localFunctionDeclaration}.
In both cases, the name of the function is in scope
in its formal parameter scope
(\ref{formalParameters}).
\noindent
\syntax{%
(<getterSignature> | <setterSignature> | <functionSignature>) %
<functionBody>},

\LMHash{}%
It is a compile-time error to preface a function declaration
with the built-in identifier \STATIC.
\noindent
a \synt{localFunctionDeclaration},
or a class member declaration or a constructor declaration derived from
\syntax{<methodSignature> <functionBody>}.
Moreover, function declarations include
\EXTERNAL{} declarations corresponding to the above forms.

\LMHash{}%
When we say that a function $f_1$ \Index{forwards} to another function $f_2$,
we mean that invoking $f_1$ causes $f_2$ to be executed
with the same arguments and/or receiver as $f_1$,
and returns the result of executing $f_2$ to the caller of $f_1$,
unless $f_2$ throws an exception,
in which case $f_1$ throws the same exception.
Furthermore, we only use the term for
synthetic functions introduced by the specification.
A function declaration consists of an identifier indicating the function's name,
possibly prefaced by a return type and/or some modifiers.
The function name is followed by a formal parameter part and a body,
except that getters omit the formal parameter part,
and external functions omit the body.


\subsection{Formal Parameters}
Expand Down Expand Up @@ -1868,7 +1853,25 @@ \subsection{Formal Parameters}
The formal parameter scope of a generic function $f$ is enclosed in
the type parameter scope of $f$.
Every formal parameter introduces a local variable into
the formal parameter scope.
the formal parameter scope,
with the declared type which is the declared type of the formal parameter.
If no type annotation is given for the formal parameter,
the declared type is considered to be the type \DYNAMIC.

\commentary{%
Type inference is not yet specified in this document,
and is assumed to have taken place already
(\ref{overview}).
In particular, some or all formal parameters of an instance method declaration
may have received a declared type based on override inference,
in which case it is not considered to be omitted.
%% TODO(eernst): Change to \ref{} when inference spec is added.
Briefly, override inference yields a type computed from the declared types of
the corresponding parameter of member signatures in superinterfaces,
or it causes a compile-time error if said types can not be reconciled.%
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you also want to mention inference from initializing formals here too since you include constructors under this umbrella now?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thanks!

}

\LMHash{}%
The current scope for the function's signature is
the scope that encloses the formal parameter scope.

Expand All @@ -1888,7 +1891,7 @@ \subsection{Formal Parameters}

\LMHash{}%
It is a compile-time error if a formal parameter
is declared as a constant variable (\ref{variables}).
has the modifier \CONST.

\begin{grammar}
<formalParameterList> ::= `(' `)'
Expand Down Expand Up @@ -2195,7 +2198,8 @@ \subsection{Type of a Function}

\LMHash{}%
This section specifies the static type which is ascribed to
the function denoted by a function declaration,
the function denoted by a function declaration
(\ref{functionDeclarations}),
and the dynamic type of the corresponding function object.

\LMHash{}%
Expand Down Expand Up @@ -2242,6 +2246,7 @@ \subsection{Type of a Function}
A function declaration may declare formal type parameters.
The type of the function includes the names of the type parameters
and for each type parameter the upper bound,
%% TODO(eernst): With null safety, use `Object?`.
which is considered to be the built-in class \code{Object}
if no bound is specified.
When consistent renaming of type parameters
Expand All @@ -2258,9 +2263,23 @@ \subsection{Type of a Function}
}

\LMHash{}%
In the following three paragraphs,
if the number \DefineSymbol{s} of formal type parameters is zero then
If the number of formal type parameters is zero then
the type parameter list in the function type is omitted.
If the declared type of a formal parameter is omitted,
it is considered to be the type \DYNAMIC.

\commentary{%
Type inference is not yet specified in this document,
and is assumed to have taken place already
(\ref{overview}).
In particular, some or all formal parameters of an instance method declaration
may have received a declared type based on override inference,
in which case it is not considered to be omitted.
%% TODO(eernst): Change to \ref{} when inference spec is added.
Briefly, override inference yields a type computed from the declared types of
the corresponding parameter of member signatures in superinterfaces,
or it causes a compile-time error if said types can not be reconciled.%
}

\LMHash{}%
Let $F$ be a function with
Expand Down