summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler/scala/tools/nsc/Global.scala23
-rw-r--r--src/compiler/scala/tools/nsc/Settings.scala3
-rw-r--r--src/compiler/scala/tools/nsc/ast/Trees.scala23
-rwxr-xr-xsrc/compiler/scala/tools/nsc/ast/parser/Parsers.scala74
-rw-r--r--src/compiler/scala/tools/nsc/ast/parser/SyntaxAnalyzer.scala6
-rw-r--r--src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala152
-rwxr-xr-xsrc/compiler/scala/tools/nsc/interactive/Global.scala32
-rwxr-xr-xsrc/compiler/scala/tools/nsc/interactive/Positions.scala48
-rw-r--r--src/compiler/scala/tools/nsc/symtab/StdNames.scala2
-rw-r--r--src/compiler/scala/tools/nsc/transform/Erasure.scala2
-rw-r--r--src/compiler/scala/tools/nsc/transform/UnCurry.scala2
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/DeVirtualize.scala4
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Implicits.scala4
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Namers.scala19
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/RefChecks.scala2
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala2
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Unapplies.scala4
-rw-r--r--src/compiler/scala/tools/nsc/util/Position.scala24
-rw-r--r--src/library/scala/Array.scala7
-rw-r--r--src/library/scala/collection/mutable/LinkedHashMap.scala2
-rw-r--r--test/files/neg/bug1241.check5
-rw-r--r--test/files/neg/bug473.check2
-rw-r--r--test/files/neg/multi-array.check2
-rw-r--r--test/files/neg/t0345.check4
24 files changed, 251 insertions, 197 deletions
diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala
index e20770a13a..0cd9d46bd1 100644
--- a/src/compiler/scala/tools/nsc/Global.scala
+++ b/src/compiler/scala/tools/nsc/Global.scala
@@ -12,7 +12,7 @@ import java.nio.charset._
import compat.Platform.currentTime
import scala.tools.nsc.io.{SourceReader, AbstractFile}
import scala.tools.nsc.reporters._
-import scala.tools.nsc.util.{ClassPath, SourceFile, BatchSourceFile, OffsetPosition}
+import scala.tools.nsc.util.{ClassPath, SourceFile, BatchSourceFile, OffsetPosition, RangePosition}
import scala.collection.mutable.{HashSet, HashMap, ListBuffer}
@@ -31,9 +31,11 @@ import backend.jvm.GenJVM
import backend.msil.GenMSIL
import backend.opt.{Inliners, ClosureElimination, DeadCodeElimination}
import backend.icode.analysis._
+import interactive._
class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable
with CompilationUnits
+ with Positions
with Plugins
with PhaseAssembly
{
@@ -42,6 +44,7 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable
def this(reporter: Reporter) =
this(new Settings(err => reporter.error(null,err)),
reporter)
+
def this(settings: Settings) =
this(settings, new ConsoleReporter(settings))
@@ -134,7 +137,9 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable
/** Return a position correponding to tree startaing at `start`, with tip
* at `mid`, and ending at `end`. ^ batch mode errors point at tip.
*/
- def rangePos(source: SourceFile, start: Int, mid: Int, end: Int) = OffsetPosition(source, mid)
+ def rangePos(source: SourceFile, start: Int, point: Int, end: Int) =
+ if (settings.Yrangepos.value) new RangePosition(source, start, point, end)
+ else new OffsetPosition(source, point)
/** Called every time an AST node is succesfully typedchecked in typerPhase.
*/
@@ -144,6 +149,16 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable
*/
def registerContext(c: analyzer.Context) {}
+ /** Allow splits when positioning a tree */
+ def withSplitAllowed(op: => Tree) = {
+ splitAllowed = true
+ try {
+ op
+ } finally {
+ splitAllowed = false
+ }
+ }
+
// ------------------ Reporting -------------------------------------
import nsc.util.NoPosition
@@ -311,7 +326,7 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable
if (!cancelled(unit)) apply(unit)
currentRun.advanceUnit
} finally {
- assert(currentRun.currentUnit == unit)
+ //assert(currentRun.currentUnit == unit)
currentRun.currentUnit = unit0
}
}
@@ -882,7 +897,7 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable
def compileLate(unit: CompilationUnit) {
addUnit(unit)
var localPhase = firstPhase.asInstanceOf[GlobalPhase]
- while (localPhase != null && (localPhase.id < globalPhase.id || localPhase.id <= namerPhase.id) && !reporter.hasErrors) {
+ while (localPhase != null && (localPhase.id < globalPhase.id || localPhase.id <= namerPhase.id)/* && !reporter.hasErrors*/) {
val oldSource = reporter.getSource
reporter.setSource(unit.source)
atPhase(localPhase)(localPhase.applyPhase(unit))
diff --git a/src/compiler/scala/tools/nsc/Settings.scala b/src/compiler/scala/tools/nsc/Settings.scala
index f0515c27d3..d098989906 100644
--- a/src/compiler/scala/tools/nsc/Settings.scala
+++ b/src/compiler/scala/tools/nsc/Settings.scala
@@ -792,7 +792,8 @@ trait ScalacSettings {
List("no-cache", "mono-cache", "poly-cache", "invoke-dynamic"), "poly-cache") .
withHelpSyntax("-Ystruct-dispatch:<method>")
val Xwarndeadcode = BooleanSetting ("-Ywarn-dead-code", "Emit warnings for dead code")
- val specialize = BooleanSetting ("-Yspecialize", "Specialize generic code on types.")
+ val specialize = BooleanSetting ("-Yspecialize", "Specialize generic code on types.")
+ val Yrangepos = BooleanSetting ("-Yrangepos", "Use range positions for syntax trees.")
/**
* -P "Plugin" settings
diff --git a/src/compiler/scala/tools/nsc/ast/Trees.scala b/src/compiler/scala/tools/nsc/ast/Trees.scala
index 1abdc04ee2..79977d69bc 100644
--- a/src/compiler/scala/tools/nsc/ast/Trees.scala
+++ b/src/compiler/scala/tools/nsc/ast/Trees.scala
@@ -104,7 +104,7 @@ trait Trees {
}
val id = nodeCount
-// assert(id != 151)
+ //assert(id != 225)
nodeCount += 1
private var rawpos: Position = NoPosition
@@ -380,11 +380,11 @@ trait Trees {
* and value parameter fields.
* @return ...
*/
- def ClassDef(sym: Symbol, constrMods: Modifiers, vparamss: List[List[ValDef]], argss: List[List[Tree]], body: List[Tree]): ClassDef =
+ def ClassDef(sym: Symbol, constrMods: Modifiers, vparamss: List[List[ValDef]], argss: List[List[Tree]], body: List[Tree], superPos: Position): ClassDef =
ClassDef(sym,
Template(sym.info.parents map TypeTree,
if (sym.thisSym == sym || phase.erasedTypes) emptyValDef else ValDef(sym.thisSym),
- constrMods, vparamss, argss, body))
+ constrMods, vparamss, argss, body, superPos))
/** Singleton object definition
*
@@ -588,16 +588,16 @@ trait Trees {
* body
* }
*/
- def Template(parents: List[Tree], self: ValDef, constrMods: Modifiers, vparamss: List[List[ValDef]], argss: List[List[Tree]], body: List[Tree]): Template = {
+ def Template(parents: List[Tree], self: ValDef, constrMods: Modifiers, vparamss: List[List[ValDef]], argss: List[List[Tree]], body: List[Tree], superPos: Position): Template = {
/* Add constructor to template */
- // create parameters for <init>
+ // create parameters for <init> as synthetic trees.
var vparamss1 =
vparamss map (vps => vps.map { vd =>
atPos(vd) {
ValDef(
Modifiers(vd.mods.flags & (IMPLICIT | DEFAULTPARAM) | PARAM) withAnnotations vd.mods.annotations,
- vd.name, atPos(vd.tpt) { vd.tpt.syntheticDuplicate }, vd.rhs.syntheticDuplicate)
+ vd.name, vd.tpt.syntheticDuplicate, vd.rhs.syntheticDuplicate)
}})
val (edefs, rest) = body span treeInfo.isEarlyDef
val (evdefs, etdefs) = edefs partition treeInfo.isEarlyValDef
@@ -609,7 +609,7 @@ trait Trees {
(local, fld)
}
}
- val constrs =
+ val constrs = {
if (constrMods.isTrait) {
if (body forall treeInfo.isInterfaceMember) List()
else List(
@@ -619,11 +619,14 @@ trait Trees {
if (vparamss1.isEmpty ||
!vparamss1.head.isEmpty && (vparamss1.head.head.mods.flags & IMPLICIT) != 0)
vparamss1 = List() :: vparamss1;
- val superRef: Tree = Select(Super(nme.EMPTY.toTypeName, nme.EMPTY.toTypeName), nme.CONSTRUCTOR)
+ val superRef: Tree = atPos(superPos) {
+ Select(Super(nme.EMPTY.toTypeName, nme.EMPTY.toTypeName), nme.CONSTRUCTOR)
+ }
val superCall = (superRef /: argss) (Apply)
List(
DefDef(constrMods, nme.CONSTRUCTOR, List(), vparamss1, TypeTree(), Block(lvdefs ::: List(superCall), Literal(()))))
}
+ }
// remove defaults
val vparamss2 = vparamss map (vps => vps map { vd =>
treeCopy.ValDef(vd, vd.mods &~ DEFAULTPARAM, vd.name, vd.tpt, EmptyTree)
@@ -866,6 +869,10 @@ trait Trees {
case class Annotated(annot: Tree, arg: Tree) extends Tree {
override def isType = arg.isType
override def isTerm = arg.isTerm
+ override def setPos(pos: Position) : this.type = {
+// assert(pos.start != 27934, this)
+ super.setPos(pos)
+ }
}
/** Singleton type, eliminated by RefCheck */
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
index 5b22914b23..e5eaf8a8e0 100755
--- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
+++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
@@ -160,6 +160,7 @@ self =>
object treeBuilder extends TreeBuilder {
val global: self.global.type = self.global
def freshName(prefix: String): Name = Parser.this.freshName(prefix)
+ def o2p(offset: Int) = Parser.this.o2p(offset)
}
import treeBuilder.{global => _, _}
@@ -338,9 +339,9 @@ self =>
ret
}
- def errorTypeTree = TypeTree().setType(ErrorType).setPos(o2p(in.offset))
- def errorTermTree = Literal(Constant(null)).setPos(o2p(in.offset))
- def errorPatternTree = Ident(nme.WILDCARD).setPos(o2p(in.offset))
+ def errorTypeTree = TypeTree().setType(ErrorType).setPos(o2p(in.offset).toSynthetic)
+ def errorTermTree = Literal(Constant(null)).setPos(o2p(in.offset).toSynthetic)
+ def errorPatternTree = Ident(nme.WILDCARD).setPos(o2p(in.offset).toSynthetic)
/** Check that type parameter is not by name T* */
def checkNotByName(t: Tree) = t match {
@@ -453,7 +454,7 @@ self =>
ValDef(Modifiers(Flags.PARAM), name, tpe, EmptyTree)
case _ =>
syntaxError(tree.pos, "not a legal formal parameter", false)
- ValDef(Modifiers(Flags.PARAM), nme.ERROR, errorTypeTree setPos o2p(tree.pos.end), EmptyTree)
+ ValDef(Modifiers(Flags.PARAM), nme.ERROR, errorTypeTree setPos o2p(tree.pos.end).toSynthetic, EmptyTree)
}
}
@@ -472,11 +473,11 @@ self =>
}
/** part {`,' part} */
- def commaSeparated(part: () => Tree): List[Tree] = {
- val ts = new ListBuffer[Tree] += part()
+ def commaSeparated(part: => Tree): List[Tree] = {
+ val ts = new ListBuffer[Tree] += part
while (in.token == COMMA) {
in.nextToken()
- ts += part()
+ ts += part
}
ts.toList
}
@@ -553,6 +554,7 @@ self =>
def selector(t: Tree): Tree = {
val point = in.offset
+ //assert(t.pos.isDefined, t)
Select(t, ident()) setPos r2p(t.pos.start, point, in.lastOffset)
}
@@ -700,7 +702,7 @@ self =>
/** Types ::= Type {`,' Type}
*/
def types(isPattern: Boolean, isTypeApply: Boolean, isFuncArg: Boolean): List[Tree] =
- commaSeparated(() => argType(isPattern, isTypeApply, isFuncArg))
+ commaSeparated(argType(isPattern, isTypeApply, isFuncArg))
/** Type ::= InfixType `=>' Type
* | `(' [`=>' Type] `)' `=>' Type
@@ -1173,7 +1175,7 @@ self =>
id
case LPAREN =>
atPos(in.skipToken()) {
- val ts = if (in.token == RPAREN) List() else commaSeparated(expr _)
+ val ts = if (in.token == RPAREN) List() else commaSeparated(expr)
accept(RPAREN)
Parens(ts)
}
@@ -1182,10 +1184,12 @@ self =>
blockExpr()
case NEW =>
canApply = false
- atPos(in.skipToken()) {
- val (parents, argss, self, stats) = template(false)
- makeNew(parents, self, stats, argss)
- }
+ val nstart = in.skipToken()
+ val npos = r2p(nstart, nstart, in.lastOffset)
+ val tstart = in.offset
+ val (parents, argss, self, stats) = template(false)
+ val cpos = r2p(tstart, tstart, in.lastOffset)
+ makeNew(parents, self, stats, argss, npos, cpos)
case _ =>
syntaxErrorOrIncomplete("illegal start of simple expression", true)
errorTermTree
@@ -1236,14 +1240,14 @@ self =>
* | [nl] BlockExpr
*/
def argumentExprs(): List[Tree] = {
- def args(): List[Tree] = commaSeparated(() => {
+ def args(): List[Tree] = commaSeparated {
val maybeNamed = isIdent
expr() match {
case a @ Assign(id, rhs) if maybeNamed =>
atPos(a.pos) { AssignOrNamedArg(id, rhs) }
case e => e
}
- })
+ }
// if arg has the form "x$1 => a = x$1" it's treated as "a = x$1" with x$1
// in placeholderParams. This allows e.g. "val f: Int => Int = foo(a = 1, b = _)"
@@ -1358,7 +1362,7 @@ self =>
* SeqPatterns ::= SeqPattern { `,' SeqPattern }
*/
def patterns(seqOK: Boolean): List[Tree] =
- commaSeparated(() => pattern(seqOK))
+ commaSeparated(pattern(seqOK))
/** Pattern ::= Pattern1 { `|' Pattern1 }
* SeqPattern ::= SeqPattern1 { `|' SeqPattern1 }
@@ -1827,7 +1831,7 @@ self =>
*/
def importClause(): List[Tree] = {
accept(IMPORT)
- commaSeparated(() => importExpr())
+ commaSeparated(importExpr())
}
/** ImportExpr ::= StableId `.' (Id | `_' | ImportSelectors)
@@ -1961,7 +1965,7 @@ self =>
} while (in.token == COMMA)
val lhs = lhsBuf.toList
val tp = typedOpt()
- var rhs =
+ val rhs =
if (tp.isEmpty || in.token == EQUALS) {
accept(EQUALS)
if (!tp.isEmpty && newmods.hasFlag(Flags.MUTABLE) &&
@@ -1976,12 +1980,13 @@ self =>
newmods = newmods | Flags.DEFERRED
EmptyTree
}
- def mkDefs(p: Tree): List[Tree] = {
+ def mkDefs(p: Tree, tp: Tree, rhs: Tree): List[Tree] = {
//Console.println("DEBUG: p = "+p.toString()); // DEBUG
val trees =
- makePatDef(newmods, if (tp.isEmpty) p else Typed(p, tp), rhs) map
- atPos(p.pos.start, p.pos.point)
- rhs = rhs.syntheticDuplicate
+ makePatDef(newmods,
+ if (tp.isEmpty) p
+ else Typed(p, tp) setPos (p.pos union tp.pos),
+ rhs)
if (newmods hasFlag Flags.DEFERRED) {
trees match {
case List(ValDef(_, _, _, EmptyTree)) =>
@@ -1991,7 +1996,7 @@ self =>
}
trees
}
- for (p <- lhs.toList; d <- mkDefs(p)) yield d
+ (lhs.toList.init flatMap (mkDefs(_, tp.syntheticDuplicate, rhs.syntheticDuplicate))) ::: mkDefs(lhs.last, tp, rhs)
}
/** VarDef ::= PatDef
@@ -2032,8 +2037,12 @@ self =>
atPos(start, in.skipToken()) {
val vparamss = paramClauses(nme.CONSTRUCTOR, implicitClassViews map (_.syntheticDuplicate), false)
newLineOptWhenFollowedBy(LBRACE)
- val rhs = if (in.token == LBRACE) constrBlock(vparamss)
- else { accept(EQUALS); constrExpr(vparamss) }
+ val rhs = if (in.token == LBRACE) {
+ atPos(in.offset) { constrBlock(vparamss) }
+ } else {
+ accept(EQUALS)
+ atPos(in.offset) { constrExpr(vparamss) }
+ }
DefDef(mods, nme.CONSTRUCTOR, List(), vparamss, TypeTree(), rhs)
}
} else {
@@ -2162,6 +2171,7 @@ self =>
val savedViews = implicitClassViews
val implicitViewBuf = new ListBuffer[Tree]
val tparams = typeParamClauseOpt(name, implicitViewBuf)
+ val tstart = in.offset
implicitClassViews = implicitViewBuf.toList
if (!implicitClassViews.isEmpty && mods.hasFlag(Flags.TRAIT)) {
syntaxError("traits cannot have type parameters with <% bounds", false)
@@ -2177,7 +2187,7 @@ self =>
} else if (in.token == SUBTYPE) {
syntaxError("classes are not allowed to be virtual", false)
}
- var template = templateOpt(mods1, name, constrMods withAnnotations constrAnnots, vparamss)
+ val template = templateOpt(mods1, name, constrMods withAnnotations constrAnnots, vparamss, tstart)
if (isInterface(mods1, template.body)) mods1 |= Flags.INTERFACE
val result = ClassDef(mods1, name, tparams, template)
implicitClassViews = savedViews
@@ -2191,9 +2201,10 @@ self =>
val start = in.skipToken()
val nameOffset = in.offset
val name = ident()
+ val tstart = in.offset
atPos(start, if (name == nme.ERROR) start else nameOffset) {
val mods1 = if (in.token == SUBTYPE) mods | Flags.DEFERRED else mods
- val template = templateOpt(mods1, name, NoMods, List())
+ val template = templateOpt(mods1, name, NoMods, List(), tstart)
ModuleDef(mods1, name, template)
}
}
@@ -2255,10 +2266,9 @@ self =>
/** ClassTemplateOpt ::= 'extends' ClassTemplate | [['extends'] TemplateBody]
* TraitTemplateOpt ::= TraitExtends TraitTemplate | [['extends'] TemplateBody] | '<:' TemplateBody
* TraitExtends ::= 'extends' | `<:'
- * @note leaves result unpositioned.
*/
def templateOpt(mods: Modifiers, name: Name, constrMods: Modifiers,
- vparamss: List[List[ValDef]]): Template = {
+ vparamss: List[List[ValDef]], tstart: Int): Template = {
val (parents0, argss, self, body) =
if (in.token == EXTENDS || settings.Xexperimental.value && (mods hasFlag Flags.TRAIT) && in.token == SUBTYPE) {
in.nextToken()
@@ -2277,7 +2287,9 @@ self =>
if (parents.isEmpty)
parents = List(scalaAnyRefConstr)
if (mods.hasFlag(Flags.CASE)) parents = parents ::: List(productConstr)
- Template(parents, self, constrMods, vparamss, argss, body)
+ atPos(tstart) {
+ Template(parents, self, constrMods, vparamss, argss, body, o2p(tstart).toSynthetic)
+ }
}
/* -------- TEMPLATES ------------------------------------------- */
@@ -2493,7 +2505,7 @@ self =>
stats ++= localDef
if (in.token == RBRACE || in.token == CASE) {
syntaxError("block must end in result expression, not in definition", false)
- stats += Literal(()).setPos(o2p(in.offset))
+ stats += Literal(()).setPos(o2p(in.offset).toSynthetic)
} else acceptStatSep()
} else if (isStatSep) {
in.nextToken()
diff --git a/src/compiler/scala/tools/nsc/ast/parser/SyntaxAnalyzer.scala b/src/compiler/scala/tools/nsc/ast/parser/SyntaxAnalyzer.scala
index 0e29853ade..874dd3cf8d 100644
--- a/src/compiler/scala/tools/nsc/ast/parser/SyntaxAnalyzer.scala
+++ b/src/compiler/scala/tools/nsc/ast/parser/SyntaxAnalyzer.scala
@@ -23,7 +23,11 @@ abstract class SyntaxAnalyzer extends SubComponent with Parsers with MarkupParse
unit.body =
if (unit.source.file.name.endsWith(".java")) new JavaUnitParser(unit).parse()
else if (!global.reporter.incompleteHandled) new UnitParser(unit).smartParse()
- else new UnitParser(unit).parse()
+ else {
+ val result = new UnitParser(unit).parse()
+ if (global.settings.Yrangepos.value) global.validatePositions(unit.body)
+ result
+ }
}
}
}
diff --git a/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala b/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala
index affe9efb3e..4ebacdd6bd 100644
--- a/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala
+++ b/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala
@@ -20,20 +20,15 @@ abstract class TreeBuilder {
def freshName(prefix: String): Name
def freshName(): Name = freshName("x$")
+ def o2p(offset: Int): Position
- /* These methods should probably be factored into a shared trait.
- * Be careful what you share between TreeGen and TreeBuilder!
- */
- def rootId = gen.rootId _
- def rootScalaDot = gen.rootScalaDot _
- def scalaDot = gen.scalaDot _
- def scalaAnyRefConstr = gen.scalaAnyRefConstr
- def scalaUnitConstr = gen.scalaUnitConstr
- def scalaScalaObjectConstr = gen.scalaScalaObjectConstr
- def productConstr = gen.productConstr
-
- /** Create a tree representing the function type (argtpes) => restpe */
- def makeFunctionTypeTree = gen.scalaFunctionConstr _
+ def rootId(name: Name) = gen.rootId(name)
+ def rootScalaDot(name: Name) = gen.rootScalaDot(name)
+ def scalaDot(name: Name) = gen.scalaDot(name)
+ def scalaAnyRefConstr = gen.scalaAnyRefConstr
+ def scalaUnitConstr = gen.scalaUnitConstr
+ def scalaScalaObjectConstr = gen.scalaScalaObjectConstr
+ def productConstr = gen.productConstr
/** Convert all occurrences of (lower-case) variables in a pattern as follows:
* x becomes x @ _
@@ -147,19 +142,31 @@ abstract class TreeBuilder {
}
}
- /** Create tree representing an object creation <new parents { stats }> */
- def makeNew(parents: List[Tree], self: ValDef, stats: List[Tree], argss: List[List[Tree]]): Tree =
+ /** Create positioned tree representing an object creation <new parents { stats }
+ * @param npos the position of the new
+ * @param cpos the position of the anonymous class startig with parents
+ */
+ def makeNew(parents: List[Tree], self: ValDef, stats: List[Tree], argss: List[List[Tree]],
+ npos: Position, cpos: Position): Tree =
if (parents.isEmpty)
- makeNew(List(scalaAnyRefConstr), self, stats, argss)
+ makeNew(List(scalaAnyRefConstr), self, stats, argss, npos, cpos)
else if (parents.tail.isEmpty && stats.isEmpty)
- New(parents.head, argss)
+ atPos(npos union cpos) { New(parents.head, argss) }
else {
val x = nme.ANON_CLASS_NAME.toTypeName
- Block(
- List(ClassDef(
- Modifiers(FINAL), x, Nil,
- Template(parents, self, NoMods, List(Nil), argss, stats))),
- New(Ident(x), List(Nil)))
+ atPos(npos union cpos) {
+ Block(
+ List(
+ atPos(cpos) {
+ ClassDef(
+ Modifiers(FINAL), x, Nil,
+ Template(parents, self, NoMods, List(Nil), argss, stats, cpos.toSynthetic))
+ }),
+ New(
+ Ident(x) setPos npos.toSynthetic,
+ List(Nil)) setPos npos
+ )
+ }
}
/** Create a tree represeting an assignment &lt;lhs = rhs&gt; */
@@ -177,7 +184,7 @@ abstract class TreeBuilder {
/** Create tree representing a while loop */
def makeWhile(lname: Name, cond: Tree, body: Tree): Tree = {
- val continu = Apply(Ident(lname), Nil)
+ val continu = atPos(o2p(body.pos.end)) { Apply(Ident(lname), Nil) }
val rhs = If(cond, Block(List(body), continu), Literal(()))
LabelDef(lname, Nil, rhs)
}
@@ -205,7 +212,7 @@ abstract class TreeBuilder {
case Some(_) =>
rhs
case None =>
- atPos(pos) {
+ atPos(rhs.pos) {
Apply(
Select(rhs, nme.filter),
List(
@@ -278,11 +285,13 @@ abstract class TreeBuilder {
*/
private def makeFor(mapName: Name, flatMapName: Name, enums: List[Enumerator], body: Tree): Tree = {
- def makeClosure(pat: Tree, body: Tree): Tree = matchVarPattern(pat) match {
- case Some((name, tpt)) =>
- Function(List(ValDef(Modifiers(PARAM), name, tpt, EmptyTree)), body)
- case None =>
- makeVisitor(List(CaseDef(pat, EmptyTree, body)), false)
+ def makeClosure(pat: Tree, body: Tree): Tree = {
+ matchVarPattern(pat) match {
+ case Some((name, tpt)) =>
+ Function(List(ValDef(Modifiers(PARAM), name, tpt, EmptyTree)), body)
+ case None =>
+ makeVisitor(List(CaseDef(pat, EmptyTree, body)), false)
+ }
}
def makeCombination(meth: Name, qual: Tree, pat: Tree, body: Tree): Tree =
@@ -302,35 +311,37 @@ abstract class TreeBuilder {
case Bind(name, _) => Ident(name)
}
- enums match {
- case ValFrom(pos, pat, rhs) :: Nil =>
- atPos(pos union body.pos) {
- makeCombination(mapName, rhs, pat, body)
- }
- case ValFrom(pos, pat, rhs) :: (rest @ (ValFrom(_, _, _) :: _)) =>
- atPos(pos union body.pos) {
- makeCombination(flatMapName, rhs, pat, makeFor(mapName, flatMapName, rest, body))
- }
- case ValFrom(pos, pat, rhs) :: Filter(_, test) :: rest =>
- makeFor(mapName, flatMapName,
- ValFrom(pos, pat, makeCombination(nme.filter, rhs, pat.syntheticDuplicate, test)) :: rest,
- body)
- case ValFrom(pos, pat, rhs) :: rest =>
- val valeqs = rest.take(definitions.MaxTupleArity - 1).takeWhile(_.isInstanceOf[ValEq]);
- assert(!valeqs.isEmpty)
- val rest1 = rest.drop(valeqs.length)
- val pats = valeqs map { case ValEq(_, pat, _) => pat }
- val rhss = valeqs map { case ValEq(_, _, rhs) => rhs }
- val defpats = pats map (x => makeBind(x.syntheticDuplicate))
- val pdefs = List.flatten(List.map2(defpats, rhss)(makePatDef))
- val patX1 = makeBind(pat.syntheticDuplicate);
- val ids = (patX1 :: defpats) map makeValue
- val rhs1 = makeForYield(
- List(ValFrom(pos, patX1, rhs)),
- Block(pdefs, makeTupleTerm(ids, true)))
- makeFor(mapName, flatMapName, ValFrom(pos, makeTuple(pat :: pats, false), rhs1) :: rest1, body)
- case _ =>
- EmptyTree //may happen for erroneous input
+ withSplitAllowed {
+ enums match {
+ case ValFrom(pos, pat, rhs) :: Nil =>
+ atPos(pos union body.pos) {
+ makeCombination(mapName, rhs, pat, body)
+ }
+ case ValFrom(pos, pat, rhs) :: (rest @ (ValFrom(_, _, _) :: _)) =>
+ atPos(pos union body.pos) {
+ makeCombination(flatMapName, rhs, pat, makeFor(mapName, flatMapName, rest, body))
+ }
+ case ValFrom(pos, pat, rhs) :: Filter(_, test) :: rest =>
+ makeFor(mapName, flatMapName,
+ ValFrom(pos, pat, makeCombination(nme.filter, rhs, pat.syntheticDuplicate, test)) :: rest,
+ body)
+ case ValFrom(pos, pat, rhs) :: rest =>
+ val valeqs = rest.take(definitions.MaxTupleArity - 1).takeWhile(_.isInstanceOf[ValEq]);
+ assert(!valeqs.isEmpty)
+ val rest1 = rest.drop(valeqs.length)
+ val pats = valeqs map { case ValEq(_, pat, _) => pat }
+ val rhss = valeqs map { case ValEq(_, _, rhs) => rhs }
+ val defpats = pats map (x => makeBind(x.syntheticDuplicate))
+ val pdefs = List.flatten(List.map2(defpats, rhss)(makePatDef))
+ val patX1 = makeBind(pat.syntheticDuplicate);
+ val ids = (patX1 :: defpats) map makeValue
+ val rhs1 = makeForYield(
+ List(ValFrom(pos, patX1, rhs)),
+ Block(pdefs, makeTupleTerm(ids, true)))
+ makeFor(mapName, flatMapName, ValFrom(pos, makeTuple(pat :: pats, false), rhs1) :: rest1, body)
+ case _ =>
+ EmptyTree //may happen for erroneous input
+ }
}
}
@@ -376,14 +387,14 @@ abstract class TreeBuilder {
def makeVisitor(cases: List[CaseDef], checkExhaustive: Boolean): Tree =
makeVisitor(cases, checkExhaustive, "x$")
- private def makeUnchecked(expr: Tree): Tree = atPos(expr.pos) {
+ private def makeUnchecked(expr: Tree): Tree =
Annotated(New(scalaDot(definitions.UncheckedClass.name), List(Nil)), expr)
- }
/** Create visitor <x => x match cases> */
def makeVisitor(cases: List[CaseDef], checkExhaustive: Boolean, prefix: String): Tree = {
val x = freshName(prefix)
- val sel = if (checkExhaustive) Ident(x) else makeUnchecked(Ident(x))
+ val id = Ident(x)
+ val sel = if (checkExhaustive) id else makeUnchecked(id)
Function(List(makeSyntheticParam(x)), Match(sel, cases))
}
@@ -398,7 +409,9 @@ abstract class TreeBuilder {
/** Create tree for pattern definition <mods val pat0 = rhs> */
def makePatDef(mods: Modifiers, pat: Tree, rhs: Tree): List[Tree] = matchVarPattern(pat) match {
case Some((name, tpt)) =>
- List(ValDef(mods, name, tpt, rhs))
+ List(atPos(pat.pos union rhs.pos) {
+ ValDef(mods, name, tpt, rhs)
+ })
case None =>
// in case there is exactly one variable x_1 in pattern
@@ -423,11 +436,16 @@ abstract class TreeBuilder {
}
vars match {
case List((vname, tpt, pos)) =>
- List(ValDef(mods, vname, tpt, matchExpr))
+ List(atPos(pat.pos union rhs.pos) {
+ ValDef(mods, vname, tpt, matchExpr)
+ })
case _ =>
val tmp = freshName()
- val firstDef = ValDef(Modifiers(PRIVATE | LOCAL | SYNTHETIC | (mods.flags & LAZY)),
- tmp, TypeTree(), matchExpr)
+ val firstDef =
+ atPos(rhs.pos) {
+ ValDef(Modifiers(PRIVATE | LOCAL | SYNTHETIC | (mods.flags & LAZY)),
+ tmp, TypeTree(), matchExpr)
+ }
var cnt = 0
val restDefs = for ((vname, tpt, pos) <- vars) yield atPos(pos) {
cnt = cnt + 1
@@ -437,6 +455,10 @@ abstract class TreeBuilder {
}
}
+ /** Create a tree representing the function type (argtpes) => restpe */
+ def makeFunctionTypeTree(argtpes: List[Tree], restpe: Tree): Tree =
+ AppliedTypeTree(rootScalaDot(newTypeName("Function" + argtpes.length)), argtpes ::: List(restpe))
+
/** Append implicit view section if for `implicitViews' if nonempty */
def addImplicitViews(owner: Name, vparamss: List[List[ValDef]], implicitViews: List[Tree]): List[List[ValDef]] = {
val mods = Modifiers(if (owner.isTypeName) PARAMACCESSOR | LOCAL | PRIVATE else PARAM)
diff --git a/src/compiler/scala/tools/nsc/interactive/Global.scala b/src/compiler/scala/tools/nsc/interactive/Global.scala
index e6993f5000..68ae0f24a6 100755
--- a/src/compiler/scala/tools/nsc/interactive/Global.scala
+++ b/src/compiler/scala/tools/nsc/interactive/Global.scala
@@ -52,7 +52,6 @@ self =>
// ----------- Overriding hooks in nsc.Global -----------------------
- /** Create a RangePosition */
override def rangePos(source: SourceFile, start: Int, point: Int, end: Int) =
new RangePosition(source, start, point, end)
@@ -129,6 +128,7 @@ self =>
}
def debugInfo(source : SourceFile, start : Int, length : Int): String = {
+ println("DEBUG INFO "+source+"/"+start+"/"+length)
val end = start+length
val pos = rangePos(source, start, start, end)
@@ -180,6 +180,7 @@ self =>
;
case ex =>
ex.printStackTrace()
+ outOfDate = false
inform("Fatal Error: "+ex)
compileRunner = newRunnerThread
}
@@ -216,6 +217,7 @@ self =>
def parse(unit: RichCompilationUnit): Unit = {
currentTyperRun.compileLate(unit)
validatePositions(unit.body)
+ println("parsed: [["+unit.body+"]]")
unit.status = JustParsed
}
@@ -251,17 +253,20 @@ self =>
}
/** Make sure a set of compilation units is loaded and parsed */
- def reload(sources: List[SourceFile], result: Response[Unit]) {
- respond(result) {
- currentTyperRun = new TyperRun()
- for (source <- sources) {
- val unit = new RichCompilationUnit(source)
- unitOfFile(source.file) = unit
- parse(unit)
- if (settings.Xprintpos.value) treePrinter.print(unit)
- }
- moveToFront(sources)
+ def reloadSources(sources: List[SourceFile]) {
+ currentTyperRun = new TyperRun()
+ for (source <- sources) {
+ val unit = new RichCompilationUnit(source)
+ unitOfFile(source.file) = unit
+ parse(unit)
+ if (settings.Xprintpos.value) treePrinter.print(unit)
}
+ moveToFront(sources)
+ }
+
+ /** Make sure a set of compilation units is loaded and parsed */
+ def reload(sources: List[SourceFile], result: Response[Unit]) {
+ respond(result)(reloadSources(sources))
if (outOfDate) throw new FreshRunReq
else outOfDate = true
}
@@ -269,8 +274,9 @@ self =>
/** A fully attributed tree located at position `pos` */
def typedTreeAt(pos: Position): Tree = {
val unit = unitOf(pos)
- assert(unit.status != NotLoaded)
- moveToFront(List(unit.source))
+ val sources = List(unit.source)
+ if (unit.status == NotLoaded) reloadSources(sources)
+ moveToFront(sources)
val typedTree = currentTyperRun.typedTreeAt(pos)
new Locator(pos) locateIn typedTree
}
diff --git a/src/compiler/scala/tools/nsc/interactive/Positions.scala b/src/compiler/scala/tools/nsc/interactive/Positions.scala
index 213ea44d42..0f8124f630 100755
--- a/src/compiler/scala/tools/nsc/interactive/Positions.scala
+++ b/src/compiler/scala/tools/nsc/interactive/Positions.scala
@@ -22,9 +22,9 @@ import scala.collection.mutable.ListBuffer
* Otherwise, the singleton consisting of the node itself.
*/
trait Positions extends Trees {
-self: Global =>
+self: nsc.Global =>
- case class Range(val pos: Position, val tree: Tree) {
+ case class Range(pos: Position, tree: Tree) {
def isFree = tree == EmptyTree
}
@@ -36,12 +36,7 @@ self: Global =>
def isRange(pos: Position) = pos.isInstanceOf[RangePosition]
- def isPositionable(tree: Tree) = tree match {
- case EmptyTree => false
- case `emptyValDef` => false
- case TypeTree() => tree.tpe != NoType
- case _ => true
- }
+ protected var splitAllowed = false
// -------------- ensuring no overlaps -------------------------------
@@ -89,6 +84,11 @@ self: Global =>
*/
def ensureNonOverlapping(cts: List[Tree]): Unit = {
+ def isSplittable(node: Tree) = node match {
+ case Function(_, _) | CaseDef(_, _, _) | Match(_, _) => true
+ case _ => false
+ }
+
/** Do a pass over all child trees `cts`, where `ranges` reflects positions previously
* encountered. If there are overlaps, break up one node by making its position a TransparentPosition
* and do another pass of `ensureOverlapping`.
@@ -113,8 +113,17 @@ self: Global =>
iterate(ranges1, trees1)
} else {
val splitNode =
- if (conflicting.size == 1 && (conflicting.head.pos includes tree.pos)) conflicting.head
- else tree
+ if (conflicting.size == 1 && (conflicting.head.pos includes tree.pos)) {
+ println("*** splitting \n"+conflicting.head+"\n--- because it conflicts with ---\n"+tree)
+ println(tree.id)
+ conflicting.head
+ } else {
+ println("*** splitting \n"+tree+"\n--- because it conflicts with trees in ---\n"+conflicting)
+ println(tree.id)
+ tree
+ }
+ //if (!splitAllowed && !isSplittable(splitNode)) throw new Error()//debug
+
// println("splitting "+splitNode)
splitNode setPos new TransparentPosition(splitNode.pos.source.get, splitNode.pos.start, splitNode.pos.point, splitNode.pos.end)
ensureNonOverlapping(replace(cts, splitNode, solidDescendants(splitNode)))
@@ -150,10 +159,10 @@ self: Global =>
private def setChildrenPos(pos: Position, trees: List[Tree]): Unit = try {
var remainingRange = pos
for (tree <- trees) {
- if (tree.pos == NoPosition) {
- val children = tree.children filter isPositionable
+ if (!tree.isEmpty && tree.pos == NoPosition) {
+ val children = tree.children filter (c => !c.isEmpty && !c.pos.isSynthetic)
if (children.isEmpty) {
- tree setPos OffsetPosition(pos.source.get, remainingRange.start)
+ tree setPos new OffsetPosition(pos.source.get, remainingRange.start)
} else {
setChildrenPos(remainingRange, children)
tree setPos new RangePosition(
@@ -174,12 +183,12 @@ self: Global =>
*/
override def atPos[T <: Tree](pos: Position)(tree: T): T =
if (isRange(pos)) {
- if (isPositionable(tree) && tree.pos == NoPosition) {
+ if (!tree.isEmpty && tree.pos == NoPosition) {
tree.setPos(pos)
val children = tree.children
if (children.nonEmpty) {
if (children.tail.isEmpty) atPos(pos)(children.head)
- else setChildrenPos(pos, children filter isPositionable)
+ else setChildrenPos(pos, children)
}
}
tree
@@ -198,15 +207,14 @@ self: Global =>
throw new ValidateError
}
def validate(tree: Tree, encltree: Tree): Unit = try {
- if (isPositionable(tree)) {
+ if (!tree.isEmpty) {
if (!tree.pos.isDefined)
error("tree without position["+tree.id+"]:"+tree)
- if (encltree.pos.isSynthetic) {
- if (!tree.pos.isSynthetic)
+ if (!tree.pos.isSynthetic) {
+ if (encltree.pos.isSynthetic)
error("synthetic "+encltree+" contains nonsynthetic["+tree.id+"] " + tree)
- } else {
if (!(encltree.pos includes tree.pos))
- error(encltree+" does not include["+tree.id+"] "+tree)
+ error(encltree+" does not include "+tree)
findOverlapping(tree.children flatMap solidDescendants) match {
case List() => ;
case xs => error("overlapping trees: "+xs)
diff --git a/src/compiler/scala/tools/nsc/symtab/StdNames.scala b/src/compiler/scala/tools/nsc/symtab/StdNames.scala
index 31650bb531..cc150d5809 100644
--- a/src/compiler/scala/tools/nsc/symtab/StdNames.scala
+++ b/src/compiler/scala/tools/nsc/symtab/StdNames.scala
@@ -311,6 +311,7 @@ trait StdNames {
val notify_ = newTermName("notify")
val notifyAll_ = newTermName("notifyAll")
val null_ = newTermName("null")
+ val ofDim = newTermName("ofDim")
val print = newTermName("print")
val productArity = newTermName("productArity")
val productElement = newTermName("productElement")
@@ -336,7 +337,6 @@ trait StdNames {
val value = newTermName("value")
val view_ = newTermName("view")
val wait_ = newTermName("wait")
- val withDims = newTermName("withDims")
val zip = newTermName("zip")
val ZAND = encode("&&")
diff --git a/src/compiler/scala/tools/nsc/transform/Erasure.scala b/src/compiler/scala/tools/nsc/transform/Erasure.scala
index ec720e90a8..19f1c737cc 100644
--- a/src/compiler/scala/tools/nsc/transform/Erasure.scala
+++ b/src/compiler/scala/tools/nsc/transform/Erasure.scala
@@ -560,7 +560,7 @@ abstract class Erasure extends AddInterfaces with typechecker.Analyzer with ast.
case Apply(Select(New(tpt), name), args) if (tpt.tpe.typeSymbol == BoxedArrayClass) =>
assert(name == nme.CONSTRUCTOR);
val translated: Tree =
- if (args.length >= 2) REF(ArrayModule) DOT nme.withDims
+ if (args.length >= 2) REF(ArrayModule) DOT nme.ofDim
else NEW(BoxedAnyArrayClass) DOT name
atPos(tree.pos) {
diff --git a/src/compiler/scala/tools/nsc/transform/UnCurry.scala b/src/compiler/scala/tools/nsc/transform/UnCurry.scala
index 6aa98bb6e9..abf80658a9 100644
--- a/src/compiler/scala/tools/nsc/transform/UnCurry.scala
+++ b/src/compiler/scala/tools/nsc/transform/UnCurry.scala
@@ -361,7 +361,7 @@ abstract class UnCurry extends InfoTransform with TypingTransformers {
localTyper.typed {
atPos(fun.pos) {
Block(
- List(ClassDef(anonClass, NoMods, List(List()), List(List()), members)),
+ List(ClassDef(anonClass, NoMods, List(List()), List(List()), members, fun.pos.toSynthetic)),
Typed(
New(TypeTree(anonClass.tpe), List(List())),
TypeTree(fun.tpe)))
diff --git a/src/compiler/scala/tools/nsc/typechecker/DeVirtualize.scala b/src/compiler/scala/tools/nsc/typechecker/DeVirtualize.scala
index c393617288..5bb1016412 100644
--- a/src/compiler/scala/tools/nsc/typechecker/DeVirtualize.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/DeVirtualize.scala
@@ -403,7 +403,9 @@ abstract class DeVirtualize extends InfoTransform with TypingTransformers {
}
}
}
- ClassDef(cclazz, Modifiers(0), vparamss, List(List()), pfields ::: overrideBridges)
+ atPos(clazz.pos) {
+ ClassDef(cclazz, Modifiers(0), vparamss, List(List()), pfields ::: overrideBridges, clazz.pos.toSynthetic)
+ }
}
diff --git a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala
index 27c94c0883..29c30bb285 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala
@@ -293,7 +293,7 @@ self: Analyzer =>
isCompatible(depoly(info.tpe), wildPt) &&
isStable(info.pre)) {
- val itree = atPos(tree.pos) {
+ val itree = atPos(tree) {
if (info.pre == NoPrefix) Ident(info.name)
else Select(gen.mkAttributedQualifier(info.pre), info.name)
}
@@ -595,7 +595,7 @@ self: Analyzer =>
def manifestFactoryCall(constructor: String, args: Tree*): Tree =
if (args contains EmptyTree) EmptyTree
else
- typed(atPos(tree.pos) {
+ typed(atPos(tree) {
Apply(
TypeApply(
Select(gen.mkAttributedRef(ManifestModule), constructor),
diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala
index 4b037533f6..0b95590aa3 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala
@@ -373,12 +373,12 @@ trait Namers { self: Analyzer =>
if (nme.isSetterName(name))
context.error(tree.pos, "Names of vals or vars may not end in `_='")
// .isInstanceOf[..]: probably for (old) IDE hook. is this obsolete?
- val getter = enterNewMethod(tree, name, accflags, mods).asInstanceOf[TermSymbol]
+ val getter = enterAliasMethod(tree, name, accflags, mods)
setInfo(getter)(namerOf(getter).getterTypeCompleter(vd))
if ((mods.flags & MUTABLE) != 0) {
- val setter = enterNewMethod(tree, nme.getterToSetter(name),
+ val setter = enterAliasMethod(tree, nme.getterToSetter(name),
accflags & ~STABLE & ~CASEACCESSOR,
- mods).asInstanceOf[TermSymbol]
+ mods)
setInfo(setter)(namerOf(setter).setterTypeCompleter(vd))
}
tree.symbol =
@@ -406,7 +406,7 @@ trait Namers { self: Analyzer =>
tree.symbol = enterInScope(sym)
finishWith(tparams)
case DefDef(mods, name, tparams, _, _, _) =>
- tree.symbol = enterNewMethod(tree, name, mods.flags, mods)
+ tree.symbol = enterNewMethod(tree, name, mods.flags, mods, tree.pos)
finishWith(tparams)
case TypeDef(mods, name, tparams, _) =>
var flags: Long = mods.flags
@@ -438,12 +438,16 @@ trait Namers { self: Analyzer =>
tree.symbol
}
- def enterNewMethod(tree: Tree, name: Name, flags: Long, mods: Modifiers) = {
- val sym = context.owner.newMethod(tree.pos, name).setFlag(flags)
+ def enterNewMethod(tree: Tree, name: Name, flags: Long, mods: Modifiers, pos: Position): TermSymbol = {
+ val sym = context.owner.newMethod(pos, name).setFlag(flags)
setPrivateWithin(tree, sym, mods)
enterInScope(sym)
+ sym
}
+ def enterAliasMethod(tree: Tree, name: Name, flags: Long, mods: Modifiers): TermSymbol =
+ enterNewMethod(tree, name, flags, mods, SyntheticAliasPosition(tree))
+
private def addBeanGetterSetter(vd: ValDef, getter: Symbol) {
def isAnn(ann: Tree, demand: String) = ann match {
case Apply(Select(New(Ident(name)), _), _) =>
@@ -482,7 +486,8 @@ trait Namers { self: Analyzer =>
// known. instead, uses the same machinery as for the non-bean setter:
// create and enter the symbol here, add the tree in Typer.addGettterSetter.
val setterName = "set" + beanName
- val setter = enterNewMethod(vd, setterName, flags, mods).asInstanceOf[TermSymbol]
+ val setter = enterAliasMethod(vd, setterName, flags, mods)
+ .setPos(SyntheticAliasPosition(vd))
setInfo(setter)(namerOf(setter).setterTypeCompleter(vd))
}
}
diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
index f9ad690472..4c2be9c247 100644
--- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
@@ -919,7 +919,7 @@ abstract class RefChecks extends InfoTransform {
case Apply(Select(New(tpt), name), args)
if (tpt.tpe.typeSymbol == ArrayClass && args.length >= 2) =>
unit.deprecationWarning(tree.pos,
- "new Array(...) with multiple dimensions has been deprecated; use Array.withDims(...) instead")
+ "new Array(...) with multiple dimensions has been deprecated; use Array.ofDim(...) instead")
currentApplication = tree
case Apply(fn, args) =>
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index c19cedfe75..2d2cec697a 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -3473,7 +3473,7 @@ trait Typers { self: Analyzer =>
//if (settings.debug.value && tree.isDef) log("typing definition of "+sym);//DEBUG
tree match {
case PackageDef(name, stats) =>
- assert(sym.moduleClass ne NoSymbol)
+ assert(sym.moduleClass ne NoSymbol, sym)
val stats1 = newTyper(context.make(tree, sym.moduleClass, sym.info.decls))
.typedStats(stats, NoSymbol)
treeCopy.PackageDef(tree, name, stats1) setType NoType
diff --git a/src/compiler/scala/tools/nsc/typechecker/Unapplies.scala b/src/compiler/scala/tools/nsc/typechecker/Unapplies.scala
index e499376068..fc20277c52 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Unapplies.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Unapplies.scala
@@ -135,11 +135,11 @@ trait Unapplies extends ast.TreeDSL
companionModuleDef(cdef, parents ::: List(gen.scalaScalaObjectConstr))
}
- def companionModuleDef(cdef: ClassDef, parents: List[Tree]): ModuleDef = atPos(cdef.pos) {
+ def companionModuleDef(cdef: ClassDef, parents: List[Tree]): ModuleDef = atPos(cdef) {
ModuleDef(
Modifiers(cdef.mods.flags & AccessFlags | SYNTHETIC, cdef.mods.privateWithin),
cdef.name.toTermName,
- Template(parents, emptyValDef, NoMods, Nil, List(Nil), Nil))
+ Template(parents, emptyValDef, NoMods, Nil, List(Nil), Nil, cdef.impl.pos.toSynthetic))
}
private val caseMods = Modifiers(SYNTHETIC | CASE)
diff --git a/src/compiler/scala/tools/nsc/util/Position.scala b/src/compiler/scala/tools/nsc/util/Position.scala
index 0f427420b8..9225dffd72 100644
--- a/src/compiler/scala/tools/nsc/util/Position.scala
+++ b/src/compiler/scala/tools/nsc/util/Position.scala
@@ -109,7 +109,7 @@ trait Position {
*/
def overlaps(pos: Position) =
isDefined && pos.isDefined &&
- (pos.start <= start && start < pos.end) || (start <= pos.start && pos.start < end)
+ (pos.start < end && start < pos.end) || (start < pos.end && pos.start < end)
/** Does this position cover the same range as that position?
*/
@@ -194,6 +194,7 @@ class SyntheticOffsetPosition(source0: SourceFile, offset0: Int) extends OffsetP
override def isSynthetic = true
override def toSynthetic = this
override def withPoint(off: Int) = new SyntheticOffsetPosition(source0, off)
+ override def show = "<["+point+"]>"
}
/** new for position ranges */
@@ -206,35 +207,16 @@ extends OffsetPosition(source0, point) {
override def withEnd(off: Int) = new RangePosition(source0, start, point, off)
override def withPoint(off: Int) = new RangePosition(source0, start, off, end)
override def union(pos: Position) =
- if (pos.isDefined) new RangePosition(source0, start min pos.start, point, end max pos.end)
+ if (pos.isDefined && !pos.isSynthetic) new RangePosition(source0, start min pos.start, point, end max pos.end)
else this
override def endOrElse(d: Int) = end
override def focusStart = OffsetPosition(source0, start)
override def focusPoint = OffsetPosition(source0, point)
override def focusEnd = OffsetPosition(source0, end)
- override def toSynthetic = new SyntheticRangePosition(source0, start, point, end)
override def toString = "RangePosition("+source0+", "+start+", "+point+", "+end+")"
override def show = "["+start+":"+end+"]"
}
-/** A position to be used for synthetic trees that do not correspond to some original tree
- * @note Trees with synthetic positions may not contain trees with real positions inside them!
- * todo: needed?
- */
-class SyntheticRangePosition(source0: SourceFile, start: Int, point: Int, end: Int) extends RangePosition(source0, start, point, end) {
- override def isSynthetic = true
- override def toSynthetic = this
- override def withStart(off: Int) = new SyntheticRangePosition(source0, off, point, end)
- override def withEnd(off: Int) = new SyntheticRangePosition(source0, start, point, off)
- override def withPoint(off: Int) = new SyntheticRangePosition(source0, start, off, end)
- override def union(pos: Position) =
- if (pos.isDefined) new SyntheticRangePosition(source0, start min pos.start, point, end max pos.end)
- else this
- override def focusStart = new SyntheticOffsetPosition(source0, start)
- override def focusPoint = new SyntheticOffsetPosition(source0, point)
- override def focusEnd = new SyntheticOffsetPosition(source0, end)
- override def show = "<["+start+":"+end+"]>"
-}
diff --git a/src/library/scala/Array.scala b/src/library/scala/Array.scala
index b72bdb01e7..7f42ada4b1 100644
--- a/src/library/scala/Array.scala
+++ b/src/library/scala/Array.scala
@@ -171,13 +171,6 @@ object Array extends SequenceFactory[Array] {
def ofDim[A](n1: Int, n2: Int, n3: Int, n4: Int, n5: Int): Array[Array[Array[Array[Array[A]]]]] =
tabulate(n1)(_ => ofDim[A](n2, n3, n4, n5))
- /** Create array with given dimensions */
- @deprecated("use `ofDim' instead") def withDims[A](n1: Int): Array[A] = ofDim(n1)
- @deprecated("use `ofDim' instead") def withDims[A](n1: Int, n2: Int): Array[Array[A]] = ofDim(n1, n2)
- @deprecated("use `ofDim' instead") def withDims[A](n1: Int, n2: Int, n3: Int): Array[Array[Array[A]]] = ofDim(n1, n2, n3)
- @deprecated("use `ofDim' instead") def withDims[A](n1: Int, n2: Int, n3: Int, n4: Int): Array[Array[Array[Array[A]]]] = ofDim(n1, n2, n3, n4)
- @deprecated("use `ofDim' instead") def withDims[A](n1: Int, n2: Int, n3: Int, n4: Int, n5: Int): Array[Array[Array[Array[Array[A]]]]] = ofDim(n1, n2, n3, n4, n5)
-
/** Create an array containing several copies of an element.
*
* @param n the length of the resulting array
diff --git a/src/library/scala/collection/mutable/LinkedHashMap.scala b/src/library/scala/collection/mutable/LinkedHashMap.scala
index fb19a7e84e..4a64b9e8ce 100644
--- a/src/library/scala/collection/mutable/LinkedHashMap.scala
+++ b/src/library/scala/collection/mutable/LinkedHashMap.scala
@@ -94,7 +94,7 @@ class LinkedHashMap[A, B] extends Map[A, B]
override def valuesIterator: Iterator[B] = new Iterator[B] {
private var cur = firstEntry
def hasNext = cur ne null
- def next = { val res = cur.value; cur = cur.later; res }
+ def next =
if (hasNext) { val res = cur.value; cur = cur.later; res }
else Iterator.empty.next
}
diff --git a/test/files/neg/bug1241.check b/test/files/neg/bug1241.check
index 2a892a274c..48c86cabb7 100644
--- a/test/files/neg/bug1241.check
+++ b/test/files/neg/bug1241.check
@@ -1,7 +1,4 @@
bug1241.scala:5: error: class type required but AnyRef{def hello(): Unit} found
val x4 = new T { def hello() { println("4") } } // error!
^
-bug1241.scala:5: error: AnyRef{def hello(): Unit} does not have a constructor
- val x4 = new T { def hello() { println("4") } } // error!
- ^
-two errors found
+one error found
diff --git a/test/files/neg/bug473.check b/test/files/neg/bug473.check
index c7d54fc4b3..7d21dfb210 100644
--- a/test/files/neg/bug473.check
+++ b/test/files/neg/bug473.check
@@ -1,4 +1,4 @@
bug473.scala:3: error: super constructor cannot be passed a self reference unless parameter is declared by-name
case object Voop extends Foo(Voop)
- ^
+ ^
one error found
diff --git a/test/files/neg/multi-array.check b/test/files/neg/multi-array.check
index 8af656ab6b..49ffdefbf7 100644
--- a/test/files/neg/multi-array.check
+++ b/test/files/neg/multi-array.check
@@ -1,4 +1,4 @@
-multi-array.scala:6: warning: new Array(...) with multiple dimensions has been deprecated; use Array.withDims(...) instead
+multi-array.scala:6: warning: new Array(...) with multiple dimensions has been deprecated; use Array.ofDim(...) instead
val a: Array[Int] = new Array(10, 10)
^
multi-array.scala:6: error: too many arguments for array constructor: found 2 but array has only 1 dimension(s)
diff --git a/test/files/neg/t0345.check b/test/files/neg/t0345.check
index cf1d330360..1e55d01cd1 100644
--- a/test/files/neg/t0345.check
+++ b/test/files/neg/t0345.check
@@ -1,4 +1,4 @@
t0345.scala:2: error: object creation impossible, since method cons in trait Lizt of type (a: Nothing)Unit is not defined
- val empty = new Lizt[Nothing] {
- ^
+ val empty = new Lizt[Nothing] {
+ ^
one error found