diff options
author | Martin Odersky <odersky@gmail.com> | 2003-03-31 08:29:52 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2003-03-31 08:29:52 +0000 |
commit | efd06d74f1621351c70456478b07a4ace6a9a211 (patch) | |
tree | 01ac7505ed4f33582974d4519dc3e33d601614d2 | |
parent | 85c73ba918913361f925c23469c012096a93fb54 (diff) | |
download | scala-efd06d74f1621351c70456478b07a4ace6a9a211.tar.gz scala-efd06d74f1621351c70456478b07a4ace6a9a211.tar.bz2 scala-efd06d74f1621351c70456478b07a4ace6a9a211.zip |
*** empty log message ***
151 files changed, 809 insertions, 510 deletions
diff --git a/doc/reference/examples.verb.tex b/doc/reference/examples.verb.tex index bca84dfb2e..ca87d53740 100644 --- a/doc/reference/examples.verb.tex +++ b/doc/reference/examples.verb.tex @@ -1457,6 +1457,59 @@ the implementer of a class. Often, a field in one version of a class becomes a computed value in the next version. Uniform access ensures that clients do not have to be rewritten because of that change. +\pararagraph{Abstract Classes} + +Consider the task of writing a class for sets of integer numbers with +operations as follows. + +\begin{verbatim} +abstract class IntSet { + def incl(x: int): IntSet; + def contains(x: int): boolean; +} +\end{verbatim} +\verb@IntSet@ is labelled as an \emph{abstract class}. This has two consequences. +First, absract classes may have abstract members which are declared +but which do not have an implementation. In our case, both \verb@incl@ +and \verb@contains@ are such members. Second, if a class has +unimplemented members, no objects of that class may be created using +\verb@new@. + +\paragraph{Subclasses} + +Let's say, we plan to implement sets as binary trees. There are two +possible forms of trees. A tree for the empty set, and a tree +consisting of an integer and two subtrees. Here are their implementations. + + \begin{verbatim} +class Empty extends IntSet { + def contains(x: int): boolean = false; + def incl(x: int): IntSet = new NonEmpty(x, Empty, Empty); +} +\end{verbatim} +\es\bs +\begin{verbatim} +class NonEmpty(elem:int, left:IntSet, right:IntSet) extends IntSet { + def contains(x: int): boolean = + if (x < elem) left contains x + else if (x > elem) right contains x + else true; + def incl(x: int): IntSet = + if (x < elem) new NonEmpty(elem, left incl x, right) + else if (x > elem) new NonEmpty(elem, left, right incl x) + else this; +} +\end{verbatim} +\redtext{Notes:} +\bi +\item Both \verb@Empty@ and \verb@NonEmpty@ \redtext{extend} class \verb@IntSet@. +\item This means that +\bi +\item +The types \verb@Empty@ and \verb@NonEmpty@ \redtext{conform} to type \verb@IntSet@. + + + \paragraph{Abstract Methods.} Classes can also omit some of the definitions of their members. As an example, consider the following class \verb@Ord@ which provides the diff --git a/sources/examples/auction.scala b/sources/examples/auction.scala index e553752342..102892b4c6 100644 --- a/sources/examples/auction.scala +++ b/sources/examples/auction.scala @@ -11,18 +11,17 @@ case class trait AuctionReply; case class Status(asked: Int, expiration: Date), // asked sum, expiration date - BestOffer(), // yours is the best offer + BestOffer, // yours is the best offer BeatenOffer(maxBid: Int), // offer beaten by maxBid AuctionConcluded(seller: Actor, client: Actor), // auction concluded - AuctionFailed(), // failed with no bids - AuctionOver() extends AuctionReply; // bidding is closed + AuctionFailed, // failed with no bids + AuctionOver extends AuctionReply; // bidding is closed -class Auction(seller: Actor, minBid: Int, closing: Date) extends Actor() { +class Auction(seller: Actor, minBid: Int, closing: Date) extends Actor { val timeToShutdown = 36000000; // msec val bidIncrement = 10; - override def run() = execute; - def execute = { + override def run() = { var maxBid = minBid - bidIncrement; var maxBidder: Actor = _; var running = true; @@ -33,7 +32,7 @@ class Auction(seller: Actor, minBid: Int, closing: Date) extends Actor() { if (maxBid >= minBid) maxBidder send BeatenOffer(bid); maxBid = bid; maxBidder = client; - client send BestOffer(); + client send BestOffer; } else { client send BeatenOffer(maxBid); } @@ -41,17 +40,17 @@ class Auction(seller: Actor, minBid: Int, closing: Date) extends Actor() { case Inquire(client) => client send Status(maxBid, closing); - case TIMEOUT() => + case TIMEOUT => if (maxBid >= minBid) { val reply = AuctionConcluded(seller, maxBidder); maxBidder send reply; seller send reply; } else { - seller send AuctionFailed(); + seller send AuctionFailed; } receiveWithin(timeToShutdown) { - case Offer(_, client) => client send AuctionOver() - case TIMEOUT() => running = false; + case Offer(_, client) => client send AuctionOver + case TIMEOUT => running = false; } } } diff --git a/sources/scala/$colon$colon.scala b/sources/scala/$colon$colon.scala index 61afd1313b..cb1bf098cc 100644 --- a/sources/scala/$colon$colon.scala +++ b/sources/scala/$colon$colon.scala @@ -7,6 +7,5 @@ package scala { def isEmpty = false; def head = hd; def tail = tl; - override def toString(): String = mkString("[", ",", "]"); } } diff --git a/sources/scala/Interpreter.scala b/sources/scala/Interpreter.scala index a6b3f4a4c3..c904c77c33 100644 --- a/sources/scala/Interpreter.scala +++ b/sources/scala/Interpreter.scala @@ -10,7 +10,7 @@ package scala; -module Interpreter { +object Interpreter { def initialize: Boolean = true; diff --git a/sources/scala/Iterator.scala b/sources/scala/Iterator.scala index 57a97ac441..25a1c81308 100644 --- a/sources/scala/Iterator.scala +++ b/sources/scala/Iterator.scala @@ -68,7 +68,7 @@ trait Iterator[a] { } } -module Iterator { +object Iterator { def empty[a] = new Iterator[a] { def hasNext = false; diff --git a/sources/scala/List.scala b/sources/scala/List.scala index 2d6464955c..a079ce4fcc 100644 --- a/sources/scala/List.scala +++ b/sources/scala/List.scala @@ -275,6 +275,8 @@ trait List[a] extends Seq[a] { else if (tail.isEmpty) head.toString() + end else head.toString().concat(sep).concat(tail.mkString("", sep, end))); + override def toString() = mkString("[", ",", "]"); + /** Return a list formed from this list and the specified list * <code>that</code> by associating each element of the former with * the element at the same position in the latter. @@ -343,7 +345,7 @@ trait List[a] extends Seq[a] { } } -module List { +object List { def range(from: Int, end: Int): List[Int] = if (from >= end) scala.Predef.List() diff --git a/sources/scala/Nil.scala b/sources/scala/Nil.scala index 82460f5de3..09f9bf0bc8 100644 --- a/sources/scala/Nil.scala +++ b/sources/scala/Nil.scala @@ -7,7 +7,6 @@ package scala { def isEmpty = true; def head: c = error("head of empty list"); def tail: List[c] = error("tail of empty list"); - override def toString(): String = "[]"; } } diff --git a/sources/scala/Predef.scala b/sources/scala/Predef.scala index 62561fab89..ee28828191 100644 --- a/sources/scala/Predef.scala +++ b/sources/scala/Predef.scala @@ -1,6 +1,6 @@ package scala; -module Predef { +object Predef { type byte = scala.Byte; type short = scala.Short; diff --git a/sources/scala/Stream.scala b/sources/scala/Stream.scala index 701499a487..984f3f362e 100644 --- a/sources/scala/Stream.scala +++ b/sources/scala/Stream.scala @@ -116,7 +116,7 @@ trait Stream[a] { } } -module Stream { +object Stream { def empty[c]: Stream[c] = new Stream[c] { def isEmpty = true; diff --git a/sources/scala/concurrent/Actor.scala b/sources/scala/concurrent/Actor.scala index f6a1447f0e..9c1c5c2a57 100644 --- a/sources/scala/concurrent/Actor.scala +++ b/sources/scala/concurrent/Actor.scala @@ -1,10 +1,10 @@ package scala.concurrent; -abstract class Actor() extends Thread() { +abstract class Actor extends Thread { type Message = AnyRef; - private val mb = new MailBox(); + private val mb = new MailBox; def send(msg: Message): Unit = mb.send(msg); @@ -12,4 +12,9 @@ abstract class Actor() extends Thread() { mb.receive(f); def receiveWithin[a](msec: Long)(f: PartialFunction[Message, a]): a = mb.receiveWithin(msec)(f); -}
\ No newline at end of file +} + + + + + diff --git a/sources/scala/concurrent/Channel.scala b/sources/scala/concurrent/Channel.scala index b58cf15862..fee66786ab 100644 --- a/sources/scala/concurrent/Channel.scala +++ b/sources/scala/concurrent/Channel.scala @@ -1,12 +1,12 @@ package scala.concurrent; -class Channel[a]() extends Monitor() { - private var written: LinkedList[a] = new LinkedList(); +class Channel[a] extends Monitor { + private var written: LinkedList[a] = new LinkedList; private var lastWritten = written; private var nreaders = 0; def write(x: a) = synchronized { - lastWritten.next = new LinkedList(); + lastWritten.next = new LinkedList; lastWritten = lastWritten.next; if (nreaders > 0) notify(); } diff --git a/sources/scala/concurrent/Lock.scala b/sources/scala/concurrent/Lock.scala index 9581151ea7..48431ff110 100644 --- a/sources/scala/concurrent/Lock.scala +++ b/sources/scala/concurrent/Lock.scala @@ -1,6 +1,6 @@ package scala.concurrent; -class Lock() extends Monitor() { +class Lock extends Monitor { var available = true; def acquire = { if (!available) wait(); diff --git a/sources/scala/concurrent/MailBox.scala b/sources/scala/concurrent/MailBox.scala index 62a102781e..576d203d89 100644 --- a/sources/scala/concurrent/MailBox.scala +++ b/sources/scala/concurrent/MailBox.scala @@ -1,10 +1,10 @@ package scala.concurrent; -class MailBox() extends Monitor() { +class MailBox extends Monitor { type Message = AnyRef; - private abstract class Receiver() extends Monitor() { + private abstract class Receiver extends Monitor { type t; val receiver: PartialFunction[Message, t]; var msg: Message = _; @@ -18,9 +18,9 @@ class MailBox() extends Monitor() { } } - private val sent = new LinkedList[Message](); + private val sent = new LinkedList[Message]; private var lastSent = sent; - private var receivers = new LinkedList[Receiver](); + private var receivers = new LinkedList[Receiver]; private var lastReceiver = receivers; def send(msg: Message): Unit = synchronized { @@ -48,13 +48,13 @@ class MailBox() extends Monitor() { } def receive[a](f: PartialFunction[Message, a]): a = { - val r = new Receiver() { type t = a; val receiver = f } + val r = new Receiver { type t = a; val receiver = f } scanSentMsgs(r); r.receive() } def receiveWithin[a](msec: Long)(f: PartialFunction[Message, a]): a = { - val r = new Receiver() { type t = a; val receiver = f } + val r = new Receiver { type t = a; val receiver = f } scanSentMsgs(r); r.receiveWithin(msec) } diff --git a/sources/scala/concurrent/SyncChannel.scala b/sources/scala/concurrent/SyncChannel.scala index 7184ff7c61..7f0680487d 100644 --- a/sources/scala/concurrent/SyncChannel.scala +++ b/sources/scala/concurrent/SyncChannel.scala @@ -1,6 +1,6 @@ package scala.concurrent; -class SyncChannel[a]() extends Monitor() { +class SyncChannel[a] extends Monitor { private var data: a = _; private var reading = false; private var writing = false; diff --git a/sources/scala/concurrent/SyncVar.scala b/sources/scala/concurrent/SyncVar.scala index 4bb550be30..4c1c6864bd 100644 --- a/sources/scala/concurrent/SyncVar.scala +++ b/sources/scala/concurrent/SyncVar.scala @@ -1,6 +1,6 @@ package scala.concurrent; -class SyncVar[a]() extends Monitor() { +class SyncVar[a] extends Monitor { private var isDefined: Boolean = false; private var value: a = _; def get = synchronized { diff --git a/sources/scala/concurrent/TIMEOUT.scala b/sources/scala/concurrent/TIMEOUT.scala index 5c26cf8611..189ae0632f 100644 --- a/sources/scala/concurrent/TIMEOUT.scala +++ b/sources/scala/concurrent/TIMEOUT.scala @@ -1,3 +1,3 @@ package scala.concurrent; -case class TIMEOUT(); +case class TIMEOUT; diff --git a/sources/scala/concurrent/ops.scala b/sources/scala/concurrent/ops.scala index 8b52975ef1..f0bc73f953 100644 --- a/sources/scala/concurrent/ops.scala +++ b/sources/scala/concurrent/ops.scala @@ -3,18 +3,18 @@ package scala.concurrent; module ops { def spawn(def p: Unit) = { - val t = new Thread() { override def run() = p; } + val t = new Thread { override def run() = p; } t.run() } def future[a](def p: a): () => a = { - val result = new SyncVar[a](); + val result = new SyncVar[a]; spawn { result set p } () => result.get } def par[a, b](def xp: a, def yp: b): Pair[a, b] = { - val y = new SyncVar[b](); + val y = new SyncVar[b]; spawn { y set yp } Pair(xp, y.get) } diff --git a/sources/scalac/ast/Tree.java b/sources/scalac/ast/Tree.java index 0c28016253..a3cc94cf3e 100644 --- a/sources/scalac/ast/Tree.java +++ b/sources/scalac/ast/Tree.java @@ -146,7 +146,7 @@ public class Tree { /** * Import declaration * - introduced by: parser - * - eliminated by: !!! ? + * - eliminated by: analyzer */ public case Import(Tree expr, Name[] selectors) { if (!expr.isTerm()) @@ -204,8 +204,8 @@ public class Tree { /** * Tuple of expressions (comma separated expressions) - * - introduced by: !!! ? - * - eliminated by: !!! ? + * - introduced by: uncurry + * - eliminated by: lambdalift */ public case Tuple(Tree[] trees) { if (trees != null) { @@ -219,14 +219,14 @@ public class Tree { /** * Visitor (a sequence of cases) * - introduced by: parser - * - eliminated by: !!! ? + * - eliminated by: transmatch */ public case Visitor(CaseDef[] cases); /** * Anonymous function * - introduced by: parser - * - eliminated by: !!! ? + * - eliminated by: analyzer */ public case Function(ValDef[] vparams, Tree body) { @@ -237,7 +237,7 @@ public class Tree { /** * Assignment * - introduced by: parser - * - eliminated by: !!! ? + * - eliminated by: - */ public case Assign(Tree lhs, Tree rhs) { @@ -283,7 +283,7 @@ public class Tree { /** * Type application * - introduced by: parser - * - eliminated by: !!! ? + * - eliminated by: erasure */ public case TypeApply(Tree fun, Tree[] args) { @@ -422,7 +422,7 @@ public class Tree { /** * Applied type * - introduced by: parser - * - eliminated by: Analyzer + * - eliminated by: analyzer */ public case AppliedType(Tree tpe, Tree[] args) { assert tpe.isType() : this; @@ -492,6 +492,17 @@ public class Tree { } } + /** Returns true if this tree is empty or error. */ + public boolean isMissing() { + switch(this) { + case Bad(): + case Empty: + return true; + default: + return false; + } + } + //######################################################################## // Public Methods - tree type diff --git a/sources/scalac/ast/TreeGen.java b/sources/scalac/ast/TreeGen.java index 0c9c47eb88..ecb4705de5 100644 --- a/sources/scalac/ast/TreeGen.java +++ b/sources/scalac/ast/TreeGen.java @@ -165,13 +165,7 @@ public class TreeGen implements Kinds, Modifiers { Tree ref = mkRef(pos, pre, sym.constructor()); Tree constr = (args.length == 0) ? ref : TypeApply(ref, mkTypes(sym.pos, args)); - switch (parentType) { - case MethodType(Symbol[] params, Type restpe): - assert params.length == 0 : parentType; - return Apply(constr, Tree.EMPTY_ARRAY); - default: - return constr; - } + return Apply(constr, Tree.EMPTY_ARRAY); default: throw global.fail("invalid parent type", parentType); } @@ -357,9 +351,17 @@ public class TreeGen implements Kinds, Modifiers { return TypeApply(fn.pos, fn, args); } + public Tree If(int pos, Tree cond, Tree thenpart, Tree elsepart) { + return + make.If(pos, cond, thenpart, elsepart).setType(thenpart.type); + } + + public Tree If(Tree cond, Tree thenpart, Tree elsepart) { + return If(cond.pos, cond, thenpart, elsepart); + } + /** Build and applied type node with given function * and argument trees. - */ public Tree AppliedType(int pos, Tree fn, Tree[] args) { return make.AppliedType(pos, fn, args) .setType(Type.appliedType(fn.type, Tree.typeOf(args))); @@ -368,6 +370,7 @@ public class TreeGen implements Kinds, Modifiers { public Tree AppliedType(Tree fn, Tree[] args) { return AppliedType(fn.pos, fn, args); } + */ /** Build and attribute select node of given symbol. * It is assumed that the prefix is not empty. diff --git a/sources/scalac/ast/TreeInfo.java b/sources/scalac/ast/TreeInfo.java index d07627724f..17ca034316 100644 --- a/sources/scalac/ast/TreeInfo.java +++ b/sources/scalac/ast/TreeInfo.java @@ -115,6 +115,8 @@ public class TreeInfo { tree.symbol() != null && tree.symbol().isPrimaryConstructor(); case TypeApply(Tree constr, _): return isPureConstr(constr); + case Apply(Tree fn, Tree[] args): + return args.length == 0 && isPureConstr(fn); default: return false; } diff --git a/sources/scalac/ast/parser/Parser.java b/sources/scalac/ast/parser/Parser.java index f525398b3c..771979fcda 100644 --- a/sources/scalac/ast/parser/Parser.java +++ b/sources/scalac/ast/parser/Parser.java @@ -124,7 +124,7 @@ public class Parser implements Tokens { boolean isDefIntro() { switch (s.token) { case VAL: case VAR: case DEF: case CONSTR: case TYPE: - case MODULE: case CLASS: case CASECLASS: case TRAIT: + case OBJECT: case CASEOBJECT: case CLASS: case CASECLASS: case TRAIT: return true; default: return false; @@ -193,6 +193,15 @@ public class Parser implements Tokens { return make.Select(pos, make.Ident(pos, Names.scala), name); } + Tree scalaBooleanDot(int pos, Name name) { + return make.Select(pos, scalaDot(pos, Names.Boolean), name); + } + + Tree scalaObjectConstr(int pos) { + return make.Apply( + pos, scalaDot(pos, Names.Object.toConstrName()), Tree.EMPTY_ARRAY); + } + /** Create tree for for-comprehension <for (enums) do body> or * <for (enums) yield body> where mapName and flatmapName are chosen * corresponding to whether this is a for-do or a for-yield. @@ -310,6 +319,17 @@ public class Parser implements Tokens { } } + /** Complete unapplied constructor with `()' arguments + */ + Tree applyConstr(Tree t) { + switch (t) { + case Apply(_, _): + return t; + default: + return make.Apply(t.pos, t, Tree.EMPTY_ARRAY); + } + } + /////// OPERAND/OPERATOR STACK ///////////////////////////////////////////////// Tree[] operands = new Tree[8]; @@ -383,6 +403,9 @@ public class Parser implements Tokens { t = make.This(s.skipToken(), Tree.Empty); if (!thisOK || s.token == DOT) t = selectors(accept(DOT), t, typeOK); + } else if (s.token == SUPER) { + t = make.Super(s.skipToken(), Tree.Empty); + t = selectors(accept(DOT), t, typeOK); } else { t = make.Ident(s.pos, ident()); if (s.token == DOT) { @@ -413,7 +436,7 @@ public class Parser implements Tokens { } } - /** StableId ::= [[Ident `.'] this `.'] {Id `.'} Id + /** StableId ::= [[Ident `.'] this `.' | super] {Id `.'} Id */ Tree stableId() { return stableRef(false, false); @@ -498,6 +521,17 @@ public class Parser implements Tokens { } } + /** SimpleTypedOpt ::= [`:' Type] + */ + Tree simpleTypedOpt() { + if (s.token == COLON) { + s.nextToken(); + return simpleType(); + } else { + return Tree.Empty; + } + } + /** Types ::= Type {`,' Type} */ Tree[] types() { @@ -894,7 +928,8 @@ public class Parser implements Tokens { switch (res) { case Block(Tree[] stats): if (stats.length > 0) - stats[stats.length - 1] = convertToConstr(stats[stats.length - 1]); + stats[stats.length - 1] = applyConstr( + convertToConstr(stats[stats.length - 1])); else syntaxError(res.pos, "class constructor expected", false); } @@ -1337,9 +1372,7 @@ public class Parser implements Tokens { } /** TopDef ::= ([case] class | trait) ClassDef {`,' ClassDef} - * | module ModuleDef {`,' ModuleDef} - * LocalTopDef ::= class ClassDef {`,' ClassDef}//todo: keep? - * | module ModuleDef {`,' ModuleDef} + * | [case] object ModuleDef {`,' ModuleDef} */ Tree[] topDef(int mods) { TreeList ts = new TreeList(); @@ -1354,7 +1387,8 @@ public class Parser implements Tokens { ts.append(classDef(mods)); } while (s.token == COMMA); return ts.toArray(); - case MODULE: + case OBJECT: + case CASEOBJECT: do { s.nextToken(); ts.append(moduleDef(mods)); @@ -1441,10 +1475,7 @@ public class Parser implements Tokens { TypeDef[] tparams = typeParamClauseOpt(); ValDef[][] vparams = new ValDef[][]{paramClause()}; Tree restype = typedOpt(); - if (s.token == LBRACE) - return make.DefDef(pos, mods, name, tparams, vparams, - restype, blockConstr()); - else if (s.token == EQUALS || restype == Tree.Empty) { + if (s.token == EQUALS || restype == Tree.Empty) { accept(EQUALS); return make.DefDef(pos, mods, name, tparams, vparams, restype, (s.token == LBRACE) ? blockConstr() : constr()); @@ -1474,24 +1505,23 @@ public class Parser implements Tokens { } } - /** ClassDef ::= Id [TypeParamClause] [`:' Type] ClassTemplate + /** ClassDef ::= Id [TypeParamClause] [`:' SimpleType] ClassTemplate */ Tree classDef(int mods) { int pos = s.pos; Name name = ident(); TypeDef[] tparams = typeParamClauseOpt(); - ValDef[][] params; - if (s.token == LPAREN) params = new ValDef[][]{paramClause()}; - else params = Tree.ExtValDef.EMPTY_ARRAY_ARRAY; + ValDef[][] params = (s.token == LPAREN) ? new ValDef[][]{paramClause()} + : Tree.ExtValDef.EMPTY_ARRAY_ARRAY; return make.ClassDef(pos, mods, name.toTypeName(), tparams, params, - typedOpt(), classTemplate()); + simpleTypedOpt(), classTemplate()); } - /** ModuleDef ::= Id [`:' Type] ClassTemplate + /** ModuleDef ::= Id [`:' SimpleType] ClassTemplate */ Tree moduleDef(int mods) { return make.ModuleDef( - s.pos, mods, ident(), typedOpt(), classTemplate()); + s.pos, mods, ident(), simpleTypedOpt(), classTemplate()); } /** ClassTemplate ::= [`extends' Constr] {`with' Constr} [TemplateBody] @@ -1504,21 +1534,16 @@ public class Parser implements Tokens { } else if (s.token == WITH) { s.nextToken(); TreeList parents = new TreeList(); - parents.append(scalaDot(pos, Names.Object.toConstrName())); + parents.append(scalaObjectConstr(pos)); return template(parents); } else if (s.token == LBRACE) { - return (Template)make.Template(pos, - new Tree[]{scalaDot(pos, Names.Object.toConstrName())}, - templateBody()); - } else if (s.token == SEMI || s.token == COMMA || s.token == RBRACE) { - return (Template)make.Template(pos, - new Tree[]{scalaDot(pos, Names.Object.toConstrName())}, - Tree.EMPTY_ARRAY); + return (Template)make.Template( + pos, new Tree[]{scalaObjectConstr(pos)}, templateBody()); } else { - syntaxError("`extends' or `{' expected", true); - return (Template)make.Template(pos, - new Tree[]{scalaDot(pos, Names.Object.toConstrName())}, - Tree.EMPTY_ARRAY); + if (!(s.token == SEMI || s.token == COMMA || s.token == RBRACE)) + syntaxError("`extends' or `{' expected", true); + return (Template)make.Template( + pos, new Tree[]{scalaObjectConstr(pos)}, Tree.EMPTY_ARRAY); } } @@ -1550,7 +1575,7 @@ public class Parser implements Tokens { t = make.TypeApply(s.pos, t, typeArgs()); if (s.token == LPAREN) t = make.Apply(s.pos, t, argumentExprs()); - return t; + return applyConstr(t); } /** TemplateBody ::= `{' [TemplateStat {`;' TemplateStat}] `}' @@ -1601,11 +1626,12 @@ public class Parser implements Tokens { } else if (s.token == CLASS || s.token == CASECLASS || s.token == TRAIT || - s.token == MODULE || + s.token == OBJECT || + s.token == CASEOBJECT || isModifier()) { stats.append(topDef(modifiers())); } else if (s.token != SEMI) { - syntaxError("illegal start of class or module definition", true); + syntaxError("illegal start of class or object definition", true); } if (s.token != RBRACE && s.token != EOF) accept(SEMI); } @@ -1658,7 +1684,7 @@ public class Parser implements Tokens { /** BlockStatSeq ::= { BlockStat `;' } [Expr] * BlockStat ::= Import * | Def - * | LocalClassModifiers LocalTopDef + * | LocalClassModifiers TopDef * | Expr * | */ diff --git a/sources/scalac/ast/parser/Scanner.java b/sources/scalac/ast/parser/Scanner.java index 82eef0d408..5cfe8292a6 100644 --- a/sources/scalac/ast/parser/Scanner.java +++ b/sources/scalac/ast/parser/Scanner.java @@ -138,6 +138,8 @@ public class Scanner extends TokenData { fetchToken(); if (token == CLASS) { token = CASECLASS; + } else if (token == OBJECT) { + token = CASEOBJECT; } else { next.copyFrom(this); this.copyFrom(prev); @@ -479,8 +481,10 @@ public class Scanner extends TokenData { void treatIdent(int start, int end) { name = Name.fromAscii(buf, start, end - start); - if (name.index <= maxKey) + if (name.index <= maxKey) { token = key[name.index]; + if (token == OBJECT1) token = OBJECT; //todo: elim + } else token = IDENTIFIER; } @@ -716,6 +720,8 @@ public class Scanner extends TokenData { return "','"; case CASECLASS: return "case class"; + case CASEOBJECT: + return "case object"; default: try { return "'" + tokenName[token].toString() + "'"; @@ -796,7 +802,8 @@ public class Scanner extends TokenData { enterKeyword("def", DEF); enterKeyword("type", TYPE); enterKeyword("extends", EXTENDS); - enterKeyword("module", MODULE); + enterKeyword("object", OBJECT); + enterKeyword("module", OBJECT1); enterKeyword("class",CLASS); enterKeyword("constr",CONSTR); enterKeyword("import", IMPORT); diff --git a/sources/scalac/ast/parser/Tokens.java b/sources/scalac/ast/parser/Tokens.java index 10503ddd48..c4499522df 100644 --- a/sources/scalac/ast/parser/Tokens.java +++ b/sources/scalac/ast/parser/Tokens.java @@ -37,19 +37,20 @@ public interface Tokens { SUPER = 27, CASE = 28, CASECLASS = 29, - VAL = 30, - ABSTRACT = 31, - FINAL = 32, - PRIVATE = 33, - PROTECTED = 34, - OVERRIDE = 35, - VAR = 36, - DEF = 37, - TYPE = 38, - EXTENDS = 39, - TRUE = 40, - FALSE = 41, - MODULE = 43, + CASEOBJECT = 30, + VAL = 31, + ABSTRACT = 32, + FINAL = 33, + PRIVATE = 34, + PROTECTED = 35, + OVERRIDE = 36, + VAR = 37, + DEF = 38, + TYPE = 39, + EXTENDS = 40, + TRUE = 41, + FALSE = 42, + OBJECT = 43, CLASS = 44, CONSTR = 45, IMPORT = 46, @@ -60,6 +61,8 @@ public interface Tokens { DO = 51, TRAIT = 52, + OBJECT1 = 53, // todo: elim + /* special symbols */ COMMA = 61, SEMI = 62, diff --git a/sources/scalac/ast/printer/TextTreePrinter.java b/sources/scalac/ast/printer/TextTreePrinter.java index adbad7c3ad..0d4ff6022f 100644 --- a/sources/scalac/ast/printer/TextTreePrinter.java +++ b/sources/scalac/ast/printer/TextTreePrinter.java @@ -150,7 +150,7 @@ public class TextTreePrinter implements TreePrinter { protected static final Text KW_IMPORT = Text.Keyword("import"); protected static final Text KW_INTERFACE = Text.Keyword("interface"); protected static final Text KW_LET = Text.Keyword("let"); - protected static final Text KW_MODULE = Text.Keyword("module"); + protected static final Text KW_OBJECT = Text.Keyword("object"); protected static final Text KW_NEW = Text.Keyword("new"); protected static final Text KW_NULL = Text.Keyword("null"); protected static final Text KW_OUTER = Text.Keyword("outer"); @@ -171,8 +171,8 @@ public class TextTreePrinter implements TreePrinter { protected static final Text TXT_ERROR = Text.Simple("<error>"); protected static final Text TXT_UNKNOWN = Text.Simple("<unknown>"); protected static final Text TXT_NULL = Text.Simple("<null>"); - protected static final Text TXT_MODULE_COMMENT - = Text.Simple("/*module*/ "); + protected static final Text TXT_OBJECT_COMMENT + = Text.Simple("/*object*/ "); protected static final Text TXT_EMPTY = Text.Simple("<empty>"); protected static final Text TXT_QUOTE = Text.Simple("\""); @@ -192,10 +192,6 @@ public class TextTreePrinter implements TreePrinter { protected static final Text TXT_LEFT_BRACKET = Text.Simple("["); protected static final Text TXT_RIGHT_BRACKET = Text.Simple("]"); - protected static final Text TXT_WITH_BLOCK_BEGIN = - Text.Sequence(new Text[] { - Text.Space, KW_WITH, Text.Space, TXT_LEFT_BRACE, Text.Newline - }); protected static final Text TXT_WITH_SP = Text.Sequence(new Text[]{ Text.Space, KW_WITH, Text.Space }); protected static final Text TXT_BLOCK_BEGIN = @@ -271,7 +267,7 @@ public class TextTreePrinter implements TreePrinter { Tree tpe, Tree.Template impl): printModifiers(mods); - print(KW_MODULE); + print(KW_OBJECT); print(Text.Space); printSymbolDefinition(tree.symbol(), name); printOpt(TXT_COLON, tpe, false); @@ -282,7 +278,7 @@ public class TextTreePrinter implements TreePrinter { printModifiers(mods); if ((mods & Modifiers.MUTABLE) != 0) print(KW_VAR); else { - if ((mods & Modifiers.MODUL) != 0) print(TXT_MODULE_COMMENT); + if ((mods & Modifiers.MODUL) != 0) print(TXT_OBJECT_COMMENT); print(KW_VAL); } print(Text.Space); @@ -506,7 +502,7 @@ public class TextTreePrinter implements TreePrinter { case CompoundType(Tree[] baseTypes, Tree[] refinements): printArray(baseTypes, Text.None, Text.None, TXT_WITH_SP); - printArray(refinements, TXT_WITH_BLOCK_BEGIN, TXT_BLOCK_END, Text.Newline); + printArray(refinements, TXT_BLOCK_BEGIN, TXT_BLOCK_END, Text.Newline); break; case AppliedType(Tree tpe, Tree[] args): @@ -649,8 +645,10 @@ public class TextTreePrinter implements TreePrinter { printArray(templ.parents, Text.None, Text.None, TXT_WITH_SP); } - if (templ.body.length > 0) - printArray(templ.body, TXT_WITH_BLOCK_BEGIN, TXT_BLOCK_END, TXT_BLOCK_SEP); + if (templ.body.length > 0) { + print(Text.Space); + printArray(templ.body, TXT_BLOCK_BEGIN, TXT_BLOCK_END, TXT_BLOCK_SEP); + } } protected void printParams(Tree.TypeDef[] tparams) { diff --git a/sources/scalac/symtab/Definitions.java b/sources/scalac/symtab/Definitions.java index de31e34a06..3fe8cc7dee 100644 --- a/sources/scalac/symtab/Definitions.java +++ b/sources/scalac/symtab/Definitions.java @@ -194,7 +194,7 @@ public class Definitions { ANY_TYPE = ANY_CLASS.typeConstructor(); ANY_CLASS.setInfo(Type.compoundType(Type.EMPTY_ARRAY, new Scope(), ANY_CLASS)); ANY_CLASS.constructor().setInfo( - Type.PolyType(Symbol.EMPTY_ARRAY, ANY_TYPE)); + Type.MethodType(Symbol.EMPTY_ARRAY, ANY_TYPE)); // the java.lang.OBJECT class JAVA_OBJECT_CLASS = getClass(Names.java_lang_Object); diff --git a/sources/scalac/symtab/Modifiers.java b/sources/scalac/symtab/Modifiers.java index cbfafae068..8d161ce117 100644 --- a/sources/scalac/symtab/Modifiers.java +++ b/sources/scalac/symtab/Modifiers.java @@ -55,7 +55,7 @@ public interface Modifiers { int SNDTIME = 0x40000000; //debug // masks - int SOURCEFLAGS = 0x00000077 | PARAM | TRAIT; // these modifiers can be set in source programs. + int SOURCEFLAGS = 0x00000077 | DEF | REPEATED | MODUL | MUTABLE | PACKAGE | PARAM | TRAIT; // these modifiers can be set in source programs. int ACCESSFLAGS = PRIVATE | PROTECTED; public static class Helper { diff --git a/sources/scalac/symtab/Symbol.java b/sources/scalac/symtab/Symbol.java index b76b8c2869..7ecbfe543a 100644 --- a/sources/scalac/symtab/Symbol.java +++ b/sources/scalac/symtab/Symbol.java @@ -104,6 +104,14 @@ public abstract class Symbol implements Modifiers, Kinds { } public Symbol setInfo(Type info, int limit) { + assert !isConstructor() + || info instanceof Type.LazyType + || info == Type.ErrorType + || info instanceof Type.MethodType + || info instanceof Type.OverloadedType + || info instanceof Type.PolyType && + ((Type.PolyType)info).result instanceof Type.MethodType + : "illegal type for " + this + ": " + info; if ((flags & (INITIALIZED | LOCKED)) != (INITIALIZED | LOCKED)) { if (infos == TypeIntervalList.EMPTY) infos = new TypeIntervalList(TypeIntervalList.EMPTY); @@ -748,7 +756,7 @@ public abstract class Symbol implements Modifiers, Kinds { if ((flags & TRAIT) != 0) return "trait"; else if ((flags & MODUL) != 0 && Global.instance.debug) - return "module class"; + return "object class"; else return "class"; case TYPE: @@ -756,7 +764,7 @@ public abstract class Symbol implements Modifiers, Kinds { return "type"; case VAL: if (isVariable()) return "variable"; - else if (isModule()) return "module"; + else if (isModule()) return "object"; else if (isConstructor()) return "constructor"; else if (isInitializedMethod() && (Global.instance.debug || (flags & STABLE) == 0) ) @@ -775,7 +783,7 @@ public abstract class Symbol implements Modifiers, Kinds { case ALIAS: return "type"; case VAL: if (isVariable()) return "var"; - else if (isModule()) return "module"; + else if (isModule()) return "object"; else if (isInitializedMethod()) return "def"; else return "val"; default: return ""; diff --git a/sources/scalac/symtab/Type.java b/sources/scalac/symtab/Type.java index 571e12061a..d579ea9685 100644 --- a/sources/scalac/symtab/Type.java +++ b/sources/scalac/symtab/Type.java @@ -26,7 +26,9 @@ public class Type implements Modifiers, Kinds, TypeTags { public case ThisType(Symbol sym); - public case TypeRef(Type pre, Symbol sym, Type[] args); + public case TypeRef(Type pre, Symbol sym, Type[] args) { + assert pre.isLegalPrefix() || pre == ErrorType : pre + "#" + sym; + } public case SingleType(Type pre, Symbol sym) { assert this instanceof ExtSingleType; @@ -80,11 +82,12 @@ public class Type implements Modifiers, Kinds, TypeTags { public static final Type[] NO_ARRAY = new Type[0]; public static SingleType singleType(Type pre, Symbol sym) { - if (pre.isStable() || pre == ErrorType) + if (pre.isStable() || pre == ErrorType) { return new ExtSingleType(pre, sym); - else + } else { throw new Type.Error( - "malformed type: " + pre + "." + sym.nameString() + ".type"); + "malformed type: " + pre + "#" + sym.nameString() + ".type"); + } } public static TypeRef appliedType(Type tycon, Type[] args) { @@ -116,7 +119,7 @@ public class Type implements Modifiers, Kinds, TypeTags { SYNTHETIC | ABSTRACTCLASS); res.tsym.setInfo(res); res.tsym.constructor().setInfo( - Type.PolyType(Symbol.EMPTY_ARRAY, Type.NoType)); + Type.MethodType(Symbol.EMPTY_ARRAY, Type.NoType)); return res; } @@ -127,7 +130,7 @@ public class Type implements Modifiers, Kinds, TypeTags { return pre.memberInfo(sym); else // todo: handle Java-style inner classes throw new Type.Error( - "malformed type: " + pre + "." + sym.nameString()); + "malformed type: " + pre + "#" + sym.nameString()); } static class ExtSingleType extends SingleType { @@ -634,7 +637,7 @@ public class Type implements Modifiers, Kinds, TypeTags { Type pre1 = apply(pre); Type[] args1 = map(args); if (pre1 == pre && args1 == args) return tp; - else return TypeRef(pre1, sym, args1); + else return typeRef(pre1, sym, args1); case SingleType(Type pre, Symbol sym): Type pre1 = apply(pre); if (pre1 == pre) return tp; @@ -866,7 +869,7 @@ public class Type implements Modifiers, Kinds, TypeTags { Type[] args1 = map(args); typeArg = prevTypeArg; if (prefix1 == prefix && args1 == args) return t; - else return TypeRef(prefix1, sym1, args1); + else return typeRef(prefix1, sym1, args1); } case SingleType(Type prefix, Symbol sym): @@ -1075,7 +1078,7 @@ public class Type implements Modifiers, Kinds, TypeTags { protected Type replacement(int i, Type fromtp) { switch (fromtp) { case TypeRef(Type pre, Symbol sym, Type[] args): - return TypeRef(pre, to[i], args); + return typeRef(pre, to[i], args); case SingleType(Type pre, Symbol sym): return singleType(pre, to[i]); default: @@ -1822,7 +1825,7 @@ public class Type implements Modifiers, Kinds, TypeTags { if (args[j] == NoType) args[j] = CovarType(lub(argss[j])); } - return TypeRef(pre, sym, args); + return typeRef(pre, sym, args); } /** The frontier of a closure C is the minimal set of types such that @@ -2050,7 +2053,7 @@ public class Type implements Modifiers, Kinds, TypeTags { Type this1 = unbox(); if (this1 != this) return this1; else if (args.length == 0) return this; - else return TypeRef(pre, sym, Type.EMPTY_ARRAY); + else return typeRef(pre, sym, Type.EMPTY_ARRAY); } default: throw new ApplicationError(); @@ -2104,6 +2107,7 @@ public class Type implements Modifiers, Kinds, TypeTags { case ThisType(Symbol sym): if (sym.isRoot()) return "<root>.this.type"; else if (this == localThisType) return "<local>.this.type"; + else if (sym.isAnonymousClass()) return "this.type"; else { Type this1 = (Global.instance.debug) ? this : expandModuleThis(); if (this1 == this) return sym.nameString() + ".this.type"; @@ -2195,7 +2199,7 @@ public class Type implements Modifiers, Kinds, TypeTags { else if (spre.endsWith(".type")) return spre.substring(0, spre.length() - 4); else - return spre + "@"; + return spre + "#"; } } diff --git a/sources/scalac/symtab/classfile/AttributeParser.java b/sources/scalac/symtab/classfile/AttributeParser.java index 8cc8e296d0..a6ae0a9083 100644 --- a/sources/scalac/symtab/classfile/AttributeParser.java +++ b/sources/scalac/symtab/classfile/AttributeParser.java @@ -253,7 +253,9 @@ public class AttributeParser implements ClassfileConstants { if ((parser.c.flags & Modifiers.INTERFACE) != 0) { parser.c.constructor().setInfo( - Type.PolyType(smbls, constrtype), parser.phaseId); + Type.PolyType( + smbls, Type.MethodType(Symbol.EMPTY_ARRAY, constrtype)), + parser.phaseId); //System.out.println("info = " + parser.c.constructor().info());//DEBUG } Symbol[] constrs; @@ -269,13 +271,9 @@ public class AttributeParser implements ClassfileConstants { switch (constrs[i].rawInfo()) { case MethodType(Symbol[] vparams, _): constrs[i].setInfo( - Type.PolyType(smbls, - Type.MethodType( - vparams, constrtype)), parser.phaseId); - break; - case PolyType(_, _): - constrs[i].setInfo( - Type.PolyType(smbls, constrtype), parser.phaseId); + Type.PolyType( + smbls, Type.MethodType(vparams, constrtype)), + parser.phaseId); break; } //System.out.println("*** constructor " + e.sym + ": " + e.sym.info());//DEBUG diff --git a/sources/scalac/symtab/classfile/ClassfileParser.java b/sources/scalac/symtab/classfile/ClassfileParser.java index 69d95f79f0..a0d69c4bed 100644 --- a/sources/scalac/symtab/classfile/ClassfileParser.java +++ b/sources/scalac/symtab/classfile/ClassfileParser.java @@ -117,10 +117,9 @@ public class ClassfileParser implements ClassfileConstants { assert constrs.length == 1; c.constructor().setInfo(constrs[0].info(), phaseId); } else { - Type constrtype = ((c.flags & Modifiers.INTERFACE) != 0) - ? Type.PolyType(Symbol.EMPTY_ARRAY, ctype) - : Type.MethodType(new Symbol[]{Symbol.NONE}, ctype); - c.constructor().setInfo(constrtype, phaseId); + Symbol[] cparams = ((c.flags & Modifiers.INTERFACE) != 0) ? Symbol.EMPTY_ARRAY + : new Symbol[]{Symbol.NONE}; + c.constructor().setInfo(Type.MethodType(cparams, ctype), phaseId); } attrib.readAttributes(c, classType, CLASS_ATTR); //System.out.println("dynamic class: " + c); @@ -214,10 +213,7 @@ public class ClassfileParser implements ClassfileConstants { } switch (type) { case MethodType(Symbol[] vparams, _): - if (c == defs.OBJECT_CLASS) - type = Type.PolyType(Symbol.EMPTY_ARRAY, ctype); - else - type = Type.MethodType(vparams, ctype); + type = Type.MethodType(vparams, ctype); break; default: throw new ApplicationError(); diff --git a/sources/scalac/transformer/AddConstructors.java b/sources/scalac/transformer/AddConstructors.java index 6e69d191c3..14ee843677 100644 --- a/sources/scalac/transformer/AddConstructors.java +++ b/sources/scalac/transformer/AddConstructors.java @@ -139,7 +139,9 @@ public class AddConstructors extends Transformer { getConstructor(fun.symbol())); constrBody.add(gen.Apply(superConstr, transform(args))); break; - default: assert false; + default: + new scalac.ast.printer.TextTreePrinter().print(baseClasses[0]).println().end(); + assert false; } } diff --git a/sources/scalac/transformer/ExpandMixins.java b/sources/scalac/transformer/ExpandMixins.java index 19984b4b61..9ce484ab12 100644 --- a/sources/scalac/transformer/ExpandMixins.java +++ b/sources/scalac/transformer/ExpandMixins.java @@ -345,9 +345,10 @@ public class ExpandMixins extends Transformer { case Apply(Select(Tree qualifier, Name selector), Tree[] args): { Tree fun = ((Tree.Apply)newTree).fun; Symbol funOwnerSym = fun.symbol().owner(); - Symbol qualSym = qualifier.type.symbol(); + Symbol qualSym = qualifier.type.symbol().moduleClass(); if (! (qualifier instanceof Tree.Super || qualSym.isSubClass(funOwnerSym))) { + global.log("inserting cast from " + qualSym + " to " + funOwnerSym);//debug Type ownerTp = funOwnerSym.type(); Tree castQualifier = gen.Apply(gen.TypeApply(gen.Select(qualifier, defs.AS), diff --git a/sources/scalac/typechecker/Analyzer.java b/sources/scalac/typechecker/Analyzer.java index da24b2ea86..ee545ac7d3 100644 --- a/sources/scalac/typechecker/Analyzer.java +++ b/sources/scalac/typechecker/Analyzer.java @@ -85,7 +85,7 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { if (sym.pos == Position.NOPOS) { sym.setInfo(Type.ErrorType); String kind; - if (sym.name.isTermName()) kind = "module or method "; + if (sym.name.isTermName()) kind = "object or method "; else if (sym.name.isTypeName()) kind = "class "; else kind = "constructor "; throw new Type.Error("file " + unit.source + " does not define public " + @@ -213,7 +213,7 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { String decode(Name name) { if (name.isTypeName()) return "type " + name; else if (name.isConstrName()) return "constructor " + name; - else return name.toString(); + else return "value " + name.toString(); } /** Is `sym' accessible as a member of tree `site' in current context? @@ -318,6 +318,8 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { if ((bsym.flags & INTERFACE) != 0) error(constrs[0].pos, "superclass may not be a Java interface"); } else { + if ((bsym.flags & (JAVA | INTERFACE)) == JAVA) + error(constrs[i].pos, "Java class may not be used as mixin"); Type[] grandparents = parents[i].parents(); if (grandparents.length > 0 && !parents[0].isSubType(grandparents[0])) @@ -421,17 +423,6 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { } } - /** Check that found type conforms to required one. - */ - Type checkType(int pos, Type found, Type required) { - if (found.isSubType(required)) return found; - else { - typeError(pos, found, required); - explainTypes(found, required); - return Type.ErrorType; - } - } - /** Check that type is eta-expandable (i.e. no `def' parameters) */ void checkEtaExpandable(int pos, Type tp) { @@ -545,14 +536,21 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { Tree checkStable(Tree tree) { if (TreeInfo.isPureExpr(tree) || tree.type == Type.ErrorType) return tree; //new TextTreePrinter().print(tree).end();//DEBUG - //System.out.println(" " + tree.type);//DEBUG + //System.out.println(" " + tree.symbol() + ":" + tree.type);//DEBUG return error(tree.pos, "stable identifier required"); } - /** Check that (abstract) type can be instantiated. + /** Check that class can be instantiated. */ void checkInstantiatable(int pos, Type tp) { - error(pos, tp.symbol() + " is abstract; cannot be instantiated"); + Symbol clazz = tp.symbol(); + if (clazz.kind == CLASS) { + if ((clazz.flags & ABSTRACTCLASS) != 0) + error(pos, clazz + " is abstract, so it cannot be instantiated"); + else if (!tp.isSubType(tp.instanceType())) + error(pos, tp + " does not conform to its self-type " + + tp.instanceType() + ", so it cannot be instantiated"); + } } /** Check all members of class `clazz' for overriding conditions. @@ -851,9 +849,9 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { // Definining Symbols ------------------------------------------------------- - /** Define symbol associated with `tree' using given `context'. + /** Define symbol associated with `tree' using given `unit' and `context'. */ - void defineSym(Tree tree, Unit unit, Infer infer, Context curcontext) { + void defineSym(Tree tree, Unit unit, Context curcontext) { Unit savedUnit = this.unit; this.unit = unit; Context savedContext = this.context; @@ -878,6 +876,8 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { pushContext(tree, sym.constructor(), new Scope(context.scope)); Symbol[] tparamSyms = enterParams(tparams); Symbol[][] vparamSyms = enterParams(vparams); + if (vparamSyms.length == 0) + vparamSyms = new Symbol[][]{Symbol.EMPTY_ARRAY}; if ((mods & CASE) != 0 && vparams.length > 0) templ.body = desugarize.addCaseElements(templ.body, vparams[0]); @@ -891,7 +891,7 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { sym.constructor().flags |= INITIALIZED; if (tpe != Tree.Empty) - sym.setTypeOfThis(transform(tpe, TYPEmode).type); + sym.setTypeOfThis(new LazySelfType(tpe)); defineTemplate(templ, sym); owntype = templ.type; @@ -1001,7 +1001,7 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { void defineTemplate(Tree.Template templ, Symbol clazz) { // attribute parent constructors Tree[] constrs = transformConstrInvocations( - templ.pos, templ.parents, true, Type.AnyType); + templ.pos, templ.parents, true); Type[] parents = new Type[constrs.length]; for (int i = 0; i < parents.length; i++) @@ -1068,6 +1068,21 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { reenterParams(vparams[i]); } + /** Define self type of class or module `sym' + * associated with `tree' using given `unit' and `context'. + */ + void defineSelfType(Symbol sym, Tree tree, Unit unit, Context curcontext) { + Unit savedUnit = this.unit; + this.unit = unit; + Context savedContext = this.context; + this.context = curcontext; + + sym.setInfo(transform(tree, TYPEmode).type); + + this.unit = savedUnit; + this.context= savedContext; + } + // Attribution and Transform ------------------------------------------------- /** Attribute an identifier consisting of a simple name or an outer reference. @@ -1284,12 +1299,11 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { /** Attribute a sequence of constructor invocations. */ - Tree[] transformConstrInvocations(int pos, Tree[] constrs, - boolean delayArgs, Type pt) { + Tree[] transformConstrInvocations(int pos, Tree[] constrs, boolean delayArgs) { for (int i = 0; i < constrs.length; i++) { pushContext(constrs[i], context.owner, context.scope); context.delayArgs = delayArgs; - constrs[i] = transform(constrs[i], CONSTRmode, pt); + constrs[i] = transform(constrs[i], CONSTRmode, Type.AnyType); Symbol f = TreeInfo.methSymbol(constrs[i]); if (f != null) { Symbol c = f.primaryConstructorClass(); @@ -1306,7 +1320,7 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { if (global.debug) global.log("transforming " + owner);//debug //System.out.println(owner.info());//DEBUG Tree[] parents1 = transformConstrInvocations( - templ.pos, templ.parents, false, Type.AnyType); + templ.pos, templ.parents, false); if (owner.kind != ERROR) { validateParentClasses( templ.parents, owner.info().parents(), owner.typeOfThis()); @@ -1636,7 +1650,7 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { " does not conform to sequence " + clazz); } } else if (tree.type != Type.ErrorType) { - error(tree.pos, tree.symbol() + + error(tree.pos, tree.type.symbol() + " is neither a case class constructor nor a sequence class constructor"); } } @@ -1648,20 +1662,26 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { // check that other idents or selects are stable. switch (tree) { case Ident(Name name): - if (sym != null && isNullaryMethod(sym) && (sym.flags & CASE) != 0) { - ((Ident)tree).name = name.toTypeName(); - return transform(tree, mode, pt); - } else { + if (sym != null && isNullaryMethod(sym) && (sym.flags & CASE) != 0) + return transform( + make.Apply( + tree.pos, + copy.Ident(tree, name.toTypeName()), + Tree.EMPTY_ARRAY), + mode, pt); + else checkStable(tree); - } break; - case Select(_, Name selector): - if (sym != null && isNullaryMethod(sym) && (sym.flags & CASE) != 0) { - ((Select)tree).selector = selector.toTypeName(); - return transform(tree, mode, pt); - } else { + case Select(Tree qual, Name name): + if (sym != null && isNullaryMethod(sym) && (sym.flags & CASE) != 0) + return transform( + make.Apply( + tree.pos, + copy.Select(tree, qual, name.toTypeName()), + Tree.EMPTY_ARRAY), + mode, pt); + else checkStable(tree); - } } } } else if ((mode & EXPRmode) != 0) { @@ -1700,9 +1720,14 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { } } - if (!(tree.type instanceof Type.PolyType)) - tree.type = checkType(tree.pos, tree.type, pt); - + Type owntype = tree.type; + if ((mode & (CONSTRmode | FUNmode)) == (CONSTRmode)) + owntype = owntype.instanceType(); + if (!(owntype instanceof Type.PolyType || owntype.isSubType(pt))) { + typeError(tree.pos, owntype, pt); + explainTypes(owntype, pt); + tree.type = Type.ErrorType; + } return tree; } //where @@ -1757,6 +1782,8 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { Symbol sym = tree1.symbol(); if ((mode & FUNmode) == 0 && sym != null && sym.typeParams().length != 0) return error(tree.pos, sym + " takes type parameters."); +// else if (tree1.isType()) +// return gen.mkType(tree1.pos, tree1.type); else return tree1; } @@ -1807,12 +1834,6 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { Tree.ValDef[][] vparams1 = transform(vparams); Tree tpe1 = transform(tpe); Tree.Template templ1 = transformTemplate(templ, sym); - - if ((sym.flags & ABSTRACTCLASS) == 0 && - !sym.type().isSubType(sym.typeOfThis())) - error(sym.pos, sym + - " needs to be abstract; it does not conform to its self-type " + - sym.typeOfThis()); popContext(); return copy.ClassDef(tree, mods, name, tparams1, vparams1, tpe1, templ1) .setType(definitions.UNIT_TYPE); @@ -1954,8 +1975,7 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { copy.Template(templ, new Tree[]{parent1}, body) .setType(parent1.type).setSymbol(Symbol.NONE); Type owntype = parent1.type; - if ((owntype.symbol().constructor().flags & ABSTRACTCLASS) != 0) - checkInstantiatable(tree.pos, owntype); + checkInstantiatable(tree.pos, owntype); return copy.New(tree, templ1) .setType(owntype.instanceType()); } else { @@ -2078,7 +2098,7 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { switch (enclClazz.info()) { case CompoundType(Type[] parents, _): return copy.Super(tree, tpe1) - .setType(Type.compoundType(parents, Scope.EMPTY)); + .setType(Type.compoundType(parents, Scope.EMPTY).symbol().thisType()); case ErrorType: return tree.setType(Type.ErrorType); default: @@ -2086,7 +2106,7 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { } } else { return error(tree.pos, - "super can be used only in a class, module, or template"); + "super can be used only in a class, object, or template"); } case This(Tree qual): @@ -2099,16 +2119,16 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { } else { return error( tree.pos, tree + - " can be used only in a class, module, or template"); + " can be used only in a class, object, or template"); } } else { Tree qual1 = transform(qual, TYPEmode | FUNmode); - clazz = qual1.symbol(); + clazz = qual1.type.symbol(); if (clazz.kind == CLASS) { Context clazzContext = context.outerContext(clazz); if (clazzContext != Context.NONE) { if (!(qual1 instanceof Tree.Ident)) - qual1 = gen.Ident(tree.pos, qual1.symbol()); + qual1 = gen.Ident(tree.pos, clazz); tree1 = copy.This(tree, qual1); } else { return error(qual.pos, @@ -2245,20 +2265,18 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { class LazyTreeType extends Type.LazyType { Tree tree; Unit u; - Infer i; Context c; LazyTreeType(Tree tree) { this.tree = tree; this.u = unit; - this.i = infer; this.c = context; } public void complete(Symbol sym) { //System.out.println("completing " + sym);//DEBUG //if (sym.isConstructor()) sym.constructorClass().initialize(); //else if (sym.isModule()) sym.moduleClass().initialize(); - defineSym(tree, u, i, c); + defineSym(tree, u, c); } } @@ -2270,7 +2288,35 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { super(tree); } public void complete(Symbol sym) { - sym.setInfo(tree.symbol().constructor().type().instanceType()); + Type constrtype = tree.symbol().constructor().type().instanceType(); + switch (tree) { + case ClassDef(_, _, _, ValDef[][] vparams, _, _): + if (vparams.length == 0) { + constrtype = removeMethod(constrtype); + } + } + sym.setInfo(constrtype); + } + private Type removeMethod(Type tp) { + switch (tp) { + case MethodType(_, Type restp): + return restp; + case PolyType(Symbol[] tparams, Type restp): + return Type.PolyType(tparams, removeMethod(restp)); + default: + return tp; + } + } + } + + /** A lazy type for self types + */ + class LazySelfType extends LazyTreeType { + LazySelfType(Tree tree) { + super(tree); + } + public void complete(Symbol sym) { + defineSelfType(sym, tree, u, c); } } } diff --git a/sources/scalac/typechecker/DeSugarize.java b/sources/scalac/typechecker/DeSugarize.java index ae7dd9b970..91faf4adb6 100644 --- a/sources/scalac/typechecker/DeSugarize.java +++ b/sources/scalac/typechecker/DeSugarize.java @@ -164,7 +164,7 @@ public class DeSugarize implements Kinds, Modifiers { } /** (x_1: T_1, ..., x_n: T_N) => e ==> - * new scala.Function[T_1, ..., T_N, T] with { + * new new scala.Object() with scala.Function[T_1, ..., T_N, T]() { * def apply(x_1: T_1, ..., x_N: T_N): T = e * } * where T = `restpe' @@ -182,14 +182,23 @@ public class DeSugarize implements Kinds, Modifiers { for (int i = 0; i < length; i++) argtpes[i] = vparams[i].tpe; argtpes[vparams.length] = restpe; - Tree objConstr = make.Select(tree.pos, - make.Ident(tree.pos, Names.scala), - Names.Object.toConstrName()); - Tree constr = make.TypeApply(tree.pos, - make.Select(tree.pos, - make.Ident(tree.pos, Names.scala), - Name.fromString("Function" + length).toConstrName()), - argtpes); + Tree objConstr = make.Apply( + tree.pos, + make.Select( + tree.pos, + make.Ident(tree.pos, Names.scala), + Names.Object.toConstrName()), + Tree.EMPTY_ARRAY); + Tree constr = make.Apply( + tree.pos, + make.TypeApply( + tree.pos, + make.Select( + tree.pos, + make.Ident(tree.pos, Names.scala), + Name.fromString("Function" + length).toConstrName()), + argtpes), + Tree.EMPTY_ARRAY); Tree applyDef = make.DefDef( tree.pos, 0, Names.apply, @@ -225,7 +234,7 @@ public class DeSugarize implements Kinds, Modifiers { } /** Cases, Argtpe, Restpe ==> - * (new scala.PartialFunction[Argtpe, Restpe] { + * (new scala.PartialFunction[Argtpe, Restpe]() { * def apply(x: Argtpe): Restpe = x match {Cases} * def isDefinedAt(x: Argtpe): scala.Boolean = x match {Cases'} * }: scala.PartialFunction[Argtpe, +Restpe]) @@ -236,12 +245,18 @@ public class DeSugarize implements Kinds, Modifiers { * Restpe = targs[1] */ public Tree partialFunction(Tree tree, Type pattpe, Type restpe) { - Tree constr = make.TypeApply(tree.pos, - make.Select(tree.pos, - make.Ident(tree.pos, Names.scala), - Names.PartialFunction.toConstrName()), - new Tree[]{gen.mkType(tree.pos, pattpe), - gen.mkType(tree.pos, restpe)}); + Tree constr = + make.Apply( + tree.pos, + make.TypeApply( + tree.pos, + make.Select( + tree.pos, + make.Ident(tree.pos, Names.scala), + Names.PartialFunction.toConstrName()), + new Tree[]{gen.mkType(tree.pos, pattpe), + gen.mkType(tree.pos, restpe)}), + Tree.EMPTY_ARRAY); Name x = getvar(); ValDef param = (ValDef) make.ValDef( tree.pos, PARAM, x, gen.mkType(tree.pos, pattpe), Tree.Empty); @@ -547,9 +562,17 @@ public class DeSugarize implements Kinds, Modifiers { public Tree toConstructor(Tree tree, Symbol constr) { switch (tree) { case Apply(Tree fn, Tree[] args): - return copy.Apply(tree, toConstructor(fn, constr), args); + return toConstructor1(tree, constr); + default: + return make.Apply(tree.pos, toConstructor1(tree, constr), Tree.EMPTY_ARRAY); + } + } + private Tree toConstructor1(Tree tree, Symbol constr) { + switch (tree) { + case Apply(Tree fn, Tree[] args): + return copy.Apply(tree, toConstructor1(fn, constr), args); case TypeApply(Tree fn, Tree[] args): - return copy.TypeApply(tree, toConstructor(fn, constr), args); + return copy.TypeApply(tree, toConstructor1(fn, constr), args); case Ident(Name name): return copy.Ident(tree, constr.name).setSymbol(constr); case Select(Tree qual, Name name): diff --git a/sources/scalac/typechecker/RefCheck.java b/sources/scalac/typechecker/RefCheck.java index af02095030..74ab754ae0 100644 --- a/sources/scalac/typechecker/RefCheck.java +++ b/sources/scalac/typechecker/RefCheck.java @@ -3,16 +3,6 @@ ** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** ** /_____/\____/\___/\____/____/ ** \* */ - -// $Id$ - -// todo: Any cannot be inherited. -// todo: check that only stable defs override stable defs -// todo: admit vardefs w/o rhs -// ClassTemplate ::= [extends Constr {with Constr}] -// [with `(' TemplateStatSeq `)'] -// todo: pretty printer prints wrong precedence for `new' (-> lambdalift.scala). - package scalac.typechecker; import java.util.HashMap; @@ -126,6 +116,18 @@ public class RefCheck extends Transformer implements Modifiers, Kinds { return stats; } + public Tree nullTree(int pos, Type tp) { + return gen.TypeApply( + gen.Ident(pos, global.definitions.NULL), + new Tree[]{gen.mkType(pos, tp)}); + } + + private boolean isGlobalModule(Symbol sym) { + return + sym.isModule() && + (sym.owner().isPackage() || isGlobalModule(sym.owner().module())); + } + /** The main checking functions */ public Tree[] transformStat(Tree tree, int index) { @@ -133,38 +135,55 @@ public class RefCheck extends Transformer implements Modifiers, Kinds { switch (tree) { case ModuleDef(int mods, Name name, Tree tpe, Tree.Template templ): Symbol sym = tree.symbol(); - // local modules are not yet supported but the interpreter - // accepts modules at the console level - if (sym.isLocal()) unit.error("local modules are not yet supported"); - - Tree[] result = new Tree[2]; - result[0] = make.ClassDef( + Tree cdef = make.ClassDef( tree.pos, mods | FINAL | MODUL, name.toTypeName(), - new Tree.TypeDef[0], - new Tree.ValDef[][]{{}}, + Tree.ExtTypeDef.EMPTY_ARRAY, + Tree.ExtValDef.EMPTY_ARRAY_ARRAY, Tree.Empty, templ) .setSymbol(sym.moduleClass()).setType(tree.type); - result[1] = make.ValDef( + Tree alloc = gen.New( tree.pos, - mods | MODUL, - name, - (tpe == Tree.Empty) ? gen.mkType(tree.pos, sym.type()) : tpe, - gen.New( - tree.pos, - sym.type().prefix(), - sym.moduleClass(), - Tree.EMPTY_ARRAY)) - .setSymbol(sym).setType(tree.type); + sym.type().prefix(), + sym.moduleClass(), + Tree.EMPTY_ARRAY); + Tree[] result; + if (isGlobalModule(sym)) { + Tree vdef = gen.ValDef(sym, alloc); + result = new Tree[]{cdef, vdef}; + } else { + // var m$: T = null[T]; + Name varname = Name.fromString(name + "$"); + Symbol mvar = new TermSymbol( + tree.pos, varname, sym.owner(), PRIVATE | MUTABLE | SYNTHETIC) + .setInfo(sym.type()); + Tree vdef = gen.ValDef(mvar, nullTree(tree.pos, sym.type())); + + // { if (m$ == null[T]) m$ = new m$class; m$ } + Tree body = gen.Block(new Tree[]{ + gen.If( + gen.Apply( + gen.Select(gen.mkRef(tree.pos, mvar), global.definitions.EQEQ), + new Tree[]{nullTree(tree.pos, sym.type())}), + gen.Assign(gen.mkRef(tree.pos, mvar), alloc), + gen.Block(tree.pos, Tree.EMPTY_ARRAY)), + gen.mkRef(tree.pos, mvar)}); + + // def m: T = { if (m$ == null[T]) m$ = new m$class; m$ } + sym.updateInfo(Type.PolyType(Symbol.EMPTY_ARRAY, sym.type())); + sym.flags |= STABLE; + Tree ddef = gen.DefDef(sym, body); + result = new Tree[]{cdef, vdef, ddef}; + } return transform(result); case ValDef(int mods, Name name, Tree tpe, Tree rhs): Symbol sym = tree.symbol(); resultTree = transform(tree); //todo: handle variables - if (sym.isLocal() && index <= maxindex[level]) { + if (sym.isLocal() && !sym.isModule() && index <= maxindex[level]) { if (Global.instance.debug) System.out.println(refsym[level] + ":" + refsym[level].type()); unit.error( @@ -180,6 +199,7 @@ public class RefCheck extends Transformer implements Modifiers, Kinds { } public Tree transform(Tree tree) { + Tree tree1; switch (tree) { case Template(Tree[] bases, Tree[] body): Tree[] bases1 = transform(bases); @@ -188,6 +208,10 @@ public class RefCheck extends Transformer implements Modifiers, Kinds { case Block(Tree[] stats): Tree[] stats1 = transformStats(stats); return copy.Block(tree, stats1); + case This(_): + return tree; + case PackageDef(Tree pkg, Template packaged): + return copy.PackageDef(tree, pkg, super.transform(packaged)); case Ident(Name name): Scope.Entry e = scopes[level].lookupEntry(name); Symbol sym = tree.symbol(); @@ -202,10 +226,14 @@ public class RefCheck extends Transformer implements Modifiers, Kinds { maxindex[i] = symindex; } } - return tree; + tree1 = tree; + break; default: - return super.transform(tree); + tree1 = super.transform(tree); } + if (tree1.isType() && !tree1.isMissing()) + tree1 = gen.mkType(tree1.pos, tree1.type); + return tree1; } } diff --git a/support/latex/verbfilterScala.java b/support/latex/verbfilterScala.java index a2b1043a0f..67de443798 100644 --- a/support/latex/verbfilterScala.java +++ b/support/latex/verbfilterScala.java @@ -7,7 +7,7 @@ public class verbfilterScala { static String[] reserved = { "abstract", "case", "class", "def", "do", "else", "extends", "false", "final", "for", "if", "import", - "module", "new", "null", "override", "package", + "module", "new", "null", "object", "override", "package", "private", "protected", "super", "this", "trait", "true", "type", "val", "var", "with", "yield"}; diff --git a/test/files/neg/S2.scala b/test/files/neg/S2.scala index 83cc1829a3..47687a916a 100644 --- a/test/files/neg/S2.scala +++ b/test/files/neg/S2.scala @@ -7,7 +7,7 @@ ** def t = foo(x, y); ** ^ */ -module M { +object M { def foo[T](x: T, y: T): T = x; class S2() { class Inner() extends S2() {} diff --git a/test/files/neg/altherr1.scala b/test/files/neg/altherr1.scala index 69443bfd06..9eb0cc9987 100644 --- a/test/files/neg/altherr1.scala +++ b/test/files/neg/altherr1.scala @@ -1,6 +1,6 @@ case class Foo[a](); -module Bug { +object Bug { def foo[a](): Foo[a] = foo[a](); foo() match { case _ => 0 } } diff --git a/test/files/neg/altherr2.scala b/test/files/neg/altherr2.scala index 41bcffca36..6ab26526f7 100644 --- a/test/files/neg/altherr2.scala +++ b/test/files/neg/altherr2.scala @@ -1,6 +1,6 @@ trait Foo[a]; -module Bug { +object Bug { def foo[a](): Foo[a] = foo[a](); foo()[Int]; } diff --git a/test/files/neg/altherr3.scala b/test/files/neg/altherr3.scala index bb40099e1e..a96513e832 100644 --- a/test/files/neg/altherr3.scala +++ b/test/files/neg/altherr3.scala @@ -1,6 +1,6 @@ // $Id$ -module bug { +object bug { //########################################################################## diff --git a/test/files/neg/vincent1.scala b/test/files/neg/vincent1.scala index 53104be640..6082b271b3 100644 --- a/test/files/neg/vincent1.scala +++ b/test/files/neg/vincent1.scala @@ -1,4 +1,4 @@ -module test { +object test { trait A { type T; } diff --git a/test/files/pos/A.scala b/test/files/pos/A.scala index 2f7c958ae2..513c8bed45 100644 --- a/test/files/pos/A.scala +++ b/test/files/pos/A.scala @@ -1,6 +1,6 @@ trait A extends scala.Object {} -module test { +object test { def x: A = x; diff --git a/test/files/pos/IntSet.scala b/test/files/pos/IntSet.scala index cfffc88944..639a099d9a 100644 --- a/test/files/pos/IntSet.scala +++ b/test/files/pos/IntSet.scala @@ -4,8 +4,8 @@ trait IntSet { def foreach(f: Int => Unit): Unit; def union(that: IntSet): IntSet; } -module Empty extends IntSet { - def contains(x: Int): Boolean = false; +object Empty extends IntSet { + def contains(x: Int): Boolean = Boolean.False; def incl(x: Int): IntSet = new NonEmpty(x, Empty, Empty); def foreach(f: Int => Unit): Unit = (); def union(that: IntSet): IntSet = that; @@ -26,7 +26,7 @@ class NonEmpty(elem: Int, left: IntSet, right: IntSet) extends IntSet { } def union(that: IntSet): IntSet = (left union (right union that)) incl elem; } -module test { +object test { def main = { val x = Empty incl 1 incl 2; val y = Empty incl 2 incl 3; diff --git a/test/files/pos/List1.scala b/test/files/pos/List1.scala index fcc506bccc..6c54f109ce 100644 --- a/test/files/pos/List1.scala +++ b/test/files/pos/List1.scala @@ -1,4 +1,4 @@ -module lists { +object lists { trait List[a] { def isEmpty: Boolean; diff --git a/test/files/pos/S5.scala b/test/files/pos/S5.scala index 87325b47e4..08f5b2a6eb 100644 --- a/test/files/pos/S5.scala +++ b/test/files/pos/S5.scala @@ -25,6 +25,6 @@ abstract class N() { // module body of N } } -module O { +object O { val system = new M() with N() {} } diff --git a/test/files/pos/S8.scala b/test/files/pos/S8.scala index e4339bb3f1..50f1df27a2 100644 --- a/test/files/pos/S8.scala +++ b/test/files/pos/S8.scala @@ -13,7 +13,7 @@ class S8() { class A() extends a.B() {} class B() {} } -module M { +object M { val x = new S8(); val y: x.a.B = new x.A(); //correct? } diff --git a/test/files/pos/Y.scala b/test/files/pos/Y.scala index 425d7fb346..ebef6f9e36 100644 --- a/test/files/pos/Y.scala +++ b/test/files/pos/Y.scala @@ -1,4 +1,4 @@ -module test { +object test { def f(x: Object): Object = x.match; diff --git a/test/files/pos/Z.scala b/test/files/pos/Z.scala index c19081e68c..c1367e46b9 100644 --- a/test/files/pos/Z.scala +++ b/test/files/pos/Z.scala @@ -2,7 +2,7 @@ trait X { val elem: Int = 1 } -module test { +object test { def g(x: X) = x.elem; def f(x: Object) = x.toString(); diff --git a/test/files/pos/cls.scala b/test/files/pos/cls.scala index 3a46c306db..54104ae692 100644 --- a/test/files/pos/cls.scala +++ b/test/files/pos/cls.scala @@ -8,7 +8,7 @@ class B[Y](y1: Y, y2: Y) extends A[Y, Y](y1, y2) { def g() = f(y1, this); } -module test { +object test { val b: B[Int] = new B[Int](1, 2); val a: A[Int, Int] = b; val a1 = new A(1, "hello"); diff --git a/test/files/pos/clsrefine.scala b/test/files/pos/clsrefine.scala index 12f5aa5246..56db9d4c13 100644 --- a/test/files/pos/clsrefine.scala +++ b/test/files/pos/clsrefine.scala @@ -15,7 +15,7 @@ trait B extends A { def g() = f(y1, this); } -module test { +object test { val b: B { type Y = Int } = new B { type Y = Int; val y1 = 1, y2 = 1; diff --git a/test/files/pos/cours1.scala b/test/files/pos/cours1.scala index 48b5f6504d..2dc3ac6238 100644 --- a/test/files/pos/cours1.scala +++ b/test/files/pos/cours1.scala @@ -1,4 +1,4 @@ -module test { +object test { def size = 2; def pi = 3.14159; diff --git a/test/files/pos/cours2.scala b/test/files/pos/cours2.scala index 032531b25e..c96f588791 100644 --- a/test/files/pos/cours2.scala +++ b/test/files/pos/cours2.scala @@ -1,4 +1,4 @@ -module m1 { +object m1 { def id(x: Int): Double = x; def cube(x: Int): Double = x * x * x; @@ -18,7 +18,7 @@ module m1 { } -module m2 { +object m2 { def id(x: Int): Double = x; def cube(x: Int): Double = x * x * x; @@ -33,7 +33,7 @@ module m2 { def sumReciprocals(a: Int, b: Int): Double = sum(reciprocal, a, b); } -module m3 { +object m3 { def sum(f: Int => Double, a: Int, b: Int): Double = if (a > b) 0 @@ -44,7 +44,7 @@ module m3 { def sumReciprocals(a: Int, b: Int): Double = sum((x => 1.0/x), a, b); } -module m4 { +object m4 { def sum(f: Int => Double) = { def sumF(a: Int, b: Int): Double = @@ -60,7 +60,7 @@ module m4 { sumCubes(1, 10) + sumReciprocals(10, 20); } -module m5 { +object m5 { def sum(f: Int => Double): (Int, Int) => Double = (a, b) => if (a > b) 0 @@ -73,7 +73,7 @@ module m5 { sumCubes(1, 10) + sumReciprocals(10, 20); } -module m6 { +object m6 { def sum(f: Int => Double)(a: Int, b: Int): Double = if (a > b) 0 @@ -86,7 +86,7 @@ module m6 { sumCubes(1, 10) + sumReciprocals(10, 20); } -module m7 { +object m7 { def sum(f: Int => Double)(a: Int, b: Int): Double = { def iter(a: Int, result: Double): Double = @@ -102,7 +102,7 @@ module m7 { sumCubes(1, 10) + sumReciprocals(10, 20); } -module m8 { +object m8 { def product(f: Int => Double)(a: Int, step: Int, b: Int): Double = if (a > b) 1 @@ -111,7 +111,7 @@ module m8 { val pi = 8 * product(x => x * x)(4, 2, 40) / product(x => x * x)(3, 2, 40); } -module m9 { +object m9 { def accumulate[t](combiner: (t, t) => t, nullValue: t, f: Int => t, next: Int => Int) (a: Int, b: Int): t = diff --git a/test/files/pos/cours2a.scala b/test/files/pos/cours2a.scala index b888b88a96..9afa703cd7 100644 --- a/test/files/pos/cours2a.scala +++ b/test/files/pos/cours2a.scala @@ -1,10 +1,10 @@ -module m1 { +object m1 { def factorial(n: Int): Int = if (n == 0) 1 else n * factorial(n-1); } -module m2 { +object m2 { def factorial(n: Int): Int = { def factIter(n: Int, acc: Int): Int = { diff --git a/test/files/pos/cours2b.scala b/test/files/pos/cours2b.scala index edac3ed483..aea7029656 100644 --- a/test/files/pos/cours2b.scala +++ b/test/files/pos/cours2b.scala @@ -1,4 +1,4 @@ -module m1 { +object m1 { def gcd(x: Int, y: Int): Int = if (y == 0) x diff --git a/test/files/pos/cours2c.scala b/test/files/pos/cours2c.scala index c2e4b221d5..776469e1bb 100644 --- a/test/files/pos/cours2c.scala +++ b/test/files/pos/cours2c.scala @@ -1,4 +1,4 @@ -module m1 { +object m1 { def average(x: Double, y: Double) = (x + y)/2; def abs(x: Double): Double = if (x < 0) - x else x; @@ -25,7 +25,7 @@ module m1 { } } -module m2 { +object m2 { def abs(x: Double): Double = if (x < 0) - x else x; def isCloseEnough(x: Double, y: Double) = abs((x - y) / x) < 0.001; diff --git a/test/files/pos/eta.scala b/test/files/pos/eta.scala index 67e6c0f080..7d862f67b1 100644 --- a/test/files/pos/eta.scala +++ b/test/files/pos/eta.scala @@ -1,4 +1,4 @@ -module test { +object test { def sum(f: Int => Int)(x: Int, y: Int): Int = 0; def g = sum; diff --git a/test/files/pos/exceptions.scala b/test/files/pos/exceptions.scala index 4c7ffa35c8..7c376f3aac 100644 --- a/test/files/pos/exceptions.scala +++ b/test/files/pos/exceptions.scala @@ -1,6 +1,6 @@ import java.io._; -module test { +object test { //def error[a](x: String):a = new java.lang.RuntimeException(x) throw; diff --git a/test/files/pos/imports.scala b/test/files/pos/imports.scala index f13a3a4368..32b7aace62 100644 --- a/test/files/pos/imports.scala +++ b/test/files/pos/imports.scala @@ -4,7 +4,7 @@ package test; import java.lang.{System => S} -module test { +object test { import S.out.{print => p, println => print} val foo = 1; @@ -12,7 +12,7 @@ module test { p("hello"); print("world"); S.out.println("!"); S.out.flush(); } -module test1 { +object test1 { import test._; foo }
\ No newline at end of file diff --git a/test/files/pos/lambda.scala b/test/files/pos/lambda.scala index 27c273cc3c..187b3f9783 100644 --- a/test/files/pos/lambda.scala +++ b/test/files/pos/lambda.scala @@ -1,4 +1,4 @@ -module test { +object test { def apply[a,b](f: a => b): a => b = x: a => f(x); diff --git a/test/files/pos/lambdalift.scala b/test/files/pos/lambdalift.scala index f780b8e13f..ae5799a6f8 100644 --- a/test/files/pos/lambdalift.scala +++ b/test/files/pos/lambdalift.scala @@ -1,6 +1,6 @@ import scala._; -module test { +object test { def f(x: Int) = { def g() = h(); diff --git a/test/files/pos/lambdalift1.scala b/test/files/pos/lambdalift1.scala index e4c7b3a801..d9172f51eb 100644 --- a/test/files/pos/lambdalift1.scala +++ b/test/files/pos/lambdalift1.scala @@ -1,6 +1,6 @@ import scala._; -module test { +object test { def f[a <: java.lang.Object](x: a) = { def print() = java.lang.System.out.println(x); diff --git a/test/files/pos/localmodules.scala b/test/files/pos/localmodules.scala new file mode 100644 index 0000000000..8ed34f455a --- /dev/null +++ b/test/files/pos/localmodules.scala @@ -0,0 +1,22 @@ +package test; + +object main { + + class a { + + object b { + + trait c {} + def foo(x: c): c = { System.out.println("foo(" + x + ")"); x } + + } + + def bar(x: b.c): a.this.b.c = { b.foo(x); x } + } + + def main(args: Array[String]) = { + val aa = new a; + val xx: aa.b.c = null; + System.out.println(aa.bar(xx)); + } +} diff --git a/test/files/pos/matthias1.scala b/test/files/pos/matthias1.scala index 418c2f32be..a923a529fe 100644 --- a/test/files/pos/matthias1.scala +++ b/test/files/pos/matthias1.scala @@ -3,7 +3,7 @@ class A() { def foo(x: B) = 0 } } -module test { +object test { def main = { val a = new A(); val b = new a.B(); diff --git a/test/files/pos/matthias4.scala b/test/files/pos/matthias4.scala index 751c8b1c88..32200cccd1 100644 --- a/test/files/pos/matthias4.scala +++ b/test/files/pos/matthias4.scala @@ -1,19 +1,19 @@ /* -module A requires B { +object A requires B { B.X getX() { return B.getX(); } void setX(B.X x) {} } -module B { +object B { class X {} X getX() { return new X(); } void setX(X x) {} } -module C requires B { - module A; +object C requires B { + object A; void test() { A.setX(B.getX()); } @@ -23,8 +23,8 @@ module C requires B { trait _a extends Object with _b { val a: _a; val A: A; - type A <: a.AModule; - trait AModule { + type A <: a.AObject; + trait AObject { def getX(): B.X; def setX(x: B.X): Unit; } @@ -32,7 +32,7 @@ trait _a extends Object with _b { abstract class a() extends Object with _a with _b { val a: this.type = this; val A: A = new A(); - class A() extends AModule { + class A() extends AObject { def getX(): B.X = B.getX(); def setX(x: B.X) = B.setX(x); } @@ -41,8 +41,8 @@ abstract class a() extends Object with _a with _b { trait _b { val b: _b; val B: B; - type B <: b.BModule; - trait BModule { + type B <: b.BObject; + trait BObject { type X; def getX(): X; def setX(x: X): Unit; @@ -51,7 +51,7 @@ trait _b { abstract class b() extends Object with _b { val b: this.type = this; val B: B = new B(); - class B() extends BModule { + class B() extends BObject { class X() {} def getX(): X = new X(); def setX(x: X) = (); @@ -61,13 +61,13 @@ abstract class b() extends Object with _b { trait _m { val m: _m; val M: M; - type M <: m.MModule; - trait MModule {} + type M <: m.MObject; + trait MObject {} } abstract class m() extends Object with _m with _b { val m: this.type = this; val M: M = new M(); - class M() extends MModule with a() with Linker() { + class M() extends MObject with a() with Linker() { def test() = { val x: B.X = B.getX(); A.setX(x); diff --git a/test/files/pos/maxim1.scala b/test/files/pos/maxim1.scala index 01a7c05e9a..58916beb8a 100644 --- a/test/files/pos/maxim1.scala +++ b/test/files/pos/maxim1.scala @@ -1,4 +1,4 @@ -module test { +object test { def f(x: Int)(y: Int) = x + y; def y: Int => Int = f(2); def main = y(1); diff --git a/test/files/pos/modules.scala b/test/files/pos/modules.scala index d916d7fd60..8168a42d3c 100644 --- a/test/files/pos/modules.scala +++ b/test/files/pos/modules.scala @@ -1,8 +1,8 @@ package scala { - module a { + object a { - module b { + object b { trait c {} def foo(x: c): c = bar(x) diff --git a/test/files/pos/modules1.scala b/test/files/pos/modules1.scala index 71c4bf8bd4..3da14af4fe 100644 --- a/test/files/pos/modules1.scala +++ b/test/files/pos/modules1.scala @@ -1,14 +1,14 @@ package scala { - module a { + object a { - module b { + object b { trait c {} def foo(x: c): c = bar(x) } - def bar(x: b.c): a.b.c = x + def bar(x: b.c): a.b.c = { b.foo(x); x } } } diff --git a/test/files/pos/moduletrans.scala b/test/files/pos/moduletrans.scala index 953ce4ee6c..51538417ed 100644 --- a/test/files/pos/moduletrans.scala +++ b/test/files/pos/moduletrans.scala @@ -1,4 +1,4 @@ -module m1 { +object m1 { class m() { def f() = 5 diff --git a/test/files/pos/null.scala b/test/files/pos/null.scala index 54a2c0f995..59f88ee0e0 100644 --- a/test/files/pos/null.scala +++ b/test/files/pos/null.scala @@ -1,3 +1,3 @@ -module M { +object M { val x: Boolean = null == null; }
\ No newline at end of file diff --git a/test/files/pos/partialfun.scala b/test/files/pos/partialfun.scala index 1f27d099e4..e6af633811 100644 --- a/test/files/pos/partialfun.scala +++ b/test/files/pos/partialfun.scala @@ -1,4 +1,4 @@ -module partialfun { +object partialfun { def applyPartial[b](f: PartialFunction[Option[String], b])(x: Option[String]) = if (f.isDefinedAt(x)) f(x) else "<undefined>"; diff --git a/test/files/pos/patterns.scala b/test/files/pos/patterns.scala index 18ffec5025..48c068c618 100644 --- a/test/files/pos/patterns.scala +++ b/test/files/pos/patterns.scala @@ -2,7 +2,7 @@ trait Option[a] {} case class Some[a](x: a) extends Option[a]; case class None[a] extends Option[a]; -module test { +object test { def println(str: String): Unit = java.lang.System.out.println(str); diff --git a/test/files/pos/patterns2.scala b/test/files/pos/patterns2.scala index 023aaf44af..dab73a98fc 100644 --- a/test/files/pos/patterns2.scala +++ b/test/files/pos/patterns2.scala @@ -3,7 +3,7 @@ case class Choice(a: Option, b: Option) extends Option; case class Some(x: java.lang.String) extends Option; case class None extends Option; -module test { +object test { def f(opt: Option) = opt match { case Choice(Some("one"), Some(x)) => 1; diff --git a/test/files/pos/philippe1.scala b/test/files/pos/philippe1.scala index d079c5974a..3cace0e116 100644 --- a/test/files/pos/philippe1.scala +++ b/test/files/pos/philippe1.scala @@ -1,4 +1,4 @@ -module test { +object test { def id[a](xs: Array[a]): Array[a] = xs; def main(args: Array[String]): Unit = { diff --git a/test/files/pos/philippe3.scala b/test/files/pos/philippe3.scala index d99ec41f52..9442583997 100644 --- a/test/files/pos/philippe3.scala +++ b/test/files/pos/philippe3.scala @@ -29,12 +29,12 @@ case class D6() extends C() {} case class D7() extends C() with U; case class D8() extends C() with U {} -module M1; -module M2 {} -module M5 extends C(); -module M6 extends C() {} -module M7 extends C() with U; -module M8 extends C() with U {} +object M1; +object M2 {} +object M5 extends C(); +object M6 extends C() {} +object M7 extends C() with U; +object M8 extends C() with U {} diff --git a/test/files/pos/reftest.scala b/test/files/pos/reftest.scala index 27083bd2cc..f709f70897 100644 --- a/test/files/pos/reftest.scala +++ b/test/files/pos/reftest.scala @@ -1,4 +1,4 @@ import scala._; -module test { +object test { val x: Ref[Int] = new Ref(1); }
\ No newline at end of file diff --git a/test/files/pos/sort1.scala b/test/files/pos/sort1.scala index 0a75a87272..c2895fe535 100644 --- a/test/files/pos/sort1.scala +++ b/test/files/pos/sort1.scala @@ -1,4 +1,4 @@ -module test { +object test { type String = java.lang.String; diff --git a/test/files/pos/sqrt.scala b/test/files/pos/sqrt.scala index f6a53824b4..5ad1718619 100644 --- a/test/files/pos/sqrt.scala +++ b/test/files/pos/sqrt.scala @@ -1,4 +1,4 @@ -module test { +object test { def abs(x: Double) = if (x >= 0) x else 0 - x; diff --git a/test/files/pos/strings.scala b/test/files/pos/strings.scala index 75bf23f5e3..3bf40e3dda 100644 --- a/test/files/pos/strings.scala +++ b/test/files/pos/strings.scala @@ -1,5 +1,5 @@ // martin 1-3-2002: it seems there is a problem with the way Serializable is loaded. -module test { +object test { def f() = "hello".concat("world"); diff --git a/test/files/pos/test1.scala b/test/files/pos/test1.scala index 6e8e4f98a7..a36d2436ec 100644 --- a/test/files/pos/test1.scala +++ b/test/files/pos/test1.scala @@ -1,4 +1,4 @@ -module test { +object test { def f() = 5; diff --git a/test/files/pos/test2.scala b/test/files/pos/test2.scala index 4c73e0a10b..fe36d07f1b 100644 --- a/test/files/pos/test2.scala +++ b/test/files/pos/test2.scala @@ -1,5 +1,5 @@ import scala._; -module test2 { +object test2 { def f(x: Int): Int = 'a'; def g(x: Int) = f(f(x)); }
\ No newline at end of file diff --git a/test/files/pos/test4.scala b/test/files/pos/test4.scala index 0bbb6f97a0..48949b7a7f 100644 --- a/test/files/pos/test4.scala +++ b/test/files/pos/test4.scala @@ -2,7 +2,7 @@ trait C {} trait D {} trait E {} -module test { +object test { def c: C = c; def d: D = d; def e: E = e; @@ -22,7 +22,7 @@ class O[X]() { val j:I[X] = null; } -module o extends O[C]() { +object o extends O[C]() { def main = { val s: S = null; diff --git a/test/files/pos/test4a.scala b/test/files/pos/test4a.scala index 0d653c5012..ada0ba4e5f 100644 --- a/test/files/pos/test4a.scala +++ b/test/files/pos/test4a.scala @@ -7,7 +7,7 @@ class O[X]() { val j:I[X] = null; } -module o extends O[C]() { +object o extends O[C]() { def c: C = c; def main = { o.j.foo(c); diff --git a/test/files/pos/test4refine.scala b/test/files/pos/test4refine.scala index ad68bc891a..6710962934 100644 --- a/test/files/pos/test4refine.scala +++ b/test/files/pos/test4refine.scala @@ -2,7 +2,7 @@ trait C {} trait D {} trait E {} -module test { +object test { def c: C = c; def d: D = d; def e: E = e; @@ -25,7 +25,7 @@ abstract class O() { val j:I { type Y = X } = null; } -module o extends O() { +object o extends O() { type X = C; def main = { diff --git a/test/files/pos/test5.scala b/test/files/pos/test5.scala index 08f91650da..bc3a17c9be 100644 --- a/test/files/pos/test5.scala +++ b/test/files/pos/test5.scala @@ -1,6 +1,6 @@ import scala._; -module test { +object test { trait F[If] {} diff --git a/test/files/pos/test5refine.scala b/test/files/pos/test5refine.scala index 7efbf5a3f1..95670faa05 100644 --- a/test/files/pos/test5refine.scala +++ b/test/files/pos/test5refine.scala @@ -1,6 +1,6 @@ import scala._; -module test { +object test { abstract trait F { type If; } diff --git a/test/files/pos/valdefs.scala b/test/files/pos/valdefs.scala index b05edbf7b2..f9150ea509 100644 --- a/test/files/pos/valdefs.scala +++ b/test/files/pos/valdefs.scala @@ -1,4 +1,4 @@ -module test { +object test { abstract class Base() { val x: String; diff --git a/test/files/pos/vincent.scala b/test/files/pos/vincent.scala new file mode 100644 index 0000000000..eed25eb84c --- /dev/null +++ b/test/files/pos/vincent.scala @@ -0,0 +1,21 @@ +object test { + + trait A { type T; } + + trait B { type T; } + + /** def functor(x: A): B { type T = x.T } */ + abstract class functor() { + val arg: A; + val res: B { type T = arg.T } = + new B { type T = arg.T; }; + } + + val a = new A { type T = String }; + /** val b: B { type T = String } = functor(a) */ + val b: B { type T = String } = { + val tmp = new functor() { val arg = a }; + tmp.res + } + +} diff --git a/test/files/run/Course-2002-01.scala b/test/files/run/Course-2002-01.scala index 33b8e2246c..11d29540af 100644 --- a/test/files/run/Course-2002-01.scala +++ b/test/files/run/Course-2002-01.scala @@ -3,7 +3,7 @@ //############################################################################ // $Id$ -module M0 { +object M0 { //########################################################################## @@ -118,7 +118,7 @@ module M0 { //############################################################################ -module M1 { +object M1 { def abs(x: Double) = if (x >= 0) x else -x; def sqrt(x: Double): Double = { @@ -139,7 +139,7 @@ module M1 { //############################################################################ -module M2 { +object M2 { def abs(x: Double) = if (x >= 0) x else -x; def sqrt(x:Double):Double = { @@ -161,7 +161,7 @@ module M2 { //############################################################################ -module M3 { +object M3 { def abs(x: Double) = if (x >= 0) x else -x; def cbrt(x:Double):Double = { @@ -183,7 +183,7 @@ module M3 { //############################################################################ -module M4 { +object M4 { def pascal(c: Int, l: Int): Int = if (c <= 0 || c >= l) 1 else pascal(c - 1, l - 1) + pascal(c, l - 1); @@ -226,7 +226,7 @@ module M4 { //############################################################################ -module Test { +object Test { def main(args: Array[String]): Unit = { M0; M1; diff --git a/test/files/run/Course-2002-02.scala b/test/files/run/Course-2002-02.scala index a39921b45b..6c78249586 100644 --- a/test/files/run/Course-2002-02.scala +++ b/test/files/run/Course-2002-02.scala @@ -3,7 +3,7 @@ //############################################################################ // $Id$ -module M0 { +object M0 { def gcd(a: Int, b: Int): Int = if (b == 0) a else gcd(b, a % b); def factorial(n: Int): Int = if (n == 0) 1 else n * factorial(n - 1); @@ -14,7 +14,7 @@ module M0 { //############################################################################ -module M1 { +object M1 { def cube(x: Int): Double = x * x * x; def sumInts(a: Int, b: Int): Double = @@ -47,7 +47,7 @@ module M1 { //############################################################################ -module M2 { +object M2 { def id(x: Int): Double = x; def cube(x: Int): Double = x * x * x; def reciprocal(x: Int): Double = 1.0/x; @@ -74,7 +74,7 @@ module M2 { //############################################################################ -module M3 { +object M3 { def sum(f: Int => Double, a: Int, b: Int): Double = if (a > b) 0 else f(a) + sum(f, a + 1, b); @@ -94,7 +94,7 @@ module M3 { //############################################################################ -module M4 { +object M4 { def sum(f: Int => Double) = { def sumF(a: Int, b: Int): Double = if (a > b) 0 @@ -117,7 +117,7 @@ module M4 { //############################################################################ -module M5 { +object M5 { def sum(f: Int => Double): (Int, Int) => Double = { (a, b) => if (a > b) 0 else f(a) + sum(f)(a + 1, b) @@ -138,7 +138,7 @@ module M5 { //############################################################################ -module M6 { +object M6 { def sum(f: Int => Double)(a: Int, b: Int): Double = if (a > b) 0 else f(a) + sum(f)(a + 1, b); @@ -158,7 +158,7 @@ module M6 { //############################################################################ -module M7 { +object M7 { def sum(f: Int => Double)(a: Int, b: Int): Double = { def iter(a: Int, result: Double): Double = if (a > b) result @@ -181,7 +181,7 @@ module M7 { //############################################################################ -module M8 { +object M8 { def product(f: Int => Double)(a: Int, step: Int, b: Int): Double = if (a > b) 1 else f(a) * product(f)(a + step, step, b); @@ -197,7 +197,7 @@ module M8 { //############################################################################ -module M9 { +object M9 { def accumulate[t](combiner: (t, t) => t, nullValue: t, f: Int => t, next: Int => Int) (a: Int, b: Int): t = if (a > b) nullValue @@ -231,7 +231,7 @@ module M9 { //############################################################################ -module MA { +object MA { val tolerance = 0.0001; def abs(x: Double) = if (x < 0) -x else x; def isCloseEnough(x: Double, y: Double) = abs((x - y) / x) < tolerance; @@ -252,7 +252,7 @@ module MA { //############################################################################ -module MB { +object MB { val tolerance = 0.0001; def abs(x: Double) = if (x < 0) -x else x; def isCloseEnough(x: Double, y: Double) = abs((x - y) / x) < tolerance; @@ -274,7 +274,7 @@ module MB { //############################################################################ -module MC { +object MC { def sum(f: Int => Double)(a: Int, b: Int): Double = { def iter(a: Int, result: Double): Double = { if (a > b) result @@ -322,7 +322,7 @@ module MC { //############################################################################ -module MD { +object MD { def reduce(op: (Double,Double) => Double, zero:Double) (f: Int => Double)(a: Int,b: Int): Double = { def iter(a: Int, result: Double): Double = { @@ -366,7 +366,7 @@ module MD { //############################################################################ -module ME { +object ME { def reduce(op: (Double,Double) => Double, zero:Double) (f: Int => Double)(a: Int,b: Int): Double = { def iter(a: Int, result: Double): Double = { @@ -410,7 +410,7 @@ module ME { //############################################################################ -module MF { +object MF { def fib(x: Int): Int = if (x <= 1) x else fib(x - 2) + fib(x - 1); @@ -429,7 +429,7 @@ module MF { //############################################################################ -module MG { +object MG { def fib(x: Int) = { def loop(n: Int, prev: Int, fibn: Int): Int = if (n == x) fibn @@ -451,7 +451,7 @@ module MG { //############################################################################ -module MH { +object MH { def power(x: Double, y: Int): Double = if (y <= 0) 1 else if (y % 2 == 0) power(x * x, y / 2) @@ -527,7 +527,7 @@ module MH { //############################################################################ -module Test { +object Test { def main(args: Array[String]): Unit = { M0; M1; diff --git a/test/files/run/Course-2002-03.scala b/test/files/run/Course-2002-03.scala index a4efd7ffa6..a2678544e4 100644 --- a/test/files/run/Course-2002-03.scala +++ b/test/files/run/Course-2002-03.scala @@ -3,7 +3,7 @@ //############################################################################ // $Id$ -module M0 { +object M0 { class Rational(x: Int, y: Int) { def numer = x; def denom = y; @@ -28,7 +28,7 @@ module M0 { //############################################################################ -module M1 { +object M1 { class Rational(x: Int, y: Int) { def numer = x; def denom = y; @@ -55,7 +55,7 @@ module M1 { //############################################################################ -module M2 { +object M2 { class Rational(x: Int, y: Int) { private def gcd(a: Int, b: Int): Int = if (b == 0) a else gcd(b, a % b); private val g = gcd(x, y); @@ -92,7 +92,7 @@ module M2 { //############################################################################ -module M3 { +object M3 { class Rational(x: Int, y: Int) { private def gcd(a: Int, b: Int): Int = if (b == 0) a else gcd(b, a % b); def numer = x / gcd(x, y); @@ -114,7 +114,7 @@ module M3 { //############################################################################ -module M4 { +object M4 { class Rational(x: Int, y: Int) { private def gcd(a: Int, b: Int): Int = if (b == 0) a else gcd(b, a % b); private val g = gcd(x, y); @@ -147,7 +147,7 @@ module M4 { //############################################################################ -module M5 { +object M5 { trait IntSet { def incl(x: Int): IntSet; def contains(x: Int): Boolean; @@ -179,7 +179,7 @@ module M5 { //############################################################################ -module M6 { +object M6 { trait Boolean { def ifThenElse[a](def t: a)(def e: a): a; @@ -195,15 +195,15 @@ module M6 { def <= (x: Boolean): Boolean = ifThenElse[Boolean](x)(new True()); def >= (x: Boolean): Boolean = ifThenElse[Boolean](new True())(x.!); } - class True() extends Boolean { // !!! class -> module + class True() extends Boolean { // !!! class -> object def ifThenElse[a](def t: a)(def e: a): a = t } - class False() extends Boolean { // !!! class -> module + class False() extends Boolean { // !!! class -> object def ifThenElse[a](def t: a)(def e: a): a = e } } //############################################################################ -module M7 { +object M7 { trait Nat { def isZero(): Boolean; def predecessor: Nat; @@ -215,7 +215,7 @@ module M7 { //############################################################################ -module M8 { +object M8 { trait IntSet { def incl(x: Int): IntSet; @@ -244,7 +244,7 @@ module M8 { } } - class Empty extends IntSet { // !!! class Empty() -> module Empty + class Empty extends IntSet { // !!! class Empty() -> object Empty def contains(x: Int): Boolean = false; def incl(x: Int): IntSet = new NonEmpty(x, new Empty, new Empty); def map(f: Int => Int): IntSet = this; @@ -337,7 +337,7 @@ module M8 { //############################################################################ -module M9 { +object M9 { class Rational(x: Int, y: Int) { private def gcd(a: Int, b: Int): Int = if (b == 0) a else gcd(b, a % b); private val g = gcd(x, y); @@ -373,7 +373,7 @@ module M9 { //############################################################################ -module Test { +object Test { def main(args: Array[String]): Unit = { M0; M1; diff --git a/test/files/run/Course-2002-04.scala b/test/files/run/Course-2002-04.scala index 541dc2ac67..61deb96a11 100644 --- a/test/files/run/Course-2002-04.scala +++ b/test/files/run/Course-2002-04.scala @@ -3,7 +3,7 @@ //############################################################################ // $Id$ -module M0 { +object M0 { def quicksort[a] (less : (a,a) => Boolean) (xs : List[a]) : List[a] = { if (xs.isEmpty) @@ -41,7 +41,7 @@ module M0 { //############################################################################ -module M1 { +object M1 { def horner (x : Double, coefs : List[Double]) : Double = { if (coefs.isEmpty) @@ -63,7 +63,7 @@ module M1 { //############################################################################ -module M2 { +object M2 { def dotproduct (v : List[Double], w : List[Double]) : Double = { if (v.isEmpty) @@ -149,7 +149,7 @@ module M2 { //############################################################################ -module Test { +object Test { def main(args: Array[String]): Unit = { M0.test; M1.test; diff --git a/test/files/run/Course-2002-06.scala b/test/files/run/Course-2002-06.scala index d9190d35b5..d044d778d6 100644 --- a/test/files/run/Course-2002-06.scala +++ b/test/files/run/Course-2002-06.scala @@ -145,7 +145,7 @@ class PostScript (filename: String, _width: Double, _height: Double) //############################################################################ -module M0 { +object M0 { /** Define the type of a painter as a function that takes a frame, * draws itself onto it and returns nothing @@ -254,7 +254,7 @@ module M0 { //############################################################################ -module Test { +object Test { def main(args: Array[String]): Unit = { M0.test; () diff --git a/test/files/run/Course-2002-07.scala b/test/files/run/Course-2002-07.scala index 3d1f21b209..2a45805138 100644 --- a/test/files/run/Course-2002-07.scala +++ b/test/files/run/Course-2002-07.scala @@ -3,7 +3,7 @@ //############################################################################ // $Id$ -module M0 { +object M0 { trait Expr { def isNumber: boolean; @@ -66,7 +66,7 @@ module M0 { //############################################################################ -module M1 { +object M1 { trait Expr { def eval: int; @@ -93,7 +93,7 @@ module M1 { //############################################################################ -module M2 { +object M2 { trait Expr; case class Number(n: int) extends Expr; @@ -117,7 +117,7 @@ module M2 { //############################################################################ -module M3 { +object M3 { trait Expr { def eval: int = this match { @@ -142,7 +142,7 @@ module M3 { //############################################################################ -module M4 { +object M4 { def concat[a](xss: List[List[a]]): List[a] = xss match { case List() => List() @@ -180,7 +180,7 @@ module M4 { //############################################################################ -module M5 { +object M5 { def zipFun[a,b](xs:List[a], ys:List[b]):List[Pair[a,b]] = Pair(xs,ys) match { case Pair(List(), _) => List() @@ -215,7 +215,7 @@ module M5 { //############################################################################ -module M6 { +object M6 { def zipFun[a,b](xs:List[a], ys:List[b]):List[Pair[a,b]] = Pair(xs,ys) match { // !!! case Pair(List(), _), Pair(_, List()) => List() @@ -248,7 +248,7 @@ module M6 { //############################################################################ -module M7 { +object M7 { def heads[a](xss: List[List[a]]): List[a] = xss flatMap { case x :: xs => List(x) @@ -292,7 +292,7 @@ module M7 { //############################################################################ -module M8 { +object M8 { def heads[a](xss: List[List[a]]): List[a] = xss.flatMap { y => y match { @@ -338,7 +338,7 @@ module M8 { //############################################################################ -module M9 { +object M9 { trait Expr { def derive(v: Var): Expr = match { @@ -374,7 +374,7 @@ module M9 { //############################################################################ -module MA { +object MA { def lookup[k,v](xs: List[Pair[k,v]], k: k): v = xs match { case List() => error("no value for " + k) @@ -449,7 +449,7 @@ module MA { //############################################################################ -module Utils { +object Utils { private def power0(x: int, y: int): int = if (y == 1) x else if (y % 2 == 0) power0(x*x,y/2) else x*power0(x, y-1); @@ -482,7 +482,7 @@ module Utils { } -module MB { +object MB { import Utils._; @@ -703,7 +703,7 @@ module MB { //############################################################################ -module Test { +object Test { def main(args: Array[String]): unit = { M0.test; M1.test; diff --git a/test/files/run/Course-2002-08.scala b/test/files/run/Course-2002-08.scala index 9cb2bb8701..dad9426d7f 100644 --- a/test/files/run/Course-2002-08.scala +++ b/test/files/run/Course-2002-08.scala @@ -5,7 +5,7 @@ import List._; -module M0 { +object M0 { var x: String = "abc"; var count = 111; @@ -23,7 +23,7 @@ module M0 { //############################################################################ -module M1 { +object M1 { class BankAccount() { private var balance = 0; @@ -87,7 +87,7 @@ module M1 { //############################################################################ -module M2 { +object M2 { def while(def condition: Boolean)(def command: Unit): Unit = if (condition) { @@ -113,7 +113,7 @@ module M2 { //############################################################################ -module M3 { +object M3 { def power (x: Double, exp: Int): Double = { var r = 1.0; @@ -133,7 +133,7 @@ module M3 { //############################################################################ -module M4 { +object M4 { def test = { for (val i <- range(1, 4)) do { System.out.print(i + " ") }; @@ -145,7 +145,7 @@ module M4 { //############################################################################ -module M5 { +object M5 { type Action = () => Unit; @@ -579,7 +579,7 @@ class Main() extends CircuitSimulator() { //############################################################################ -module Test { +object Test { def main(args: Array[String]): Unit = { M0.test; M1.test; diff --git a/test/files/run/Course-2002-09.scala b/test/files/run/Course-2002-09.scala index 2e012fdf35..4238402263 100644 --- a/test/files/run/Course-2002-09.scala +++ b/test/files/run/Course-2002-09.scala @@ -12,7 +12,7 @@ trait Constraint { def dropValue: Unit } -module NoConstraint extends Constraint { +object NoConstraint extends Constraint { def newValue: Unit = error("NoConstraint.newValue"); def dropValue: Unit = error("NoConstraint.dropValue"); } @@ -168,7 +168,7 @@ class Quantity() { //############################################################################ -module M0 { +object M0 { def CFconverter(c: Quantity, f: Quantity) = { val u = new Quantity(); @@ -209,7 +209,7 @@ module M0 { //############################################################################ -module M1 { +object M1 { def constant(x: double): Quantity = { val q = new Quantity(); @@ -250,7 +250,7 @@ module M1 { //############################################################################ -module M2 { +object M2 { val a = new Quantity(); val b = new Quantity(); @@ -298,7 +298,7 @@ module M2 { //############################################################################ -module M3 { +object M3 { def test = { val a = new Quantity(); @@ -324,7 +324,7 @@ module M3 { //############################################################################ -module Test { +object Test { def main(args: Array[String]): Unit = { M0.test; M1.test; diff --git a/test/files/run/Course-2002-10.scala b/test/files/run/Course-2002-10.scala index aabe99ba53..9a292937ca 100644 --- a/test/files/run/Course-2002-10.scala +++ b/test/files/run/Course-2002-10.scala @@ -3,7 +3,7 @@ //############################################################################ // $Id$ -module M0 { +object M0 { def addStream (s1: Stream[int], s2: Stream[int]): Stream[int] = Stream.cons(s1.head + s2.head, addStream(s1.tail, s2.tail)); @@ -20,7 +20,7 @@ module M0 { //############################################################################ -module M1 { +object M1 { def scale(x: double, s: Stream[double]): Stream[double] = s map (e: double => e*x); @@ -92,7 +92,7 @@ module M1 { //############################################################################ -module M2 { +object M2 { class IntIterator(start: int) extends Iterator[int] { var current: int = start; @@ -120,7 +120,7 @@ module M2 { //############################################################################ -module Test { +object Test { def main(args: Array[String]): Unit = { M0.test; M1.test; diff --git a/test/files/run/Course-2002-11.scala b/test/files/run/Course-2002-11.scala index 5a257234c4..c7cae8bb53 100644 --- a/test/files/run/Course-2002-11.scala +++ b/test/files/run/Course-2002-11.scala @@ -5,7 +5,7 @@ import List._; -module Lisp { +object Lisp { trait Data { def elemsToString(): String = toString(); @@ -17,7 +17,7 @@ module Lisp { case _ => " " + cdr.elemsToString(); }) } - case class NIL() extends Data { // !!! use case module + case class NIL() extends Data { // !!! use case object override def toString() = "()"; } case class SYM(name: String) extends Data { @@ -237,7 +237,7 @@ class LispTokenizer(s: String) extends Iterator[String] { //############################################################################ -module M0 { +object M0 { def test = { import Lisp._; @@ -288,7 +288,7 @@ module M0 { //############################################################################ -module Test { +object Test { def main(args: Array[String]): Unit = { M0.test; () diff --git a/test/files/run/Course-2002-13.scala b/test/files/run/Course-2002-13.scala index 0fdb715991..ebdde8bf86 100644 --- a/test/files/run/Course-2002-13.scala +++ b/test/files/run/Course-2002-13.scala @@ -82,7 +82,7 @@ class Interpreter { } -module Terms { +object Terms { val debug = false; @@ -159,7 +159,7 @@ module Terms { import Terms._; -module Programs { +object Programs { case class Clause(lhs: Term, rhs: List[Term]) { def tyvars = @@ -262,7 +262,7 @@ class Parser(s: String) { def all: List[Clause] = if (token equals "") List() else line :: all; } -module Prolog { +object Prolog { def processor: String => Unit = { var program: List[Clause] = List(); @@ -304,7 +304,7 @@ module Prolog { //############################################################################ -module Test { +object Test { def main(args: Array[String]): Unit = { Prolog.process( "sujet(jean).\n" + diff --git a/test/files/run/misc.scala b/test/files/run/misc.scala index dd82d097cd..1468193ab6 100644 --- a/test/files/run/misc.scala +++ b/test/files/run/misc.scala @@ -1,6 +1,6 @@ // $Id$ -module Test { +object Test { def fac(n: Int): Int = if (n < 2) 1 else fac(n - 1) * n; diff --git a/test/files/run/queens.scala b/test/files/run/queens.scala index 2a705c4892..4daa702e29 100644 --- a/test/files/run/queens.scala +++ b/test/files/run/queens.scala @@ -1,6 +1,6 @@ // $Id$ -module M0 { +object M0 { type Placement = List[Int]; def range(lo: Int, hi: Int): List[Int] = @@ -41,7 +41,7 @@ module M0 { } } -module Test { +object Test { def main(args: Array[String]): Unit = { M0.test; () diff --git a/test/neg/S2.scala b/test/neg/S2.scala index 83cc1829a3..47687a916a 100644 --- a/test/neg/S2.scala +++ b/test/neg/S2.scala @@ -7,7 +7,7 @@ ** def t = foo(x, y); ** ^ */ -module M { +object M { def foo[T](x: T, y: T): T = x; class S2() { class Inner() extends S2() {} diff --git a/test/neg/altherr1.scala b/test/neg/altherr1.scala index 69443bfd06..9eb0cc9987 100644 --- a/test/neg/altherr1.scala +++ b/test/neg/altherr1.scala @@ -1,6 +1,6 @@ case class Foo[a](); -module Bug { +object Bug { def foo[a](): Foo[a] = foo[a](); foo() match { case _ => 0 } } diff --git a/test/neg/altherr2.scala b/test/neg/altherr2.scala index 41bcffca36..6ab26526f7 100644 --- a/test/neg/altherr2.scala +++ b/test/neg/altherr2.scala @@ -1,6 +1,6 @@ trait Foo[a]; -module Bug { +object Bug { def foo[a](): Foo[a] = foo[a](); foo()[Int]; } diff --git a/test/neg/altherr3.scala b/test/neg/altherr3.scala index bb40099e1e..a96513e832 100644 --- a/test/neg/altherr3.scala +++ b/test/neg/altherr3.scala @@ -1,6 +1,6 @@ // $Id$ -module bug { +object bug { //########################################################################## diff --git a/test/neg/vincent1.scala b/test/neg/vincent1.scala index 53104be640..6082b271b3 100644 --- a/test/neg/vincent1.scala +++ b/test/neg/vincent1.scala @@ -1,4 +1,4 @@ -module test { +object test { trait A { type T; } diff --git a/test/pos/A.scala b/test/pos/A.scala index 2f7c958ae2..513c8bed45 100644 --- a/test/pos/A.scala +++ b/test/pos/A.scala @@ -1,6 +1,6 @@ trait A extends scala.Object {} -module test { +object test { def x: A = x; diff --git a/test/pos/IntSet.scala b/test/pos/IntSet.scala index cfffc88944..639a099d9a 100644 --- a/test/pos/IntSet.scala +++ b/test/pos/IntSet.scala @@ -4,8 +4,8 @@ trait IntSet { def foreach(f: Int => Unit): Unit; def union(that: IntSet): IntSet; } -module Empty extends IntSet { - def contains(x: Int): Boolean = false; +object Empty extends IntSet { + def contains(x: Int): Boolean = Boolean.False; def incl(x: Int): IntSet = new NonEmpty(x, Empty, Empty); def foreach(f: Int => Unit): Unit = (); def union(that: IntSet): IntSet = that; @@ -26,7 +26,7 @@ class NonEmpty(elem: Int, left: IntSet, right: IntSet) extends IntSet { } def union(that: IntSet): IntSet = (left union (right union that)) incl elem; } -module test { +object test { def main = { val x = Empty incl 1 incl 2; val y = Empty incl 2 incl 3; diff --git a/test/pos/List1.scala b/test/pos/List1.scala index fcc506bccc..6c54f109ce 100644 --- a/test/pos/List1.scala +++ b/test/pos/List1.scala @@ -1,4 +1,4 @@ -module lists { +object lists { trait List[a] { def isEmpty: Boolean; diff --git a/test/pos/S5.scala b/test/pos/S5.scala index 87325b47e4..08f5b2a6eb 100644 --- a/test/pos/S5.scala +++ b/test/pos/S5.scala @@ -25,6 +25,6 @@ abstract class N() { // module body of N } } -module O { +object O { val system = new M() with N() {} } diff --git a/test/pos/S8.scala b/test/pos/S8.scala index e4339bb3f1..50f1df27a2 100644 --- a/test/pos/S8.scala +++ b/test/pos/S8.scala @@ -13,7 +13,7 @@ class S8() { class A() extends a.B() {} class B() {} } -module M { +object M { val x = new S8(); val y: x.a.B = new x.A(); //correct? } diff --git a/test/pos/Y.scala b/test/pos/Y.scala index 425d7fb346..ebef6f9e36 100644 --- a/test/pos/Y.scala +++ b/test/pos/Y.scala @@ -1,4 +1,4 @@ -module test { +object test { def f(x: Object): Object = x.match; diff --git a/test/pos/Z.scala b/test/pos/Z.scala index c19081e68c..c1367e46b9 100644 --- a/test/pos/Z.scala +++ b/test/pos/Z.scala @@ -2,7 +2,7 @@ trait X { val elem: Int = 1 } -module test { +object test { def g(x: X) = x.elem; def f(x: Object) = x.toString(); diff --git a/test/pos/cls.scala b/test/pos/cls.scala index 3a46c306db..54104ae692 100644 --- a/test/pos/cls.scala +++ b/test/pos/cls.scala @@ -8,7 +8,7 @@ class B[Y](y1: Y, y2: Y) extends A[Y, Y](y1, y2) { def g() = f(y1, this); } -module test { +object test { val b: B[Int] = new B[Int](1, 2); val a: A[Int, Int] = b; val a1 = new A(1, "hello"); diff --git a/test/pos/clsrefine.scala b/test/pos/clsrefine.scala index 12f5aa5246..56db9d4c13 100644 --- a/test/pos/clsrefine.scala +++ b/test/pos/clsrefine.scala @@ -15,7 +15,7 @@ trait B extends A { def g() = f(y1, this); } -module test { +object test { val b: B { type Y = Int } = new B { type Y = Int; val y1 = 1, y2 = 1; diff --git a/test/pos/cours1.scala b/test/pos/cours1.scala index 48b5f6504d..2dc3ac6238 100644 --- a/test/pos/cours1.scala +++ b/test/pos/cours1.scala @@ -1,4 +1,4 @@ -module test { +object test { def size = 2; def pi = 3.14159; diff --git a/test/pos/cours2.scala b/test/pos/cours2.scala index 032531b25e..c96f588791 100644 --- a/test/pos/cours2.scala +++ b/test/pos/cours2.scala @@ -1,4 +1,4 @@ -module m1 { +object m1 { def id(x: Int): Double = x; def cube(x: Int): Double = x * x * x; @@ -18,7 +18,7 @@ module m1 { } -module m2 { +object m2 { def id(x: Int): Double = x; def cube(x: Int): Double = x * x * x; @@ -33,7 +33,7 @@ module m2 { def sumReciprocals(a: Int, b: Int): Double = sum(reciprocal, a, b); } -module m3 { +object m3 { def sum(f: Int => Double, a: Int, b: Int): Double = if (a > b) 0 @@ -44,7 +44,7 @@ module m3 { def sumReciprocals(a: Int, b: Int): Double = sum((x => 1.0/x), a, b); } -module m4 { +object m4 { def sum(f: Int => Double) = { def sumF(a: Int, b: Int): Double = @@ -60,7 +60,7 @@ module m4 { sumCubes(1, 10) + sumReciprocals(10, 20); } -module m5 { +object m5 { def sum(f: Int => Double): (Int, Int) => Double = (a, b) => if (a > b) 0 @@ -73,7 +73,7 @@ module m5 { sumCubes(1, 10) + sumReciprocals(10, 20); } -module m6 { +object m6 { def sum(f: Int => Double)(a: Int, b: Int): Double = if (a > b) 0 @@ -86,7 +86,7 @@ module m6 { sumCubes(1, 10) + sumReciprocals(10, 20); } -module m7 { +object m7 { def sum(f: Int => Double)(a: Int, b: Int): Double = { def iter(a: Int, result: Double): Double = @@ -102,7 +102,7 @@ module m7 { sumCubes(1, 10) + sumReciprocals(10, 20); } -module m8 { +object m8 { def product(f: Int => Double)(a: Int, step: Int, b: Int): Double = if (a > b) 1 @@ -111,7 +111,7 @@ module m8 { val pi = 8 * product(x => x * x)(4, 2, 40) / product(x => x * x)(3, 2, 40); } -module m9 { +object m9 { def accumulate[t](combiner: (t, t) => t, nullValue: t, f: Int => t, next: Int => Int) (a: Int, b: Int): t = diff --git a/test/pos/cours2a.scala b/test/pos/cours2a.scala index b888b88a96..9afa703cd7 100644 --- a/test/pos/cours2a.scala +++ b/test/pos/cours2a.scala @@ -1,10 +1,10 @@ -module m1 { +object m1 { def factorial(n: Int): Int = if (n == 0) 1 else n * factorial(n-1); } -module m2 { +object m2 { def factorial(n: Int): Int = { def factIter(n: Int, acc: Int): Int = { diff --git a/test/pos/cours2b.scala b/test/pos/cours2b.scala index edac3ed483..aea7029656 100644 --- a/test/pos/cours2b.scala +++ b/test/pos/cours2b.scala @@ -1,4 +1,4 @@ -module m1 { +object m1 { def gcd(x: Int, y: Int): Int = if (y == 0) x diff --git a/test/pos/cours2c.scala b/test/pos/cours2c.scala index c2e4b221d5..776469e1bb 100644 --- a/test/pos/cours2c.scala +++ b/test/pos/cours2c.scala @@ -1,4 +1,4 @@ -module m1 { +object m1 { def average(x: Double, y: Double) = (x + y)/2; def abs(x: Double): Double = if (x < 0) - x else x; @@ -25,7 +25,7 @@ module m1 { } } -module m2 { +object m2 { def abs(x: Double): Double = if (x < 0) - x else x; def isCloseEnough(x: Double, y: Double) = abs((x - y) / x) < 0.001; diff --git a/test/pos/eta.scala b/test/pos/eta.scala index 67e6c0f080..7d862f67b1 100644 --- a/test/pos/eta.scala +++ b/test/pos/eta.scala @@ -1,4 +1,4 @@ -module test { +object test { def sum(f: Int => Int)(x: Int, y: Int): Int = 0; def g = sum; diff --git a/test/pos/exceptions.scala b/test/pos/exceptions.scala index 4c7ffa35c8..7c376f3aac 100644 --- a/test/pos/exceptions.scala +++ b/test/pos/exceptions.scala @@ -1,6 +1,6 @@ import java.io._; -module test { +object test { //def error[a](x: String):a = new java.lang.RuntimeException(x) throw; diff --git a/test/pos/imports.scala b/test/pos/imports.scala index f13a3a4368..32b7aace62 100644 --- a/test/pos/imports.scala +++ b/test/pos/imports.scala @@ -4,7 +4,7 @@ package test; import java.lang.{System => S} -module test { +object test { import S.out.{print => p, println => print} val foo = 1; @@ -12,7 +12,7 @@ module test { p("hello"); print("world"); S.out.println("!"); S.out.flush(); } -module test1 { +object test1 { import test._; foo }
\ No newline at end of file diff --git a/test/pos/lambda.scala b/test/pos/lambda.scala index 27c273cc3c..187b3f9783 100644 --- a/test/pos/lambda.scala +++ b/test/pos/lambda.scala @@ -1,4 +1,4 @@ -module test { +object test { def apply[a,b](f: a => b): a => b = x: a => f(x); diff --git a/test/pos/lambdalift.scala b/test/pos/lambdalift.scala index f780b8e13f..ae5799a6f8 100644 --- a/test/pos/lambdalift.scala +++ b/test/pos/lambdalift.scala @@ -1,6 +1,6 @@ import scala._; -module test { +object test { def f(x: Int) = { def g() = h(); diff --git a/test/pos/lambdalift1.scala b/test/pos/lambdalift1.scala index e4c7b3a801..d9172f51eb 100644 --- a/test/pos/lambdalift1.scala +++ b/test/pos/lambdalift1.scala @@ -1,6 +1,6 @@ import scala._; -module test { +object test { def f[a <: java.lang.Object](x: a) = { def print() = java.lang.System.out.println(x); diff --git a/test/pos/localmodules.scala b/test/pos/localmodules.scala new file mode 100644 index 0000000000..8ed34f455a --- /dev/null +++ b/test/pos/localmodules.scala @@ -0,0 +1,22 @@ +package test; + +object main { + + class a { + + object b { + + trait c {} + def foo(x: c): c = { System.out.println("foo(" + x + ")"); x } + + } + + def bar(x: b.c): a.this.b.c = { b.foo(x); x } + } + + def main(args: Array[String]) = { + val aa = new a; + val xx: aa.b.c = null; + System.out.println(aa.bar(xx)); + } +} diff --git a/test/pos/matthias1.scala b/test/pos/matthias1.scala index 418c2f32be..a923a529fe 100644 --- a/test/pos/matthias1.scala +++ b/test/pos/matthias1.scala @@ -3,7 +3,7 @@ class A() { def foo(x: B) = 0 } } -module test { +object test { def main = { val a = new A(); val b = new a.B(); diff --git a/test/pos/matthias4.scala b/test/pos/matthias4.scala index 751c8b1c88..32200cccd1 100644 --- a/test/pos/matthias4.scala +++ b/test/pos/matthias4.scala @@ -1,19 +1,19 @@ /* -module A requires B { +object A requires B { B.X getX() { return B.getX(); } void setX(B.X x) {} } -module B { +object B { class X {} X getX() { return new X(); } void setX(X x) {} } -module C requires B { - module A; +object C requires B { + object A; void test() { A.setX(B.getX()); } @@ -23,8 +23,8 @@ module C requires B { trait _a extends Object with _b { val a: _a; val A: A; - type A <: a.AModule; - trait AModule { + type A <: a.AObject; + trait AObject { def getX(): B.X; def setX(x: B.X): Unit; } @@ -32,7 +32,7 @@ trait _a extends Object with _b { abstract class a() extends Object with _a with _b { val a: this.type = this; val A: A = new A(); - class A() extends AModule { + class A() extends AObject { def getX(): B.X = B.getX(); def setX(x: B.X) = B.setX(x); } @@ -41,8 +41,8 @@ abstract class a() extends Object with _a with _b { trait _b { val b: _b; val B: B; - type B <: b.BModule; - trait BModule { + type B <: b.BObject; + trait BObject { type X; def getX(): X; def setX(x: X): Unit; @@ -51,7 +51,7 @@ trait _b { abstract class b() extends Object with _b { val b: this.type = this; val B: B = new B(); - class B() extends BModule { + class B() extends BObject { class X() {} def getX(): X = new X(); def setX(x: X) = (); @@ -61,13 +61,13 @@ abstract class b() extends Object with _b { trait _m { val m: _m; val M: M; - type M <: m.MModule; - trait MModule {} + type M <: m.MObject; + trait MObject {} } abstract class m() extends Object with _m with _b { val m: this.type = this; val M: M = new M(); - class M() extends MModule with a() with Linker() { + class M() extends MObject with a() with Linker() { def test() = { val x: B.X = B.getX(); A.setX(x); diff --git a/test/pos/maxim1.scala b/test/pos/maxim1.scala index 01a7c05e9a..58916beb8a 100644 --- a/test/pos/maxim1.scala +++ b/test/pos/maxim1.scala @@ -1,4 +1,4 @@ -module test { +object test { def f(x: Int)(y: Int) = x + y; def y: Int => Int = f(2); def main = y(1); diff --git a/test/pos/modules.scala b/test/pos/modules.scala index d916d7fd60..8168a42d3c 100644 --- a/test/pos/modules.scala +++ b/test/pos/modules.scala @@ -1,8 +1,8 @@ package scala { - module a { + object a { - module b { + object b { trait c {} def foo(x: c): c = bar(x) diff --git a/test/pos/modules1.scala b/test/pos/modules1.scala index 71c4bf8bd4..3da14af4fe 100644 --- a/test/pos/modules1.scala +++ b/test/pos/modules1.scala @@ -1,14 +1,14 @@ package scala { - module a { + object a { - module b { + object b { trait c {} def foo(x: c): c = bar(x) } - def bar(x: b.c): a.b.c = x + def bar(x: b.c): a.b.c = { b.foo(x); x } } } diff --git a/test/pos/moduletrans.scala b/test/pos/moduletrans.scala index 953ce4ee6c..51538417ed 100644 --- a/test/pos/moduletrans.scala +++ b/test/pos/moduletrans.scala @@ -1,4 +1,4 @@ -module m1 { +object m1 { class m() { def f() = 5 diff --git a/test/pos/null.scala b/test/pos/null.scala index 54a2c0f995..59f88ee0e0 100644 --- a/test/pos/null.scala +++ b/test/pos/null.scala @@ -1,3 +1,3 @@ -module M { +object M { val x: Boolean = null == null; }
\ No newline at end of file diff --git a/test/pos/partialfun.scala b/test/pos/partialfun.scala index 1f27d099e4..e6af633811 100644 --- a/test/pos/partialfun.scala +++ b/test/pos/partialfun.scala @@ -1,4 +1,4 @@ -module partialfun { +object partialfun { def applyPartial[b](f: PartialFunction[Option[String], b])(x: Option[String]) = if (f.isDefinedAt(x)) f(x) else "<undefined>"; diff --git a/test/pos/patterns.scala b/test/pos/patterns.scala index 18ffec5025..48c068c618 100644 --- a/test/pos/patterns.scala +++ b/test/pos/patterns.scala @@ -2,7 +2,7 @@ trait Option[a] {} case class Some[a](x: a) extends Option[a]; case class None[a] extends Option[a]; -module test { +object test { def println(str: String): Unit = java.lang.System.out.println(str); diff --git a/test/pos/patterns2.scala b/test/pos/patterns2.scala index 023aaf44af..dab73a98fc 100644 --- a/test/pos/patterns2.scala +++ b/test/pos/patterns2.scala @@ -3,7 +3,7 @@ case class Choice(a: Option, b: Option) extends Option; case class Some(x: java.lang.String) extends Option; case class None extends Option; -module test { +object test { def f(opt: Option) = opt match { case Choice(Some("one"), Some(x)) => 1; diff --git a/test/pos/philippe1.scala b/test/pos/philippe1.scala index d079c5974a..3cace0e116 100644 --- a/test/pos/philippe1.scala +++ b/test/pos/philippe1.scala @@ -1,4 +1,4 @@ -module test { +object test { def id[a](xs: Array[a]): Array[a] = xs; def main(args: Array[String]): Unit = { diff --git a/test/pos/philippe3.scala b/test/pos/philippe3.scala index d99ec41f52..9442583997 100644 --- a/test/pos/philippe3.scala +++ b/test/pos/philippe3.scala @@ -29,12 +29,12 @@ case class D6() extends C() {} case class D7() extends C() with U; case class D8() extends C() with U {} -module M1; -module M2 {} -module M5 extends C(); -module M6 extends C() {} -module M7 extends C() with U; -module M8 extends C() with U {} +object M1; +object M2 {} +object M5 extends C(); +object M6 extends C() {} +object M7 extends C() with U; +object M8 extends C() with U {} diff --git a/test/pos/reftest.scala b/test/pos/reftest.scala index 27083bd2cc..f709f70897 100644 --- a/test/pos/reftest.scala +++ b/test/pos/reftest.scala @@ -1,4 +1,4 @@ import scala._; -module test { +object test { val x: Ref[Int] = new Ref(1); }
\ No newline at end of file diff --git a/test/pos/sort1.scala b/test/pos/sort1.scala index 0a75a87272..c2895fe535 100644 --- a/test/pos/sort1.scala +++ b/test/pos/sort1.scala @@ -1,4 +1,4 @@ -module test { +object test { type String = java.lang.String; diff --git a/test/pos/sqrt.scala b/test/pos/sqrt.scala index f6a53824b4..5ad1718619 100644 --- a/test/pos/sqrt.scala +++ b/test/pos/sqrt.scala @@ -1,4 +1,4 @@ -module test { +object test { def abs(x: Double) = if (x >= 0) x else 0 - x; diff --git a/test/pos/strings.scala b/test/pos/strings.scala index 75bf23f5e3..3bf40e3dda 100644 --- a/test/pos/strings.scala +++ b/test/pos/strings.scala @@ -1,5 +1,5 @@ // martin 1-3-2002: it seems there is a problem with the way Serializable is loaded. -module test { +object test { def f() = "hello".concat("world"); diff --git a/test/pos/test1.scala b/test/pos/test1.scala index 6e8e4f98a7..a36d2436ec 100644 --- a/test/pos/test1.scala +++ b/test/pos/test1.scala @@ -1,4 +1,4 @@ -module test { +object test { def f() = 5; diff --git a/test/pos/test2.scala b/test/pos/test2.scala index 4c73e0a10b..fe36d07f1b 100644 --- a/test/pos/test2.scala +++ b/test/pos/test2.scala @@ -1,5 +1,5 @@ import scala._; -module test2 { +object test2 { def f(x: Int): Int = 'a'; def g(x: Int) = f(f(x)); }
\ No newline at end of file diff --git a/test/pos/test4.scala b/test/pos/test4.scala index 0bbb6f97a0..48949b7a7f 100644 --- a/test/pos/test4.scala +++ b/test/pos/test4.scala @@ -2,7 +2,7 @@ trait C {} trait D {} trait E {} -module test { +object test { def c: C = c; def d: D = d; def e: E = e; @@ -22,7 +22,7 @@ class O[X]() { val j:I[X] = null; } -module o extends O[C]() { +object o extends O[C]() { def main = { val s: S = null; diff --git a/test/pos/test4a.scala b/test/pos/test4a.scala index 0d653c5012..ada0ba4e5f 100644 --- a/test/pos/test4a.scala +++ b/test/pos/test4a.scala @@ -7,7 +7,7 @@ class O[X]() { val j:I[X] = null; } -module o extends O[C]() { +object o extends O[C]() { def c: C = c; def main = { o.j.foo(c); diff --git a/test/pos/test4refine.scala b/test/pos/test4refine.scala index ad68bc891a..6710962934 100644 --- a/test/pos/test4refine.scala +++ b/test/pos/test4refine.scala @@ -2,7 +2,7 @@ trait C {} trait D {} trait E {} -module test { +object test { def c: C = c; def d: D = d; def e: E = e; @@ -25,7 +25,7 @@ abstract class O() { val j:I { type Y = X } = null; } -module o extends O() { +object o extends O() { type X = C; def main = { diff --git a/test/pos/test5.scala b/test/pos/test5.scala index 08f91650da..bc3a17c9be 100644 --- a/test/pos/test5.scala +++ b/test/pos/test5.scala @@ -1,6 +1,6 @@ import scala._; -module test { +object test { trait F[If] {} diff --git a/test/pos/test5refine.scala b/test/pos/test5refine.scala index 7efbf5a3f1..95670faa05 100644 --- a/test/pos/test5refine.scala +++ b/test/pos/test5refine.scala @@ -1,6 +1,6 @@ import scala._; -module test { +object test { abstract trait F { type If; } diff --git a/test/pos/valdefs.scala b/test/pos/valdefs.scala index b05edbf7b2..f9150ea509 100644 --- a/test/pos/valdefs.scala +++ b/test/pos/valdefs.scala @@ -1,4 +1,4 @@ -module test { +object test { abstract class Base() { val x: String; diff --git a/test/pos/vincent.scala b/test/pos/vincent.scala new file mode 100644 index 0000000000..eed25eb84c --- /dev/null +++ b/test/pos/vincent.scala @@ -0,0 +1,21 @@ +object test { + + trait A { type T; } + + trait B { type T; } + + /** def functor(x: A): B { type T = x.T } */ + abstract class functor() { + val arg: A; + val res: B { type T = arg.T } = + new B { type T = arg.T; }; + } + + val a = new A { type T = String }; + /** val b: B { type T = String } = functor(a) */ + val b: B { type T = String } = { + val tmp = new functor() { val arg = a }; + tmp.res + } + +} |