Change static typing so that inherited noSuchMethod silences errors,

including undefined abstract members.

R=justinfagnani@google.com

Review URL: https://codereview.chromium.org//818463002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@42521 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
gbracha@google.com 2014-12-19 18:44:39 +00:00
parent 72ff873c0b
commit 38606de2a5

View file

@ -1106,7 +1106,11 @@ The purpose of an abstract method is to provide a declaration for purposes such
%always results in a run-time error. This must be \code{NoSuchMethodError} or an instance of a subclass of \code{NoSuchMethodError}, such as \code{AbstractMethodError}.
\LMHash{}
It is a static warning if an abstract member is declared or inherited in a concrete class unless that member overrides a concrete one.
It is a static warning if an abstract member $m$ is declared or inherited in a concrete class $C$ unless:
\begin{itemize}
\item $m$ overrides a concrete member, or
\item $C$ has a \cd{noSuchMethod()} method distinct from the one declared in class \cd{Object}.
\end{itemize}
\rationale {
We wish to warn if one declares a concrete class with abstract members. However, code like the following should work without warnings:
@ -1813,7 +1817,7 @@ If two members override each other, it is a static warning if the overriding mem
\item If possible the interface gets a member named $m$ that has the minimum number of required parameters among all the members in the superinterfaces, the maximal number of positionals, and the superset of named parameters. The types of these are all \DYNAMIC{}. If this is impossible then no member $m$ appears in the interface.
\end{itemize} (\ref{interfaceInheritanceAndOverriding})
\item Rule \ref{typeSigAssignable} applies to interfaces as well as classes (\ref{interfaceInheritanceAndOverriding}).
\item It is a static warning if a concrete class does not have an implementation for a method in any of its superinterfaces unless it declares its own \cd{noSuchMethod} method (\ref{superinterfaces}).
\item It is a static warning if a concrete class does not have an implementation for a method in any of its superinterfaces unless it has a \cd{noSuchMethod} method (\ref{superinterfaces}).
\item The identifier of a named constructor cannot be the same as the name of a member declared (as opposed to inherited) in the same class (\ref{constructors}).
\end{enumerate}
}
@ -1847,7 +1851,7 @@ One might argue that it is harmless to repeat a type in the superinterface list,
It is a compile-time error if the interface of a class $C$ is a superinterface of itself.
\LMHash{}
Let $C$ be a concrete class that does not declare its own \code{noSuchMethod()} method.
Let $C$ be a concrete class that does not have a \code{noSuchMethod()} method distinct from the one declared in class \cd{Object}.
It is a static warning if the implicit interface of $C$ includes an instance member $m$ of type $F$ and $C$ does not declare or inherit a corresponding non-abstract instance member $m$ of type $F'$ such that $F' <: F$.
\commentary{A class does not inherit members from its superinterfaces. However, its implicit interface does.
@ -1856,14 +1860,9 @@ It is a static warning if the implicit interface of $C$ includes an instance me
\rationale {
We choose to issue these warnings only for concrete classes; an abstract class might legitimately be designed with the expectation that concrete subclasses will implement part of the interface.
We also disable these warnings if a \code{noSuchMethod()} declaration is present. In such cases, the supported interface is going to be implemented via \code{noSuchMethod()} and no actual declarations of the implemented interface's members are needed. This allows proxy classes for specific types to be implemented without provoking type warnings.
In addition, it may be useful to suppress these warnings if \code{noSuchMethod} is inherited, However, this may suppress meaningful warnings and so we choose not to do so. If one does want to suppress the warnings in a subclass, one can define a simple implementation of \code{noSuchMethod} in the subclass:
We also disable these warnings if a \code{noSuchMethod()} declaration is present or inherited from any class other than \cd{Object}. In such cases, the supported interface is going to be implemented via \code{noSuchMethod()} and no actual declarations of the implemented interface's members are needed. This allows proxy classes for specific types to be implemented without provoking type warnings.
}
\begin{dartCode}
noSuchMethod(inv) =$>$ \SUPER.noSuchMethod(inv);
\end{dartCode}
\LMHash{}
It is a static warning if the implicit interface of a class $C$ includes an instance member $m$ of type $F$ and $C$ declares or inherits a corresponding instance member $m$ of type $F'$ if $F'$ is not a subtype of $F$.
@ -6827,7 +6826,7 @@ A function type $T$ may be assigned to a function type $S$, written $T \Longlef
\LMHash{}
% ensure that Object and dynamic may be assign dot a function type
A function is always an instance of some class that implements the class \code{Function} and implements a \CALL{} method with the same signature as the function. All function types are subtypes of \code{Function}.
If a type $I$ includes an instance method named \CALL{}, and the type of \CALL{} is the function type $F$, then $I$ is considered to be more specific than $F$. It is a static warning if a concrete class implements \cd{Function} and does not have a concrete method named \CALL{} unless that class declares its own implementation of \cd{noSuchMethod()}.
If a type $I$ includes an instance method named \CALL{}, and the type of \CALL{} is the function type $F$, then $I$ is considered to be more specific than $F$. It is a static warning if a concrete class implements \cd{Function} and does not have a concrete method named \CALL{} unless that class has an implementation of \cd{noSuchMethod()} distinct from the one declared in class \cd{Object}.