summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2007-06-19 12:03:24 +0000
committerMartin Odersky <odersky@gmail.com>2007-06-19 12:03:24 +0000
commit6d5979b71423b55121c582786e5d052c1419ac41 (patch)
treefd28e2bd4d046afe413b65caef82ab8e07c2a6fb
parent9867746f9a849170725c87a591eb3f10ab9f7c09 (diff)
downloadscala-6d5979b71423b55121c582786e5d052c1419ac41.tar.gz
scala-6d5979b71423b55121c582786e5d052c1419ac41.tar.bz2
scala-6d5979b71423b55121c582786e5d052c1419ac41.zip
merged Alias/AbsTypeDef into TypeDef
-rw-r--r--src/compiler/scala/tools/nsc/Interpreter.scala13
-rw-r--r--src/compiler/scala/tools/nsc/ast/TreeBrowsers.scala23
-rw-r--r--src/compiler/scala/tools/nsc/ast/TreeInfo.scala20
-rw-r--r--src/compiler/scala/tools/nsc/ast/TreePrinters.scala36
-rw-r--r--src/compiler/scala/tools/nsc/ast/Trees.scala129
-rw-r--r--src/compiler/scala/tools/nsc/ast/parser/Parsers.scala40
-rw-r--r--src/compiler/scala/tools/nsc/models/Models.scala19
-rw-r--r--src/compiler/scala/tools/nsc/models/SemanticTokens.scala9
-rw-r--r--src/compiler/scala/tools/nsc/symtab/Symbols.scala4
-rw-r--r--src/compiler/scala/tools/nsc/symtab/Types.scala21
-rw-r--r--src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala1
-rw-r--r--src/compiler/scala/tools/nsc/transform/Erasure.scala4
-rw-r--r--src/compiler/scala/tools/nsc/transform/LiftCode.scala3
-rw-r--r--src/compiler/scala/tools/nsc/transform/TailCalls.scala2
-rw-r--r--src/compiler/scala/tools/nsc/transform/UnCurry.scala2
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Namers.scala50
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/RefChecks.scala5
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala64
18 files changed, 205 insertions, 240 deletions
diff --git a/src/compiler/scala/tools/nsc/Interpreter.scala b/src/compiler/scala/tools/nsc/Interpreter.scala
index c986c86664..c15794a929 100644
--- a/src/compiler/scala/tools/nsc/Interpreter.scala
+++ b/src/compiler/scala/tools/nsc/Interpreter.scala
@@ -59,7 +59,7 @@ class Interpreter(val settings: Settings, out: PrintWriter) {
import compiler.Traverser
import compiler.{Tree, TermTree,
ValOrDefDef, ValDef, DefDef, Assign,
- ClassDef, ModuleDef, Ident, Select, AliasTypeDef,
+ ClassDef, ModuleDef, Ident, Select, TypeDef,
Import, MemberDef}
import compiler.CompilationUnit
import compiler.{Symbol,Name,Type}
@@ -399,12 +399,12 @@ class Interpreter(val settings: Settings, out: PrintWriter) {
new ExprReq(line, lineName)
case List(_:ModuleDef) => new ModuleReq(line, lineName)
case List(_:ClassDef) => new ClassReq(line, lineName)
- case List(_:AliasTypeDef) => new TypeAliasReq(line, lineName)
+ case List(t:TypeDef) if compiler.treeInfo.isAliasTypeDef(t) =>
+ new TypeAliasReq(line, lineName)
case List(_:Import) => new ImportReq(line, lineName)
- case _ => {
+ case _ =>
reporter.error(null, "That kind of statement combination is not supported by the interpreter.")
null
- }
}
/** <p>
@@ -587,7 +587,8 @@ class Interpreter(val settings: Settings, out: PrintWriter) {
/** list of type aliases defined */
val typeNames =
- for (AliasTypeDef(mods, name, _, _) <- trees if mods.isPublic)
+ for (t @ TypeDef(mods, name, _, _) <- trees
+ if mods.isPublic && compiler.treeInfo.isAliasTypeDef(t))
yield name
/** all (public) names defined by these statements */
@@ -829,7 +830,7 @@ class Interpreter(val settings: Settings, out: PrintWriter) {
private class TypeAliasReq(line: String, lineName: String)
extends Request(line, lineName) {
def newTypeName = trees match {
- case List(AliasTypeDef(_, name, _, _)) => name
+ case List(TypeDef(_, name, _, _)) => name
}
override def resultExtractionCode(code: PrintWriter): Unit = {
diff --git a/src/compiler/scala/tools/nsc/ast/TreeBrowsers.scala b/src/compiler/scala/tools/nsc/ast/TreeBrowsers.scala
index c13742860f..78e05d8e72 100644
--- a/src/compiler/scala/tools/nsc/ast/TreeBrowsers.scala
+++ b/src/compiler/scala/tools/nsc/ast/TreeBrowsers.scala
@@ -269,11 +269,8 @@ abstract class TreeBrowsers {
case DefDef(mods, name, tparams, vparams, tpe, rhs) =>
("DefDef", name)
- case AbsTypeDef(mods, name, tparams, rhs, lobound) =>
- ("AbsTypeDef", name)
-
- case AliasTypeDef(mods, name, tparams, rhs) =>
- ("AliasTypeDef", name)
+ case TypeDef(mods, name, tparams, rhs) =>
+ ("TypeDef", name)
case Import(expr, selectors) =>
("Import", EMPTY)
@@ -365,6 +362,9 @@ abstract class TreeBrowsers {
case AppliedTypeTree(tpe, args) =>
("AppliedType", EMPTY)
+ case TypeBoundsTree(lo, hi) =>
+ ("TypeBoundsTree", EMPTY)
+
case Try(block, catcher, finalizer) =>
("Try", EMPTY)
@@ -411,14 +411,8 @@ abstract class TreeBrowsers {
tpe :: rhs :: children
}
- case AbsTypeDef(mods, name, tparams, rhs, lobound) =>
- rhs :: lobound :: tparams // @M: was List(rhs, lobound)
-
- case AliasTypeDef(mods, name, tparams, rhs) => {
- var children: List[Tree] = List()
- children = tparams ::: children
- rhs :: children
- }
+ case TypeDef(mods, name, tparams, rhs) =>
+ rhs :: tparams // @M: was List(rhs, lobound)
case Import(expr, selectors) => {
var children: List[Tree] = List(expr)
@@ -512,6 +506,9 @@ abstract class TreeBrowsers {
case AppliedTypeTree(tpe, args) =>
tpe :: args
+ case TypeBoundsTree(lo, hi) =>
+ List(lo, hi)
+
case Try(block, catches, finalizer) =>
block :: catches ::: List(finalizer)
diff --git a/src/compiler/scala/tools/nsc/ast/TreeInfo.scala b/src/compiler/scala/tools/nsc/ast/TreeInfo.scala
index eef8aa406c..af98036536 100644
--- a/src/compiler/scala/tools/nsc/ast/TreeInfo.scala
+++ b/src/compiler/scala/tools/nsc/ast/TreeInfo.scala
@@ -36,8 +36,7 @@ abstract class TreeInfo {
def isDeclaration(tree: Tree): boolean = tree match {
case DefDef(_, _, _, _, _, EmptyTree)
| ValDef(_, _, _, EmptyTree)
- | AbsTypeDef(_, _, _, _, _)
- | AliasTypeDef(_, _, _, _) => true
+ | TypeDef(_, _, _, _) => true
case _ => false
}
@@ -46,8 +45,7 @@ abstract class TreeInfo {
def isInterfaceMember(tree: Tree): boolean = tree match {
case EmptyTree => true
case Import(_, _) => true
- case AbsTypeDef(_, _, _, _, _) => true
- case AliasTypeDef(_, _, _, _) => true
+ case TypeDef(_, _, _, _) => true
case DefDef(mods, _, _, _, _, __) => mods.hasFlag(DEFERRED)
case ValDef(mods, _, _, _) => mods.hasFlag(DEFERRED)
case DocDef(_, definition) => isInterfaceMember(definition)
@@ -59,8 +57,7 @@ abstract class TreeInfo {
def isPureDef(tree: Tree): boolean = tree match {
case EmptyTree
| ClassDef(_, _, _, _)
- | AbsTypeDef(_, _, _, _, _)
- | AliasTypeDef(_, _, _, _)
+ | TypeDef(_, _, _, _)
| Import(_, _)
| DefDef(_, _, _, _, _, _) =>
true
@@ -284,4 +281,15 @@ abstract class TreeInfo {
case _ =>
false
}
+
+ def isAbsTypeDef(tree: Tree) = tree match {
+ case TypeDef(_, _, _, TypeBoundsTree(_, _)) => true
+ case TypeDef(_, _, _, rhs) => rhs.tpe.isInstanceOf[TypeBounds]
+ case _ => false
+ }
+
+ def isAliasTypeDef(tree: Tree) = tree match {
+ case TypeDef(_, _, _, _) => !isAbsTypeDef(tree)
+ case _ => false
+ }
}
diff --git a/src/compiler/scala/tools/nsc/ast/TreePrinters.scala b/src/compiler/scala/tools/nsc/ast/TreePrinters.scala
index 501339cadf..f2cbceb316 100644
--- a/src/compiler/scala/tools/nsc/ast/TreePrinters.scala
+++ b/src/compiler/scala/tools/nsc/ast/TreePrinters.scala
@@ -50,7 +50,7 @@ abstract class TreePrinters {
def printRow(ts: List[Tree], sep: String): unit = printRow(ts, "", sep, "")
- def printTypeParams(ts: List[AbsTypeDef]): unit =
+ def printTypeParams(ts: List[TypeDef]): unit =
if (!ts.isEmpty) {
print("["); printSeq(ts){printParam}{print(", ")}; print("]")
}
@@ -66,9 +66,9 @@ abstract class TreePrinters {
case ValDef(mods, name, tp, rhs) =>
printAnnotations(tree)
print(symName(tree, name)); printOpt(": ", tp)
- case AbsTypeDef(mods, name, tparams, lo, hi) =>
+ case TypeDef(mods, name, tparams, rhs) =>
print(symName(tree, name))
- printTypeParams(tparams); printOpt(" >: ", lo); printOpt(" <: ", hi)
+ printTypeParams(tparams); print(rhs)
}
def printBlock(tree: Tree): unit = tree match {
@@ -156,13 +156,14 @@ abstract class TreePrinters {
printTypeParams(tparams); vparamss foreach printValueParams
printOpt(": ", tp); printOpt(" = ", rhs)
- case AbsTypeDef(mods, name, _, lo, hi) =>
- printModifiers(tree, mods); print("type "); printParam(tree)
-
- case AliasTypeDef(mods, name, tparams, rhs) =>
- printAnnotations(tree)
- printModifiers(tree, mods); print("type " + symName(tree, name))
- printTypeParams(tparams); printOpt(" = ", rhs)
+ case TypeDef(mods, name, tparams, rhs) =>
+ if (mods hasFlag (PARAM | DEFERRED)) {
+ printModifiers(tree, mods); print("type "); printParam(tree)
+ } else {
+ printAnnotations(tree)
+ printModifiers(tree, mods); print("type " + symName(tree, name))
+ printTypeParams(tparams); printOpt(" = ", rhs)
+ }
case LabelDef(name, params, rhs) =>
print(symName(tree, name)); printRow(params, "(", ",", ")"); printBlock(rhs)
@@ -324,8 +325,8 @@ abstract class TreePrinters {
case AppliedTypeTree(tp, args) =>
print(tp); printRow(args, "[", ", ", "]")
- case WildcardTypeTree(lo, hi) =>
- print("_ "); printOpt(" >: ", lo); printOpt(" <: ", hi)
+ case TypeBoundsTree(lo, hi) =>
+ printOpt(" >: ", lo); printOpt(" <: ", hi)
case ExistentialTypeTree(tpt, whereClauses) =>
print(tpt);
@@ -342,14 +343,13 @@ abstract class TreePrinters {
def print(tree: Tree): unit = {
if (settings.Xprintpos.value) print("[" + tree.pos + "]")
printRaw(
- if (tree.isDef && tree.symbol != NoSymbol) {
+ if (tree.isDef && tree.symbol != NoSymbol && tree.symbol.isInitialized) {
tree match {
- case ClassDef(_, _, _, impl) => ClassDef(tree.symbol, impl)
- case ModuleDef(_, _, impl) => ModuleDef(tree.symbol, impl)
-// case ValDef(_, _, _, rhs) => ValDef(tree.symbol, rhs)
+ case ClassDef(_, _, _, impl) => ClassDef(tree.symbol, impl)
+ case ModuleDef(_, _, impl) => ModuleDef(tree.symbol, impl)
+ case ValDef(_, _, _, rhs) => ValDef(tree.symbol, rhs)
case DefDef(_, _, _, vparamss, _, rhs) => DefDef(tree.symbol, vparamss, rhs)
- case AbsTypeDef(_, _, _, _, _) => AbsTypeDef(tree.symbol)
- case AliasTypeDef(_, _, _, rhs) => AliasTypeDef(tree.symbol, rhs)
+ case TypeDef(_, _, _, rhs) => TypeDef(tree.symbol, rhs)
case _ => tree
}
} else tree)
diff --git a/src/compiler/scala/tools/nsc/ast/Trees.scala b/src/compiler/scala/tools/nsc/ast/Trees.scala
index 12e680fb3c..6de292b7ed 100644
--- a/src/compiler/scala/tools/nsc/ast/Trees.scala
+++ b/src/compiler/scala/tools/nsc/ast/Trees.scala
@@ -227,9 +227,8 @@ trait Trees {
abstract class MemberDef extends DefTree {
def mods: Modifiers
def keyword: String = this match {
- case AliasTypeDef(_, _, _, _) => "type"
- case AbsTypeDef(_, _, _, _, _) => "type"
- case _ : ClassDef => "class"
+ case TypeDef(_, _, _, _) => "type"
+ case ClassDef(_, _, _, _) => "class"
case DefDef(_, _, _, _, _, _) => "def"
case ModuleDef(_, _, _) => "object"
case PackageDef(_, _) => "package"
@@ -253,7 +252,7 @@ trait Trees {
}
/** Class definition */
- case class ClassDef(mods: Modifiers, name: Name, tparams: List[AbsTypeDef], impl: Template)
+ case class ClassDef(mods: Modifiers, name: Name, tparams: List[TypeDef], impl: Template)
extends ImplDef
/**
@@ -265,7 +264,7 @@ trait Trees {
posAssigner.atPos(sym.pos) {
ClassDef(Modifiers(sym.flags),
sym.name,
- sym.typeParams map AbsTypeDef,
+ sym.typeParams map TypeDef,
impl) setSymbol sym
}
@@ -346,7 +345,7 @@ trait Trees {
* @param tpt
* @param rhs
*/
- case class DefDef(mods: Modifiers, name: Name, tparams: List[AbsTypeDef],
+ case class DefDef(mods: Modifiers, name: Name, tparams: List[TypeDef],
vparamss: List[List[ValDef]], tpt: Tree, rhs: Tree)
extends ValOrDefDef {
assert(tpt.isType)
@@ -360,7 +359,7 @@ trait Trees {
assert(sym != NoSymbol)
DefDef(Modifiers(sym.flags),
sym.name,
- sym.typeParams map AbsTypeDef,
+ sym.typeParams map TypeDef,
vparamss,
TypeTree(sym.tpe.finalResultType),
rhs) setSymbol sym
@@ -377,39 +376,21 @@ trait Trees {
def DefDef(sym: Symbol, rhs: List[List[Symbol]] => Tree): DefDef =
DefDef(sym, Modifiers(sym.flags), rhs)
- /** Abstract type or type parameter
- *
- * @param mods
- * @param name
- * @param tparams
- * @param lo
- * @param hi
- */
- case class AbsTypeDef(mods: Modifiers, name: Name, tparams: List[AbsTypeDef], lo: Tree, hi: Tree)
+ /** Abstract type, type parameter, or type alias */
+ case class TypeDef(mods: Modifiers, name: Name, tparams: List[TypeDef], rhs: Tree)
extends MemberDef {
def namePos = pos.offset.map(n => n - name.length).get(-1)
}
- def AbsTypeDef(sym: Symbol): AbsTypeDef =
+ /** A TypeDef node which defines given `sym' with given tight hand side `rhs'. */
+ def TypeDef(sym: Symbol, rhs: Tree): TypeDef =
posAssigner.atPos(sym.pos) {
- AbsTypeDef(Modifiers(sym.flags), sym.name, sym.typeParams map AbsTypeDef,
- TypeTree(sym.info.bounds.lo), TypeTree(sym.info.bounds.hi))
+ TypeDef(Modifiers(sym.flags), sym.name, sym.typeParams map TypeDef, rhs)
}
- /** Type alias
- *
- * @param mods
- * @param name
- * @param tparams
- * @param rhs
- */
- case class AliasTypeDef(mods: Modifiers, name: Name, tparams: List[AbsTypeDef], rhs: Tree)
- extends MemberDef
-
- def AliasTypeDef(sym: Symbol, rhs: Tree): AliasTypeDef =
- posAssigner.atPos(sym.pos) {
- AliasTypeDef(Modifiers(sym.flags), sym.name, sym.typeParams map AbsTypeDef, rhs)
- }
+ /** A TypeDef node which defines abstract type or type parameter for given `sym' */
+ def TypeDef(sym: Symbol): TypeDef =
+ TypeDef(sym, TypeBoundsTree(TypeTree(sym.info.bounds.lo), TypeTree(sym.info.bounds.hi)))
/** <p>
* Labelled expression - the symbols in the array (must be Idents!)
@@ -748,7 +729,7 @@ trait Trees {
override def symbol_=(sym: Symbol): unit = { tpt.symbol = sym }
}
- case class WildcardTypeTree(lo: Tree, hi: Tree)
+ case class TypeBoundsTree(lo: Tree, hi: Tree)
extends TypTree
case class ExistentialTypeTree(tpt: Tree, whereClauses: List[Tree])
@@ -766,9 +747,7 @@ trait Trees {
// mods val name: tpt = rhs
case DefDef(mods, name, tparams, vparamss, tpt, rhs) =>
// mods def name[tparams](vparams): tpt = rhs
- case AbsTypeDef(mods, name, tparams, lo, hi) => (eliminated by erasure)
- // mods type name[tparams] >: lo <: hi
- case AliasTypeDef(mods, name, tparams, rhs) => (eliminated by erasure)
+ case TypeDef(mods, name, tparams, rhs) => (eliminated by erasure)
// mods type name[tparams] = rhs
case LabelDef(name, params, rhs) =>
// used for tailcalls and like
@@ -842,20 +821,19 @@ trait Trees {
// parent1 with ... with parentN { refinement }
case AppliedTypeTree(tpt, args) => (eliminated by uncurry)
// tpt[args]
- case WildcardTypeTree(lo, hi) => (eliminated by uncurry)
- // todo: get rid of that!
+ case TypeBoundsTree(lo, hi) => (eliminated by uncurry)
+ // >: lo <: hi
case ExistentialTypeTree(tpt, whereClauses) =>
*/
abstract class TreeCopier {
- def ClassDef(tree: Tree, mods: Modifiers, name: Name, tparams: List[AbsTypeDef], impl: Template): ClassDef
+ def ClassDef(tree: Tree, mods: Modifiers, name: Name, tparams: List[TypeDef], impl: Template): ClassDef
def PackageDef(tree: Tree, name: Name, stats: List[Tree]): PackageDef
def ModuleDef(tree: Tree, mods: Modifiers, name: Name, impl: Template): ModuleDef
def ValDef(tree: Tree, mods: Modifiers, name: Name, tpt: Tree, rhs: Tree): ValDef
- def DefDef(tree: Tree, mods: Modifiers, name: Name, tparams: List[AbsTypeDef], vparamss: List[List[ValDef]], tpt: Tree, rhs: Tree): DefDef
- def AbsTypeDef(tree: Tree, mods: Modifiers, name: Name, tparams: List[AbsTypeDef], lo: Tree, hi: Tree): AbsTypeDef
- def AliasTypeDef(tree: Tree, mods: Modifiers, name: Name, tparams: List[AbsTypeDef], rhs: Tree): AliasTypeDef
+ def DefDef(tree: Tree, mods: Modifiers, name: Name, tparams: List[TypeDef], vparamss: List[List[ValDef]], tpt: Tree, rhs: Tree): DefDef
+ def TypeDef(tree: Tree, mods: Modifiers, name: Name, tparams: List[TypeDef], rhs: Tree): TypeDef
def LabelDef(tree: Tree, name: Name, params: List[Ident], rhs: Tree): LabelDef
def Import(tree: Tree, expr: Tree, selectors: List[(Name, Name)]): Import
def Annotation(tree: Tree, constr: Tree, elements: List[Tree]): Annotation
@@ -892,12 +870,12 @@ trait Trees {
def SelectFromTypeTree(tree: Tree, qualifier: Tree, selector: Name): SelectFromTypeTree
def CompoundTypeTree(tree: Tree, templ: Template): CompoundTypeTree
def AppliedTypeTree(tree: Tree, tpt: Tree, args: List[Tree]): AppliedTypeTree
- def WildcardTypeTree(tree: Tree, lo: Tree, hi: Tree): WildcardTypeTree
+ def TypeBoundsTree(tree: Tree, lo: Tree, hi: Tree): TypeBoundsTree
def ExistentialTypeTree(tree: Tree, tpt: Tree, whereClauses: List[Tree]): ExistentialTypeTree
}
class StrictTreeCopier extends TreeCopier {
- def ClassDef(tree: Tree, mods: Modifiers, name: Name, tparams: List[AbsTypeDef], impl: Template) =
+ def ClassDef(tree: Tree, mods: Modifiers, name: Name, tparams: List[TypeDef], impl: Template) =
new ClassDef(mods, name, tparams, impl).copyAttrs(tree);
def PackageDef(tree: Tree, name: Name, stats: List[Tree]) =
new PackageDef(name, stats).copyAttrs(tree)
@@ -905,12 +883,10 @@ trait Trees {
new ModuleDef(mods, name, impl).copyAttrs(tree)
def ValDef(tree: Tree, mods: Modifiers, name: Name, tpt: Tree, rhs: Tree) =
new ValDef(mods, name, tpt, rhs).copyAttrs(tree)
- def DefDef(tree: Tree, mods: Modifiers, name: Name, tparams: List[AbsTypeDef], vparamss: List[List[ValDef]], tpt: Tree, rhs: Tree) =
+ def DefDef(tree: Tree, mods: Modifiers, name: Name, tparams: List[TypeDef], vparamss: List[List[ValDef]], tpt: Tree, rhs: Tree) =
new DefDef(mods, name, tparams, vparamss, tpt, rhs).copyAttrs(tree)
- def AbsTypeDef(tree: Tree, mods: Modifiers, name: Name, tparams: List[AbsTypeDef], lo: Tree, hi: Tree) =
- new AbsTypeDef(mods, name, tparams, lo, hi).copyAttrs(tree)
- def AliasTypeDef(tree: Tree, mods: Modifiers, name: Name, tparams: List[AbsTypeDef], rhs: Tree) =
- new AliasTypeDef(mods, name, tparams, rhs).copyAttrs(tree)
+ def TypeDef(tree: Tree, mods: Modifiers, name: Name, tparams: List[TypeDef], rhs: Tree) =
+ new TypeDef(mods, name, tparams, rhs).copyAttrs(tree)
def LabelDef(tree: Tree, name: Name, params: List[Ident], rhs: Tree) =
new LabelDef(name, params, rhs).copyAttrs(tree)
def Import(tree: Tree, expr: Tree, selectors: List[(Name, Name)]) =
@@ -983,15 +959,15 @@ trait Trees {
new CompoundTypeTree(templ).copyAttrs(tree)
def AppliedTypeTree(tree: Tree, tpt: Tree, args: List[Tree]) =
new AppliedTypeTree(tpt, args).copyAttrs(tree)
- def WildcardTypeTree(tree: Tree, lo: Tree, hi: Tree) =
- new WildcardTypeTree(lo, hi).copyAttrs(tree)
+ def TypeBoundsTree(tree: Tree, lo: Tree, hi: Tree) =
+ new TypeBoundsTree(lo, hi).copyAttrs(tree)
def ExistentialTypeTree(tree: Tree, tpt: Tree, whereClauses: List[Tree]) =
new ExistentialTypeTree(tpt, whereClauses).copyAttrs(tree)
}
class LazyTreeCopier(copy: TreeCopier) extends TreeCopier {
def this() = this(new StrictTreeCopier)
- def ClassDef(tree: Tree, mods: Modifiers, name: Name, tparams: List[AbsTypeDef], impl: Template) = tree match {
+ def ClassDef(tree: Tree, mods: Modifiers, name: Name, tparams: List[TypeDef], impl: Template) = tree match {
case t @ ClassDef(mods0, name0, tparams0, impl0)
if (mods0 == mods && (name0 == name) && (tparams0 == tparams) && (impl0 == impl)) => t
case _ => copy.ClassDef(tree, mods, name, tparams, impl)
@@ -1011,21 +987,16 @@ trait Trees {
if (mods0 == mods) && (name0 == name) && (tpt0 == tpt) && (rhs0 == rhs) => t
case _ => copy.ValDef(tree, mods, name, tpt, rhs)
}
- def DefDef(tree: Tree, mods: Modifiers, name: Name, tparams: List[AbsTypeDef], vparamss: List[List[ValDef]], tpt: Tree, rhs: Tree) = tree match {
+ def DefDef(tree: Tree, mods: Modifiers, name: Name, tparams: List[TypeDef], vparamss: List[List[ValDef]], tpt: Tree, rhs: Tree) = tree match {
case t @ DefDef(mods0, name0, tparams0, vparamss0, tpt0, rhs0)
if (mods0 == mods) && (name0 == name) && (tparams0 == tparams) &&
(vparamss0 == vparamss) && (tpt0 == tpt) && (rhs == rhs0) => t
case _ => copy.DefDef(tree, mods, name, tparams, vparamss, tpt, rhs)
}
- def AbsTypeDef(tree: Tree, mods: Modifiers, name: Name, tparams: List[AbsTypeDef], lo: Tree, hi: Tree) = tree match {
- case t @ AbsTypeDef(mods0, name0, tparams0, lo0, hi0)
- if (mods0 == mods) && (name0 == name) && (tparams0 == tparams) && (lo0 == lo) && (hi0 == hi) => t
- case _ => copy.AbsTypeDef(tree, mods, name, tparams, lo, hi)
- }
- def AliasTypeDef(tree: Tree, mods: Modifiers, name: Name, tparams: List[AbsTypeDef], rhs: Tree) = tree match {
- case t @ AliasTypeDef(mods0, name0, tparams0, rhs0)
+ def TypeDef(tree: Tree, mods: Modifiers, name: Name, tparams: List[TypeDef], rhs: Tree) = tree match {
+ case t @ TypeDef(mods0, name0, tparams0, rhs0)
if (mods0 == mods) && (name0 == name) && (tparams0 == tparams) && (rhs0 == rhs) => t
- case _ => copy.AliasTypeDef(tree, mods, name, tparams, rhs)
+ case _ => copy.TypeDef(tree, mods, name, tparams, rhs)
}
def LabelDef(tree: Tree, name: Name, params: List[Ident], rhs: Tree) = tree match {
case t @ LabelDef(name0, params0, rhs0)
@@ -1206,10 +1177,10 @@ trait Trees {
if (tpt0 == tpt) && (args0 == args) => t
case _ => copy.AppliedTypeTree(tree, tpt, args)
}
- def WildcardTypeTree(tree: Tree, lo: Tree, hi: Tree) = tree match {
- case t @ WildcardTypeTree(lo0, hi0)
+ def TypeBoundsTree(tree: Tree, lo: Tree, hi: Tree) = tree match {
+ case t @ TypeBoundsTree(lo0, hi0)
if (lo0 == lo) && (hi0 == hi) => t
- case _ => copy.WildcardTypeTree(tree, lo, hi)
+ case _ => copy.TypeBoundsTree(tree, lo, hi)
}
def ExistentialTypeTree(tree: Tree, tpt: Tree, whereClauses: List[Tree]) = tree match {
case t @ ExistentialTypeTree(tpt0, whereClauses0)
@@ -1233,7 +1204,7 @@ trait Trees {
}
case ClassDef(mods, name, tparams, impl) =>
atOwner(tree.symbol) {
- copy.ClassDef(tree, mods, name, transformAbsTypeDefs(tparams), transformTemplate(impl))
+ copy.ClassDef(tree, mods, name, transformTypeDefs(tparams), transformTemplate(impl))
}
case ModuleDef(mods, name, impl) =>
atOwner(tree.symbol.moduleClass) {
@@ -1246,15 +1217,11 @@ trait Trees {
case DefDef(mods, name, tparams, vparamss, tpt, rhs) =>
atOwner(tree.symbol) {
copy.DefDef(
- tree, mods, name, transformAbsTypeDefs(tparams), transformValDefss(vparamss), transform(tpt), transform(rhs))
+ tree, mods, name, transformTypeDefs(tparams), transformValDefss(vparamss), transform(tpt), transform(rhs))
}
- case AbsTypeDef(mods, name, tparams, lo, hi) =>
+ case TypeDef(mods, name, tparams, rhs) =>
atOwner(tree.symbol) {
- copy.AbsTypeDef(tree, mods, name, transformAbsTypeDefs(tparams), transform(lo), transform(hi))
- }
- case AliasTypeDef(mods, name, tparams, rhs) =>
- atOwner(tree.symbol) {
- copy.AliasTypeDef(tree, mods, name, transformAbsTypeDefs(tparams), transform(rhs))
+ copy.TypeDef(tree, mods, name, transformTypeDefs(tparams), transform(rhs))
}
case LabelDef(name, params, rhs) =>
copy.LabelDef(tree, name, transformIdents(params), transform(rhs)) //bq: Martin, once, atOwner(...) works, also change `LamdaLifter.proxy'
@@ -1330,8 +1297,8 @@ trait Trees {
copy.CompoundTypeTree(tree, transformTemplate(templ))
case AppliedTypeTree(tpt, args) =>
copy.AppliedTypeTree(tree, transform(tpt), transformTrees(args))
- case WildcardTypeTree(lo, hi) =>
- copy.WildcardTypeTree(tree, transform(lo), transform(hi))
+ case TypeBoundsTree(lo, hi) =>
+ copy.TypeBoundsTree(tree, transform(lo), transform(hi))
case ExistentialTypeTree(tpt, whereClauses) =>
copy.ExistentialTypeTree(tree, transform(tpt), transformTrees(whereClauses))
}
@@ -1340,8 +1307,8 @@ trait Trees {
List.mapConserve(trees)(transform)
def transformTemplate(tree: Template): Template =
transform(tree: Tree).asInstanceOf[Template]
- def transformAbsTypeDefs(trees: List[AbsTypeDef]): List[AbsTypeDef] =
- List.mapConserve(trees)(tree => transform(tree).asInstanceOf[AbsTypeDef])
+ def transformTypeDefs(trees: List[TypeDef]): List[TypeDef] =
+ List.mapConserve(trees)(tree => transform(tree).asInstanceOf[TypeDef])
def transformValDef(tree: ValDef): ValDef =
if (tree.isEmpty) tree else transform(tree).asInstanceOf[ValDef]
def transformValDefs(trees: List[ValDef]): List[ValDef] =
@@ -1392,11 +1359,7 @@ trait Trees {
atOwner(tree.symbol) {
traverseTrees(tparams); traverseTreess(vparamss); traverse(tpt); traverse(rhs)
}
- case AbsTypeDef(mods, name, tparams, lo, hi) =>
- atOwner(tree.symbol) {
- traverseTrees(tparams); traverse(lo); traverse(hi)
- }
- case AliasTypeDef(mods, name, tparams, rhs) =>
+ case TypeDef(mods, name, tparams, rhs) =>
atOwner(tree.symbol) {
traverseTrees(tparams); traverse(rhs)
}
@@ -1476,7 +1439,7 @@ trait Trees {
traverse(templ)
case AppliedTypeTree(tpt, args) =>
traverse(tpt); traverseTrees(args)
- case WildcardTypeTree(lo, hi) =>
+ case TypeBoundsTree(lo, hi) =>
traverse(lo); traverse(hi)
case ExistentialTypeTree(tpt, whereClauses) =>
traverse(tpt); traverseTrees(whereClauses)
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
index abe2248b3e..6da395b2f1 100644
--- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
+++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
@@ -130,7 +130,7 @@ trait Parsers {
/** The wildcards introduced by `_' in the current type.
* Parameters appear in reverse order
*/
- var wildcards: List[AbsTypeDef] = Nil
+ var wildcards: List[TypeDef] = Nil
/** this is the general parse method
*/
@@ -671,7 +671,7 @@ trait Parsers {
val whereClauses = refinement()
for (wc <- whereClauses) {
wc match {
- case AbsTypeDef(_, _, _, _, _) | ValDef(_, _, _, EmptyTree) =>
+ case TypeDef(_, _, _, TypeBoundsTree(_, _)) | ValDef(_, _, _, EmptyTree) =>
;
case _ =>
syntaxError(wc.pos, "not a legal where clause", false)
@@ -775,6 +775,14 @@ trait Parsers {
val ts = types(isPattern)
accept(RPAREN)
atPos(pos) { makeTupleType(ts, true) }
+/*
+ } else if (inToken == USCORE) {
+ val pname = freshName("_$").toTypeName
+ val pos = inSkipToken
+ val param = makeSyntheticTypeParam(pname) setPos pos
+ implicitTypeParams = param :: implicitTypeParams
+ t = atPos(pos) { Ident(pname) }
+*/
} else {
val r = path(false, true)
val x = r match {
@@ -1735,8 +1743,8 @@ trait Parsers {
* FunTypeParamClause ::= `[' TypeParam {`,' TypeParam} `]']
* TypeParam ::= Id TypeParamClauseOpt TypeBounds [<% Type]
*/
- def typeParamClauseOpt(owner: Name, implicitViewBuf: ListBuffer[Tree]): List[AbsTypeDef] = {
- def typeParam(): AbsTypeDef = {
+ def typeParamClauseOpt(owner: Name, implicitViewBuf: ListBuffer[Tree]): List[TypeDef] = {
+ def typeParam(): TypeDef = {
var mods = Modifiers(Flags.PARAM)
if (owner.isTypeName && isIdent) {
if (inName == PLUS) {
@@ -1749,20 +1757,20 @@ trait Parsers {
}
val pos = inCurrentPos
val pname =
- if (inToken == USCORE) { // @M! also allow underscore
+ (if (inToken == USCORE) { // @M! also allow underscore
inNextToken
nme.WILDCARD
- } else ident()
+ } else ident()).toTypeName
- val tparams = typeParamClauseOpt(pname.toTypeName, null) // @M TODO null --> no higher-order view bounds for now
- val param = atPos(pos) { typeBounds(mods, pname, tparams) }
+ val tparams = typeParamClauseOpt(pname, null) // @M TODO null --> no higher-order view bounds for now
+ val param = atPos(pos) { TypeDef(mods, pname, tparams, typeBounds()) }
if (inToken == VIEWBOUND && (implicitViewBuf ne null))
implicitViewBuf += atPos(inSkipToken) {
- makeFunctionTypeTree(List(Ident(pname.toTypeName)), typ())
+ makeFunctionTypeTree(List(Ident(pname)), typ())
}
param
}
- val params = new ListBuffer[AbsTypeDef]
+ val params = new ListBuffer[TypeDef]
newLineOptWhenFollowedBy(LBRACKET)
if (inToken == LBRACKET) {
inNextToken
@@ -1778,10 +1786,10 @@ trait Parsers {
/** TypeBounds ::= [`>:' Type] [`<:' Type]
*/
- def typeBounds(mods: Modifiers, name: Name, tparams: List[AbsTypeDef]): AbsTypeDef =
- AbsTypeDef(mods, name.toTypeName, tparams, // @M: an abstract type may have type parameters
- bound(SUPERTYPE, nme.Nothing),
- bound(SUBTYPE, nme.Any))
+ def typeBounds(): TypeBoundsTree =
+ TypeBoundsTree(
+ bound(SUPERTYPE, nme.Nothing),
+ bound(SUBTYPE, nme.Any))
def bound(tok: int, default: Name): Tree =
if (inToken == tok) { inNextToken; typ() }
@@ -2052,9 +2060,9 @@ trait Parsers {
inToken match {
case EQUALS =>
inNextToken
- AliasTypeDef(mods, name, tparams, typ())
+ TypeDef(mods, name, tparams, typ())
case SUPERTYPE | SUBTYPE | SEMI | NEWLINE | NEWLINES | COMMA | RBRACE =>
- typeBounds(mods | Flags.DEFERRED, name, tparams)
+ TypeDef(mods | Flags.DEFERRED, name, tparams, typeBounds())
case _ =>
syntaxErrorOrIncomplete("`=', `>:', or `<:' expected", true)
EmptyTree
diff --git a/src/compiler/scala/tools/nsc/models/Models.scala b/src/compiler/scala/tools/nsc/models/Models.scala
index 553ea5f2a4..b21435d587 100644
--- a/src/compiler/scala/tools/nsc/models/Models.scala
+++ b/src/compiler/scala/tools/nsc/models/Models.scala
@@ -119,10 +119,12 @@ abstract class Models {
case _ =>
}
ret = ret + " : " + textFor(vdef.tpt)
+/* Martin to Sean: Please check whether this can be dropped or does it need to be adapted?
case atd: AbsTypeDef =>
ret = ret + "[" + (for (val tparam <- atd.tparams) yield textFor(tparam)) + "]" +
((if(atd.hi ne null) " <: " + textFor(atd.hi) else "") +
(if(atd.lo ne null) " >: " + textFor(atd.lo) else ""));
+*/
case _ =>
ret = ret + tree.toString()
}
@@ -302,7 +304,7 @@ abstract class Models {
(acceptPrivate || !tree.asInstanceOf[ValOrDefDef].mods.isPrivate)
/* && !tree.asInstanceOf[ValOrDefDef].mods.isPrivate */
/* && !tree.asInstanceOf[ValOrDefDef].mods.isAccessor */) ||
- tree.isInstanceOf[AliasTypeDef])
+ treeInfo.isAliasTypeDef(tree))
override def member(tree: Tree, members: List[Tree]): Tree = {
val tree0 = if (tree.isInstanceOf[DefDef]) {
@@ -358,15 +360,9 @@ abstract class Models {
override def replacedBy(tree0: Tree): Boolean =
super.replacedBy(tree0) && tree0.isInstanceOf[ModuleDef]
}
- class AliasTypeMod(parent0: Composite) extends MemberMod(parent0) {
- def treey = tree.asInstanceOf[AliasTypeDef];
- override def replacedBy(tree0 : Tree) : Boolean = (super.replacedBy(tree0) && tree0.isInstanceOf[AliasTypeDef]);
- }
-
- class AbsTypeMod(parent0: Composite) extends HasTree(parent0) {
- def treey = tree.asInstanceOf[AbsTypeDef]
- override def replacedBy(tree0: Tree): Boolean =
- super.replacedBy(tree0) && tree0.isInstanceOf[AbsTypeDef]
+ class TypeMod(parent0: Composite) extends MemberMod(parent0) {
+ def treey = tree.asInstanceOf[TypeDef];
+ override def replacedBy(tree0 : Tree) : Boolean = (super.replacedBy(tree0) && tree0.isInstanceOf[TypeDef]);
}
def SourceMod(original: CompilationUnit) = new SourceMod(original)
@@ -420,8 +416,7 @@ abstract class Models {
case _: DefDef => new DefMod(parent)
case _: ClassDef => new ClassMod(parent)
case _: ModuleDef => new ObjectMod(parent)
- case _: AliasTypeDef => new AliasTypeMod(parent)
- case _: AbsTypeDef => new AbsTypeMod(parent)
+ case _: TypeDef => new TypeMod(parent)
case _: Import => new ImportMod(parent)
}
diff --git a/src/compiler/scala/tools/nsc/models/SemanticTokens.scala b/src/compiler/scala/tools/nsc/models/SemanticTokens.scala
index fe2b4367a9..934dc6874d 100644
--- a/src/compiler/scala/tools/nsc/models/SemanticTokens.scala
+++ b/src/compiler/scala/tools/nsc/models/SemanticTokens.scala
@@ -396,7 +396,9 @@ class SemanticTokens(val compiler: Global) {
doLog = false;
}
};
-
+/*
+ Martin to Sean: I don't understand why AbsTypeDef is different from AliasTypeDef.
+ Why is the order reversed? Why two buildDefs for tree.symbol vs one for AliasTypeDef?
case tree: AbsTypeDef =>
//Console.err.println("ABS: " + tree.symbol + " " + unit.source.dbg(tree.namePos) + " " + tree.pos.dbgString);
buildDef(tree.symbol, tree.namePos)
@@ -404,6 +406,7 @@ class SemanticTokens(val compiler: Global) {
build(tree.tparams); //@M
build(tree.lo)
build(tree.hi)
+*/
case tree: Bind =>
buildDef(tree.symbol, tree.pos.offset.get(-1))
build(tree.body)
@@ -472,10 +475,10 @@ class SemanticTokens(val compiler: Global) {
//Console.err.println("THIS: " + tree.symbol + " " + tree.qual + " " + tree.pos.dbgString + " " + tree.tpe);
if (tree.symbol ne null) buildUse(tree.symbol, tree.pos.offset.get(-1), tree.tpe);
//Thread.dumpStack();
- case tree : AliasTypeDef =>
+ case tree : TypeDef =>
//Console.err.println("ALIAS: " + tree);
build(tree.rhs); build(tree.tparams); buildDef(tree.symbol, tree.pos.offset.get(-1));
- case tree : DocDef => build(tree.definition);
+ case tree : DocDef => build(tree.definition);
case tree: Import => build(tree.expr)
case tree: AppliedTypeTree => ;
case tree: Annotated => ;
diff --git a/src/compiler/scala/tools/nsc/symtab/Symbols.scala b/src/compiler/scala/tools/nsc/symtab/Symbols.scala
index 3fbd7b8612..596d9619cf 100644
--- a/src/compiler/scala/tools/nsc/symtab/Symbols.scala
+++ b/src/compiler/scala/tools/nsc/symtab/Symbols.scala
@@ -757,7 +757,9 @@ trait Symbols {
/** The top-level class containing this symbol */
def toplevelClass: Symbol =
- if (isClass && owner.isPackageClass) this else owner.toplevelClass
+ if (owner.isPackageClass) {
+ if (isClass) this else moduleClass
+ } else owner.toplevelClass
/** The class with the same name in the same package as this module or
* case class factory
diff --git a/src/compiler/scala/tools/nsc/symtab/Types.scala b/src/compiler/scala/tools/nsc/symtab/Types.scala
index 0813bb4794..03f408cf01 100644
--- a/src/compiler/scala/tools/nsc/symtab/Types.scala
+++ b/src/compiler/scala/tools/nsc/symtab/Types.scala
@@ -1456,6 +1456,7 @@ A type's symbol should never be inspected directly.
val tp = quantified
override protected def rewrap(newtp: Type) = existentialAbstraction(typeParams, newtp)
+ override def isStable: Boolean = false
override def bounds = TypeBounds(maybeRewrap(tp.bounds.lo), maybeRewrap(tp.bounds.hi))
override def parents = tp.parents map maybeRewrap
override def prefix = maybeRewrap(tp.prefix)
@@ -2469,6 +2470,12 @@ A type's symbol should never be inspected directly.
import Math.max
+ private var nextid = 0
+ private def freshTypeName() = {
+ nextid += 1
+ newTypeName("_"+nextid)
+ }
+
/** The maximum depth of all types in the closures of each of the types `tps' */
final def maxClosureDepth(tps: Seq[Type]): Int = {
var d = 0
@@ -3288,6 +3295,7 @@ A type's symbol should never be inspected directly.
val pres = tps map (_.prefix)
val pre = if (variance == 1) lub(pres, depth) else glb(pres, depth)
val argss = tps map (_.typeArgs)
+ val capturedParams = new ListBuffer[Symbol]
val args = List.map2(sym.typeParams, List.transpose(argss)) {
(tparam, as) =>
if (depth == 0)
@@ -3299,12 +3307,21 @@ A type's symbol should never be inspected directly.
else if (tparam.variance == -variance) glb(as, depth-1)
else {
val l = lub(as, depth-1)
- if (l <:< glb(as, depth-1)) l else NoType
+ val g = glb(as, depth-1)
+ if (l <:< g) l
+ else {
+ val qvar =
+ commonOwner(as).newAbstractType(NoPosition, freshTypeName())
+ .setInfo(TypeBounds(g, l))
+ .setFlag(EXISTENTIAL)
+ capturedParams += qvar
+ qvar.tpe
+ }
}
}
try {
if (args contains NoType) None
- else Some(typeRef(pre, sym, args))
+ else Some(existentialAbstraction(capturedParams.toList, typeRef(pre, sym, args)))
} catch {
case ex: MalformedType => None
}
diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala
index 145cccbe2b..aa9e73b70e 100644
--- a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala
+++ b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala
@@ -394,6 +394,7 @@ abstract class ClassfileParser {
if (!isScala) {
clazz.setFlag(sflags)
setPrivateWithin(clazz, jflags)
+ setPrivateWithin(staticModule, jflags)
if (!hasMeta) {
clazz.setInfo(classInfo)
}
diff --git a/src/compiler/scala/tools/nsc/transform/Erasure.scala b/src/compiler/scala/tools/nsc/transform/Erasure.scala
index 1be7a0dc68..59e63b043d 100644
--- a/src/compiler/scala/tools/nsc/transform/Erasure.scala
+++ b/src/compiler/scala/tools/nsc/transform/Erasure.scala
@@ -752,9 +752,7 @@ abstract class Erasure extends AddInterfaces with typechecker.Analyzer {
copy.ClassDef(tree, mods, name, List(), impl)
case DefDef(mods, name, tparams, vparamss, tpt, rhs) =>
copy.DefDef(tree, mods, name, List(), vparamss, tpt, rhs)
- case AbsTypeDef(_, _, _, _, _) =>
- EmptyTree
- case AliasTypeDef(_, _, _, _) =>
+ case TypeDef(_, _, _, _) =>
EmptyTree
case TypeApply(fun, args) if (fun.symbol.owner != AnyClass &&
fun.symbol != Object_asInstanceOf &&
diff --git a/src/compiler/scala/tools/nsc/transform/LiftCode.scala b/src/compiler/scala/tools/nsc/transform/LiftCode.scala
index 18f3983a62..88a9350f0b 100644
--- a/src/compiler/scala/tools/nsc/transform/LiftCode.scala
+++ b/src/compiler/scala/tools/nsc/transform/LiftCode.scala
@@ -259,8 +259,7 @@ abstract class LiftCode extends Transform {
// case ClassDef(mods, name, tparams, impl) =>
// case ValDef(mods, name, tpt, rhs) =>
// case DefDef(mods, name, tparams, vparamss, tpt, rhs) =>
-// case AbsTypeDef(mods, name, tparams, lo, hi) =>
-// case AliasTypeDef(mods, name, tparams, rhs) =>
+// case TypeDef(mods, name, tparams, rhs) =>
// case LabelDef(name, params, rhs) =>
// case Template(parents, self, body) =>
// case Block(stats, expr) =>
diff --git a/src/compiler/scala/tools/nsc/transform/TailCalls.scala b/src/compiler/scala/tools/nsc/transform/TailCalls.scala
index 567afe73ea..e4b88162d7 100644
--- a/src/compiler/scala/tools/nsc/transform/TailCalls.scala
+++ b/src/compiler/scala/tools/nsc/transform/TailCalls.scala
@@ -195,8 +195,6 @@ abstract class TailCalls extends Transform
res
case ValDef(mods, name, tpt, rhs) => super.transform(tree)
- case AbsTypeDef(mods, name, tparams, lo, hi) => tree // (eliminated by erasure)
- case AliasTypeDef(mods, name, tparams, rhs) => tree // (eliminated by erasure)
case LabelDef(name, params, rhs) => super.transform(tree)
case Template(parents, self, body) =>
diff --git a/src/compiler/scala/tools/nsc/transform/UnCurry.scala b/src/compiler/scala/tools/nsc/transform/UnCurry.scala
index 793b173958..80e5210a36 100644
--- a/src/compiler/scala/tools/nsc/transform/UnCurry.scala
+++ b/src/compiler/scala/tools/nsc/transform/UnCurry.scala
@@ -368,7 +368,7 @@ abstract class UnCurry extends InfoTransform with TypingTransformers {
transform(expr));
}
copy.DefDef(
- tree, mods, name, transformAbsTypeDefs(tparams),
+ tree, mods, name, transformTypeDefs(tparams),
transformValDefss(vparamss), transform(tpt), rhs1)
}
} else {
diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala
index 78c35f345b..89f8a26546 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala
@@ -217,7 +217,7 @@ trait Namers { self: Analyzer =>
/** Replace type parameters with their TypeSkolems, which can later be deskolemized to the original type param
* (a skolem is a representation of a bound variable when viewed outside its scope)
*/
- def skolemize(tparams: List[AbsTypeDef]): unit = {
+ def skolemize(tparams: List[TypeDef]): unit = {
val tskolems = newTypeSkolems(tparams map (_.symbol))
for ((tparam, tskolem) <- tparams zip tskolems) tparam.symbol = tskolem
}
@@ -241,12 +241,12 @@ trait Namers { self: Analyzer =>
def enterSym(tree: Tree): Context = {
- def finishWith(tparams: List[AbsTypeDef]): unit = {
+ def finishWith(tparams: List[TypeDef]) {
val sym = tree.symbol
if (settings.debug.value) log("entered " + sym + " in " + context.owner + ", scope-id = " + context.scope.hashCode());
var ltype: LazyType = namerOf(sym).typeCompleter(tree)
if (!tparams.isEmpty) {
- //@M! AbsTypeDef's type params are handled differently
+ //@M! TypeDef's type params are handled differently
//@M e.g., in [A[x <: B], B], A and B are entered first as both are in scope in the definition of x
//@M x is only in scope in `A[x <: B]'
if(!sym.isAbstractType) //@M
@@ -322,14 +322,11 @@ trait Namers { self: Analyzer =>
.setFlag(mods.flags)
setPrivateWithin(tree, tree.symbol, mods)
finishWith(tparams)
- case AbsTypeDef(mods, name, tparams, _, _) =>
- tree.symbol = enterInScope(owner.newAbstractType(tree.pos, name))
- .setFlag(mods.flags)
- setPrivateWithin(tree, tree.symbol, mods)
- finishWith(tparams)
- case AliasTypeDef(mods, name, tparams, _) =>
- tree.symbol = enterInScope(owner.newAliasType(tree.pos, name))
- .setFlag(mods.flags)
+ case TypeDef(mods, name, tparams, _) =>
+ var flags: Long = mods.flags
+ if ((flags & PARAM) != 0) flags |= DEFERRED
+ tree.symbol = enterInScope(new TypeSymbol(owner, tree.pos, name))
+ .setFlag(flags)
setPrivateWithin(tree, tree.symbol, mods)
finishWith(tparams)
case DocDef(_, defn) =>
@@ -457,10 +454,10 @@ trait Namers { self: Analyzer =>
ClassInfoType(parents, decls, clazz)
}
- private def classSig(tparams: List[AbsTypeDef], impl: Template): Type =
+ private def classSig(tparams: List[TypeDef], impl: Template): Type =
parameterizedType(typer.reenterTypeParams(tparams), templateSig(impl))
- private def methodSig(tparams: List[AbsTypeDef], vparamss: List[List[ValDef]],
+ private def methodSig(tparams: List[TypeDef], vparamss: List[List[ValDef]],
tpt: Tree, rhs: Tree): Type = {
val meth = context.owner
@@ -620,21 +617,17 @@ trait Namers { self: Analyzer =>
}
//@M! an abstract type definition (abstract type member/type parameter) may take type parameters, which are in scope in its bounds
- private def abstractTypeSig(tree: Tree, tpsym: Symbol, tparams: List[AbsTypeDef], lo: Tree, hi: Tree) = {
+ private def typeDefSig(tpsym: Symbol, tparams: List[TypeDef], rhs: Tree) = {
val tparamSyms = typer.reenterTypeParams(tparams) //@M make tparams available in scope (just for this abstypedef)
-
- var lt = typer.typedType(lo).tpe
- if (lt.isError) lt = AllClass.tpe
-
- var ht = typer.typedType(hi).tpe
- if (ht.isError) ht = AnyClass.tpe
-
- parameterizedType(tparamSyms, mkTypeBounds(lt, ht)) //@M
+ var tp = typer.typedType(rhs).tpe
+ tp match {
+ case TypeBounds(lt, rt) if (lt.isError || rt.isError) =>
+ tp = TypeBounds(AllClass.tpe, AnyClass.tpe)
+ case _ =>
+ }
+ parameterizedType(tparamSyms, tp) //@M
}
- private def aliasTypeSig(tpsym: Symbol, tparams: List[AbsTypeDef], rhs: Tree): Type =
- parameterizedType(typer.reenterTypeParams(tparams), typer.typedType(rhs).tpe);
-
def typeSig(tree: Tree): Type = {
val sym: Symbol = tree.symbol
tree match {
@@ -680,11 +673,8 @@ trait Namers { self: Analyzer =>
}
} else typer1.typedType(tpt).tpe
- case tree @ AliasTypeDef(_, _, tparams, rhs) =>
- new Namer(makeNewScope(context, tree, sym)).aliasTypeSig(sym, tparams, rhs)
-
- case AbsTypeDef(_, _, tparams, lo, hi) =>
- new Namer(makeNewScope(context, tree, sym)).abstractTypeSig(tree, sym, tparams, lo, hi) //@M!
+ case TypeDef(_, _, tparams, rhs) =>
+ new Namer(makeNewScope(context, tree, sym)).typeDefSig(sym, tparams, rhs) //@M!
case Import(expr, selectors) =>
val expr1 = typer.typedQualifier(expr)
diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
index d12992ad3d..bad97b2d1c 100644
--- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
@@ -705,10 +705,7 @@ abstract class RefChecks extends InfoTransform {
validateVariance(sym, sym.tpe, if (sym.isVariable) NoVariance else CoVariance) //@M TODO: might be affected by change in tpe --> can't use tree.tpe though
checkDeprecatedOvers()
- case AbsTypeDef(_, _, _, _, _) =>
- validateVariance(sym, sym.info, CoVariance)
-
- case AliasTypeDef(_, _, _, _) =>
+ case TypeDef(_, _, _, _) =>
validateVariance(sym, sym.info, CoVariance)
case Template(_, _, _) =>
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index a72afdd642..b80170a302 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -403,7 +403,7 @@ trait Typers { self: Analyzer =>
context.scope enter vparam.symbol
}
- def reenterTypeParams(tparams: List[AbsTypeDef]): List[Symbol] =
+ def reenterTypeParams(tparams: List[TypeDef]): List[Symbol] =
for (tparam <- tparams) yield {
context.scope enter tparam.symbol
tparam.symbol.deSkolemize
@@ -476,7 +476,6 @@ trait Typers { self: Analyzer =>
} else if ((mode & (EXPRmode | QUALmode)) == EXPRmode && !sym.isValue) { // (2)
errorTree(tree, sym+" is not a value")
} else {
- skolemizeIfExistential(tree, mode)
if (sym.isStable && pre.isStable && tree.tpe.symbol != ByNameParamClass &&
(isStableContext(tree, mode, pt) || sym.isModule && !sym.isMethod))
tree.setType(singleType(pre, sym))
@@ -484,14 +483,6 @@ trait Typers { self: Analyzer =>
}
}
- private def skolemizeIfExistential(tree: Tree, mode: int): Tree = {
- if ((mode & (EXPRmode | LHSmode)) == EXPRmode && tree.tpe.isInstanceOf[ExistentialType]) {
- tree setType tree.tpe.skolemizeExistential(context.owner, tree)
-// Console.println("skolemized "+tree+":"+tree.tpe);//DEBUG
- }
- tree
- }
-
/**
* @param tree ...
* @param mode ...
@@ -960,7 +951,7 @@ trait Typers { self: Analyzer =>
// attributes(cdef)
val clazz = cdef.symbol
reenterTypeParams(cdef.tparams)
- val tparams1 = List.mapConserve(cdef.tparams)(typedAbsTypeDef)
+ val tparams1 = List.mapConserve(cdef.tparams)(typedTypeDef)
val impl1 = newTyper(context.make(cdef.impl, clazz, newTemplateScope(cdef.impl, clazz)))
.typedTemplate(cdef.impl, parentTypes(cdef.impl))
val impl2 = addSyntheticMethods(impl1, clazz, context)
@@ -1165,7 +1156,7 @@ trait Typers { self: Analyzer =>
val meth = ddef.symbol
reenterTypeParams(ddef.tparams)
reenterValueParams(ddef.vparamss)
- val tparams1 = List.mapConserve(ddef.tparams)(typedAbsTypeDef)
+ val tparams1 = List.mapConserve(ddef.tparams)(typedTypeDef)
val vparamss1 = List.mapConserve(ddef.vparamss)(vparams1 =>
List.mapConserve(vparams1)(typedValDef))
var tpt1 = checkNoEscaping.privates(meth, typedType(ddef.tpt))
@@ -1196,24 +1187,18 @@ trait Typers { self: Analyzer =>
copy.DefDef(ddef, ddef.mods, ddef.name, tparams1, vparamss1, tpt1, rhs1) setType NoType
}
- def typedAbsTypeDef(tdef: AbsTypeDef): AbsTypeDef = {
+ def typedTypeDef(tdef: TypeDef): TypeDef = {
reenterTypeParams(tdef.tparams) // @M!
- val tparams1 = List.mapConserve(tdef.tparams)(typedAbsTypeDef) // @M!
- val lo1 = checkNoEscaping.privates(tdef.symbol, typedType(tdef.lo))
- val hi1 = checkNoEscaping.privates(tdef.symbol, typedType(tdef.hi))
- checkNonCyclic(tdef.symbol)
- if (!(lo1.tpe <:< hi1.tpe))
- error(tdef.pos,
- "lower bound "+lo1.tpe+" does not conform to upper bound "+hi1.tpe)
- copy.AbsTypeDef(tdef, tdef.mods, tdef.name, tparams1, lo1, hi1) setType NoType
- }
-
- def typedAliasTypeDef(tdef: AliasTypeDef): AliasTypeDef = {
- reenterTypeParams(tdef.tparams)
- val tparams1 = List.mapConserve(tdef.tparams)(typedAbsTypeDef)
+ val tparams1 = List.mapConserve(tdef.tparams)(typedTypeDef) // @M!
val rhs1 = checkNoEscaping.privates(tdef.symbol, typedType(tdef.rhs))
checkNonCyclic(tdef.symbol)
- copy.AliasTypeDef(tdef, tdef.mods, tdef.name, tparams1, rhs1) setType NoType
+ rhs1.tpe match {
+ case TypeBounds(lo1, hi1) =>
+ if (!(lo1 <:< hi1))
+ error(tdef.pos, "lower bound "+lo1+" does not conform to upper bound "+hi1)
+ case _ =>
+ }
+ copy.TypeDef(tdef, tdef.mods, tdef.name, tparams1, rhs1) setType NoType
}
private def enterLabelDef(stat: Tree) {
@@ -2508,7 +2493,7 @@ trait Typers { self: Analyzer =>
val sym: Symbol = tree.symbol
if (sym ne null) sym.initialize
//if (settings.debug.value && tree.isDef) log("typing definition of "+sym);//DEBUG
- tree match {
+ val result = tree match {
case PackageDef(name, stats) =>
val stats1 = newTyper(context.make(tree, sym.moduleClass, sym.info.decls))
.typedStats(stats, NoSymbol)
@@ -2526,11 +2511,8 @@ trait Typers { self: Analyzer =>
case ddef @ DefDef(_, _, _, _, _, _) =>
newTyper(makeNewScope(context, tree, sym)).typedDefDef(ddef)
- case tdef @ AbsTypeDef(_, _, _, _, _) =>
- newTyper(makeNewScope(context, tree, sym)).typedAbsTypeDef(tdef)
-
- case tdef @ AliasTypeDef(_, _, _, _) =>
- newTyper(makeNewScope(context, tree, sym)).typedAliasTypeDef(tdef)
+ case tdef @ TypeDef(_, _, _, _) =>
+ newTyper(makeNewScope(context, tree, sym)).typedTypeDef(tdef)
case ldef @ LabelDef(_, _, _) =>
labelTyper(ldef).typedLabelDef(ldef)
@@ -2625,7 +2607,7 @@ trait Typers { self: Analyzer =>
if ((mode & PATTERNmode) != 0) inferTypedPattern(tpt1.pos, tpt1.tpe, widen(pt))
else tpt1.tpe
//Console.println(typed pattern: "+tree+":"+", tp = "+tpt1.tpe+", pt = "+pt+" ==> "+owntype)//DEBUG
- skolemizeIfExistential(copy.Typed(tree, expr1, tpt1) setType owntype, mode)
+ copy.Typed(tree, expr1, tpt1) setType owntype
case TypeApply(fun, args) =>
// @M: kind-arity checking is done here and in adapt, full kind-checking is in checkKindBounds (in Infer)
@@ -2661,13 +2643,13 @@ trait Typers { self: Analyzer =>
}
//@M TODO: context.undetparams = undets_fun ?
- skolemizeIfExistential(typedTypeApply(fun1, args1), mode)
+ typedTypeApply(fun1, args1)
case Apply(Block(stats, expr), args) =>
typed1(atPos(tree.pos)(Block(stats, Apply(expr, args))), mode, pt)
case Apply(fun, args) =>
- skolemizeIfExistential(typedApply(fun, args), mode)
+ typedApply(fun, args)
case ApplyDynamic(qual, args) =>
val qual1 = typed(qual, AnyRefClass.tpe)
@@ -2724,8 +2706,10 @@ trait Typers { self: Analyzer =>
case AppliedTypeTree(tpt, args) =>
typedAppliedTypeTree(tpt, args)
- case WildcardTypeTree(lo, hi) =>
- tree setType mkTypeBounds(typedType(lo).tpe, typedType(hi).tpe)
+ case TypeBoundsTree(lo, hi) =>
+ val lo1 = typedType(lo)
+ val hi1 = typedType(hi)
+ copy.TypeBoundsTree(tree, lo1, hi1) setType mkTypeBounds(lo1.tpe, hi1.tpe)
case etpt @ ExistentialTypeTree(_, _) =>
newTyper(makeNewScope(context, tree, context.owner)).typedExistentialTypeTree(etpt)
@@ -2739,6 +2723,10 @@ trait Typers { self: Analyzer =>
case _ =>
throw new Error("unexpected tree: " + tree.getClass + "\n" + tree)//debug
}
+ if ((mode & (EXPRmode | LHSmode)) == EXPRmode && result.tpe.isInstanceOf[ExistentialType])
+ result setType result.tpe.skolemizeExistential(context.owner, result)
+ else
+ result
}
/**