diff options
-rw-r--r-- | doc/reference/ScalaReference.tex | 76 | ||||
-rw-r--r-- | sources/scalac/symtab/Symbol.java | 2 | ||||
-rw-r--r-- | sources/scalac/symtab/Type.java | 9 | ||||
-rw-r--r-- | sources/scalac/typechecker/RefCheck.java | 36 |
4 files changed, 69 insertions, 54 deletions
diff --git a/doc/reference/ScalaReference.tex b/doc/reference/ScalaReference.tex index f252db3c25..195922c454 100644 --- a/doc/reference/ScalaReference.tex +++ b/doc/reference/ScalaReference.tex @@ -3525,35 +3525,32 @@ abstract class Any { final def != (that: Any): boolean = !(this == that) /** Hash code */ - def hashCode: Int = $\ldots$ + def hashCode(): Int = $\ldots$ /** Textual representation */ def toString(): String = $\ldots$ /** Type test */ - def isInstanceOf[a]: Boolean = $\ldots$ + def isInstanceOf[a]: Boolean = match { + case x: a => true + case _ => false + } /** Type cast */ - def asInstanceOf[a]: a = - if (isInstanceOf[a]) $\ldots$ - else if (this eq null) this - else new ClassCastException().throw + def asInstanceOf[a]: a = match { + case x: a => x + case _ => if (this eq null) this + else else new ClassCastException().throw + } /** Pattern match */ - def match[a](cases: Any => a): a = cases(this); - - /** Representation as string */ - def toString(): String = $\ldots$ + def match[a, b](cases: a => b): b = cases(this); } -final class AnyVal extends Any -class AnyRef extends Any -class Object extends AnyRef +final class AnyVal extends Any; +class AnyRef extends Any; +class Object extends AnyRef; \end{lstlisting} -\section{Class String} - - - \section{Value Classes} \label{sec:cls-value} @@ -3563,15 +3560,15 @@ class \code{AnyVal}. Scala implementations need to provide the following value classes (but are free to provide others as well). \begin{lstlisting} -final class Unit extends AnyVal with { $\ldots$ } -final class Boolean extends AnyVal with { $\ldots$ } -final class Double extends AnyVal with { $\ldots$ } -final class Float extends Double with { $\ldots$ } -final class Long extends Float with { $\ldots$ } -final class Int extends Long with { $\ldots$ } -final class Char extends Int with { $\ldots$ } -final class Short extends Int with { $\ldots$ } -final class Byte extends Short with { $\ldots$ } +final class Unit extends AnyVal { $\ldots$ } +final class Boolean extends AnyVal { $\ldots$ } +final class Double extends AnyVal { $\ldots$ } +final class Float extends Double { $\ldots$ } +final class Long extends Float { $\ldots$ } +final class Int extends Long { $\ldots$ } +final class Char extends Int { $\ldots$ } +final class Short extends Int { $\ldots$ } +final class Byte extends Short { $\ldots$ } \end{lstlisting} These classes are defined in the following. @@ -3579,7 +3576,7 @@ These classes are defined in the following. \subsection{Class \prog{Double}} \begin{lstlisting} -final class Double extends AnyVal with Ord with { +final class Double extends AnyVal with Ord { def asDouble: Double // convert to Double def asFloat: Float // convert to Float def asLong: Long // convert to Long @@ -3594,8 +3591,11 @@ final class Double extends AnyVal with Ord with { def / (that: Double): Double // double division def % (that: Double): Double // double remainder - def == (that: Double): Boolean // double equality - def != (that: Double): Boolean // double inequality + def equals(that: Double): Boolean //double equality + def equals(that: Any) = that match { + case x: Double => equals(x) + case _ => false + } def < (that: Double): Boolean // double less def > (that: Double): Boolean // double greater def <= (that: Double): Boolean // double less or equals @@ -3604,7 +3604,7 @@ final class Double extends AnyVal with Ord with { def - : Double = 0.0 - this // double negation def + : Double = this } -\end{lstlisting} + \subsection{Class \prog{Float}} @@ -3619,10 +3619,12 @@ final class Float extends Double with { def asByte: Byte \>// convert to Byte def + (that: Double): Double = asDouble + that - def + (that: Float): Double \>// float addition + def + (that: Float): Double // float addition /* analogous for -, *, /, % */ - def == (that: Double): Boolean = asDouble == that + def equals(that: Double): Boolean = asDouble equals that + def equals(that: Float): Boolean = // float equality + def equals(that: Any): Boolean = super equals that def == (that: Float): Boolean \>// float equality /* analogous for !=, <, >, <=, >= */ @@ -3725,6 +3727,16 @@ case class True extends Boolean with { def ifThenElse(t)(e) = t } case class False extends Boolean with { def ifThenElse(t)(e) = e } \end{lstlisting} +\section{Class String} + +The class \verb@scala.String@ is usually derived from the standard +String class of the undrelying host system (and may be identified with +it). For Scala clients the class supports in each case a method +\begin{lstlisting} +def + (that: Any): String +\end{lstlisting} +which concatenates its left operand with the textual representation of its +right operand. \comment{ \section{Reflection} diff --git a/sources/scalac/symtab/Symbol.java b/sources/scalac/symtab/Symbol.java index bee27bf63a..c3da3e15d9 100644 --- a/sources/scalac/symtab/Symbol.java +++ b/sources/scalac/symtab/Symbol.java @@ -1079,7 +1079,7 @@ public class TermSymbol extends Symbol { public static TermSymbol newConstructor(Symbol clazz, int flags) { TermSymbol sym = new TermSymbol( - clazz.pos, Names.CONSTRUCTOR, clazz.owner(), flags | FINAL); + clazz.pos, Names.CONSTRUCTOR, clazz.owner(), flags); sym.clazz = clazz; return sym; } diff --git a/sources/scalac/symtab/Type.java b/sources/scalac/symtab/Type.java index 847b847baa..339c09b38a 100644 --- a/sources/scalac/symtab/Type.java +++ b/sources/scalac/symtab/Type.java @@ -1418,9 +1418,8 @@ public class Type implements Modifiers, Kinds, TypeTags, EntryTags { case TypeRef(Type pre1, Symbol sym1, Type[] args1): switch (this) { case TypeRef(Type pre, Symbol sym, Type[] args): - boolean samepre = pre.isSameAs(pre1); - if ((samepre && sym == sym1 /* fast case */ || - !samepre && pre.isSubType(pre1) && sym == pre.rebind(sym1)) && + if (pre.isSubType(pre1) && + (sym == sym1 || sym == pre.rebind(sym1)) && isSubArgs(args, args1, sym.typeParams()) || sym.kind == TYPE && pre.memberInfo(sym).isSubType(that)) @@ -1630,8 +1629,8 @@ public class Type implements Modifiers, Kinds, TypeTags, EntryTags { || (sym.kind == sym1.kind || sym1.kind == TYPE) && self.memberInfo(sym).subst(tparams, targs) - .isSubType(sym1.info().substThis(sym.owner(), self)) && - sym1.loBound().substThis(sym.owner(), self) + .isSubType(sym1.info().substThis(sym1.owner(), self)) && + sym1.loBound().substThis(sym1.owner(), self) .isSubType(self.memberLoBound(sym).subst(tparams, targs)) || (sym.kind == TYPE && sym1.kind == ALIAS && diff --git a/sources/scalac/typechecker/RefCheck.java b/sources/scalac/typechecker/RefCheck.java index e78d628631..460e98abeb 100644 --- a/sources/scalac/typechecker/RefCheck.java +++ b/sources/scalac/typechecker/RefCheck.java @@ -9,6 +9,7 @@ package scalac.typechecker; import java.util.HashMap; +import java.util.Iterator; import scalac.*; import scalac.util.*; import scalac.ast.*; @@ -62,6 +63,7 @@ public class RefCheck extends Transformer implements Modifiers, Kinds { */ void checkAllOverrides(int pos, Symbol clazz) { Type[] closure = clazz.closure(); + HashMap/*<Symbol,Symbol>*/ overrides = null; for (int i = 0; i < closure.length; i++) { for (Scope.SymbolIterator it = closure[i].members().iterator(); it.hasNext();) { @@ -77,23 +79,25 @@ public class RefCheck extends Transformer implements Modifiers, Kinds { member + member.locationString() + " is not defined" + (((member.flags & MUTABLE) == 0) ? "" : "\n(Note that variables need to be initialized to be defined)")); + } else if ((member.flags & OVERRIDE) != 0) { + if (overrides == null) + overrides = new HashMap(); + if ((other.flags & DEFERRED) == 0 || + overrides.get(member) == null) + overrides.put(member, other); } - if ((other.flags & OVERRIDE) != 0) { - Type[] clparents = closure[i].parents(); - Symbol sym1 = null; - for (int j = clparents.length - 1; sym1 == null && j > 0; j--) - sym1 = clparents[j].lookup(other.name); - if (sym1 == null) { - Symbol superclazz = clazz.info().parents()[0].symbol(); - if (superclazz.isSubClass(closure[i].symbol())) - superclazz = clparents[0].symbol(); - sym1 = superclazz.lookup(other.name); - } - if (sym1 != null && (sym1.flags & DEFERRED) != 0) - abstractClassError( - clazz, other + other.locationString() + - " is marked `override' and overrides an abstract member" + sym1.locationString()); - } + } + } + } + if (overrides != null) { + for (Iterator/*<Symbol>*/ it = overrides.keySet().iterator(); + it.hasNext();) { + Symbol member = (Symbol) it.next(); + Symbol other = (Symbol) overrides.get(member); + if ((other.flags & DEFERRED) != 0) { + abstractClassError( + clazz, member + member.locationString() + + " is marked `override' and overrides only abstract members"); } } } |