summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2008-04-08 10:54:54 +0000
committerMartin Odersky <odersky@gmail.com>2008-04-08 10:54:54 +0000
commitb26701964007ab9126a136d52a40615842a36422 (patch)
tree9fe3299a043aac66e9ffb8db238fd5b3d7caef24
parent3884f6e1ce4feff64e816e426d318f9cb10036a8 (diff)
downloadscala-b26701964007ab9126a136d52a40615842a36422.tar.gz
scala-b26701964007ab9126a136d52a40615842a36422.tar.bz2
scala-b26701964007ab9126a136d52a40615842a36422.zip
fixed t607, t699
-rw-r--r--src/compiler/scala/tools/nsc/symtab/Flags.scala3
-rw-r--r--src/compiler/scala/tools/nsc/symtab/Symbols.scala2
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala17
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala8
-rw-r--r--src/library/scala/Either.scala10
-rw-r--r--src/library/scala/Left.scala16
-rw-r--r--src/library/scala/Option.scala2
-rw-r--r--src/library/scala/Right.scala16
8 files changed, 28 insertions, 46 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/Flags.scala b/src/compiler/scala/tools/nsc/symtab/Flags.scala
index d747ecfef7..2c526f77a9 100644
--- a/src/compiler/scala/tools/nsc/symtab/Flags.scala
+++ b/src/compiler/scala/tools/nsc/symtab/Flags.scala
@@ -58,7 +58,8 @@ object Flags extends Enumeration {
final val PARAMACCESSOR = 0x20000000 // for value definitions: is an access method
// for a final val parameter
// for parameters: is a val parameter
- final val MODULEVAR = 0x40000000 // for term symbols: is the variable caching a module value
+ final val MODULEVAR = 0x40000000 // for variables: is the variable caching a module value
+ final val SYNTHETICMETH = 0x40000000 // for methods: synthetic method, but without SYNTHETIC flag
final val MONOMORPHIC = 0x40000000 // for type symbols: does not have type parameters
final val LAZY = 0x80000000L // symbol is a lazy val. can't have MUTABLE unless transformed by typer
diff --git a/src/compiler/scala/tools/nsc/symtab/Symbols.scala b/src/compiler/scala/tools/nsc/symtab/Symbols.scala
index 7a12dcee2f..8d6f1b0c40 100644
--- a/src/compiler/scala/tools/nsc/symtab/Symbols.scala
+++ b/src/compiler/scala/tools/nsc/symtab/Symbols.scala
@@ -11,6 +11,8 @@ import scala.tools.nsc.io.AbstractFile
import scala.tools.nsc.util.{Position, NoPosition, BatchSourceFile}
import Flags._
+//todo: get rid of MONOMORPHIC flag
+
trait Symbols {
self: SymbolTable =>
import definitions._
diff --git a/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala b/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala
index dcb1ff70d9..962f749591 100644
--- a/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala
@@ -54,7 +54,7 @@ trait SyntheticMethods { self: Analyzer =>
def hasOverridingImplementation(meth: Symbol): Boolean = if (inIDE) true else {
val sym = clazz.info.nonPrivateMember(meth.name)
sym.alternatives exists { sym =>
- sym != meth && !(sym hasFlag DEFERRED) && !(sym hasFlag SYNTHETIC) &&
+ sym != meth && !(sym hasFlag DEFERRED) && !(sym hasFlag (SYNTHETIC | SYNTHETICMETH)) &&
(clazz.thisType.memberType(sym) matches clazz.thisType.memberType(meth))
}
}
@@ -63,10 +63,9 @@ trait SyntheticMethods { self: Analyzer =>
newSyntheticMethod(name, flags | OVERRIDE, tpe)
def newSyntheticMethod(name: Name, flags: Int, tpe: Type) = {
- var method = clazz.newMethod(clazz.pos, name) setFlag ({
- if (inIDE) flags | SYNTHETIC
- else flags
- }) setInfo tpe
+ var method = clazz.newMethod(clazz.pos, name)
+ .setFlag(flags | (if (inIDE) SYNTHETIC else SYNTHETICMETH))
+ .setInfo(tpe)
method = clazz.info.decls.enter(method).asInstanceOf[TermSymbol]
method
}
@@ -78,18 +77,18 @@ trait SyntheticMethods { self: Analyzer =>
}
*/
def productPrefixMethod: Tree = {
- val method = syntheticMethod(nme.productPrefix, FINAL, PolyType(List(), StringClass.tpe))
+ val method = syntheticMethod(nme.productPrefix, 0, PolyType(List(), StringClass.tpe))
typer.typed(DefDef(method, vparamss => Literal(Constant(clazz.name.decode))))
}
def productArityMethod(nargs:Int ): Tree = {
- val method = syntheticMethod(nme.productArity, FINAL, PolyType(List(), IntClass.tpe))
+ val method = syntheticMethod(nme.productArity, 0, PolyType(List(), IntClass.tpe))
typer.typed(DefDef(method, vparamss => Literal(Constant(nargs))))
}
def productElementMethod(accs: List[Symbol]): Tree = {
//val retTpe = lub(accs map (_.tpe.resultType))
- val method = syntheticMethod(nme.productElement, FINAL, MethodType(List(IntClass.tpe), AnyClass.tpe/*retTpe*/))
+ val method = syntheticMethod(nme.productElement, 0, MethodType(List(IntClass.tpe), AnyClass.tpe/*retTpe*/))
typer.typed(DefDef(method, vparamss => Match(Ident(vparamss.head.head), {
(for ((sym,i) <- accs.zipWithIndex) yield {
CaseDef(Literal(Constant(i)),EmptyTree, Ident(sym))
@@ -106,7 +105,7 @@ trait SyntheticMethods { self: Analyzer =>
}
def tagMethod: Tree = {
- val method = syntheticMethod(nme.tag, FINAL, MethodType(List(), IntClass.tpe))
+ val method = syntheticMethod(nme.tag, 0, MethodType(List(), IntClass.tpe))
typer.typed(DefDef(method, vparamss => Literal(Constant(clazz.tag))))
}
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index 2cdbb3d57d..db35ab1681 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -972,9 +972,11 @@ trait Typers { self: Analyzer =>
} else {
error(parent.pos, psym+" needs to be a trait be mixed in")
}
- } else if (psym hasFlag FINAL) {
- error(parent.pos, "illegal inheritance from final class")
- } else if (psym.isSealed && !phase.erasedTypes) {
+ }
+ if (psym hasFlag FINAL) {
+ error(parent.pos, "illegal inheritance from final "+psym)
+ }
+ if (psym.isSealed && !phase.erasedTypes) {
if (context.unit.source.file != psym.sourceFile)
error(parent.pos, "illegal inheritance from sealed "+psym)
else
diff --git a/src/library/scala/Either.scala b/src/library/scala/Either.scala
index 474eafcb4b..b306e83b27 100644
--- a/src/library/scala/Either.scala
+++ b/src/library/scala/Either.scala
@@ -534,3 +534,13 @@ object Either {
def iif[A, B](cond: Boolean)(left: => A, right: => B) =
if(cond) Right(right) else Left(left)
}
+
+/**
+ * The left side of the disjoint union, as opposed to the <code>Right</code> side.
+ */
+final case class Left[+A, +B](a: A) extends Either[A, B]
+
+/**
+ * The right side of the disjoint union, as opposed to the <code>Left</code> side.
+ */
+final case class Right[+A, +B](b: B) extends Either[A, B]
diff --git a/src/library/scala/Left.scala b/src/library/scala/Left.scala
deleted file mode 100644
index 98873c72ad..0000000000
--- a/src/library/scala/Left.scala
+++ /dev/null
@@ -1,16 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2002-2008, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id$
-
-package scala
-
-/**
- * The left side of the disjoint union, as opposed to the <code>Right</code> side.
- */
-final case class Left[+A, +B](a: A) extends Either[A, B]
diff --git a/src/library/scala/Option.scala b/src/library/scala/Option.scala
index 3c669c1b9c..3477a1644d 100644
--- a/src/library/scala/Option.scala
+++ b/src/library/scala/Option.scala
@@ -117,7 +117,7 @@ sealed abstract class Option[+A] extends Product {
* <code>left</code> if this is empty, or a <code>Right</code> if this is nonempty with the
* options' value.
*/
- def toEither[X](left: => X) =
+ def toEither[X](left: => X): Either[X, A] =
if (isEmpty) Left(left) else Right(this.get)
}
diff --git a/src/library/scala/Right.scala b/src/library/scala/Right.scala
deleted file mode 100644
index d97c8c4b27..0000000000
--- a/src/library/scala/Right.scala
+++ /dev/null
@@ -1,16 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2002-2008, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id$
-
-package scala
-
-/**
- * The right side of the disjoint union, as opposed to the <code>Left</code> side.
- */
-final case class Right[+A, +B](b: B) extends Either[A, B]