diff options
Diffstat (limited to 'src')
6 files changed, 109 insertions, 93 deletions
diff --git a/src/compiler/scala/tools/nsc/doc/html/page/Template.scala b/src/compiler/scala/tools/nsc/doc/html/page/Template.scala index e885e9c56e..ea07ff29c4 100644 --- a/src/compiler/scala/tools/nsc/doc/html/page/Template.scala +++ b/src/compiler/scala/tools/nsc/doc/html/page/Template.scala @@ -335,12 +335,10 @@ class Template(universe: doc.Universe, generator: DiagramGenerator, tpl: DocTemp } } - def memberToShortCommentHtml(mbr: MemberEntity, isSelf: Boolean): NodeSeq = { - if (mbr.comment.isEmpty) - NodeSeq.Empty - else - <p class="shortcomment cmt">{ memberToUseCaseCommentHtml(mbr, isSelf) }{ inlineToHtml(mbr.comment.get.short) }</p> - } + def memberToShortCommentHtml(mbr: MemberEntity, isSelf: Boolean): NodeSeq = + mbr.comment.fold(NodeSeq.Empty) { comment => + <p class="shortcomment cmt">{ memberToUseCaseCommentHtml(mbr, isSelf) }{ inlineToHtml(comment.short) }</p> + } def memberToInlineCommentHtml(mbr: MemberEntity, isSelf: Boolean): NodeSeq = <p class="comment cmt">{ inlineToHtml(mbr.comment.get.short) }</p> @@ -361,37 +359,34 @@ class Template(universe: doc.Universe, generator: DiagramGenerator, tpl: DocTemp case _ => Nil } - def mbrCmt = mbr.comment.get - - def paramCommentToHtml(prs: List[ParameterEntity]): NodeSeq = prs match { + def paramCommentToHtml(prs: List[ParameterEntity], comment: Comment): NodeSeq = prs match { case (tp: TypeParam) :: rest => val paramEntry: NodeSeq = { - <dt class="tparam">{ tp.name }</dt><dd class="cmt">{ bodyToHtml(mbrCmt.typeParams(tp.name)) }</dd> + <dt class="tparam">{ tp.name }</dt><dd class="cmt">{ bodyToHtml(comment.typeParams(tp.name)) }</dd> } - paramEntry ++ paramCommentToHtml(rest) + paramEntry ++ paramCommentToHtml(rest, comment) case (vp: ValueParam) :: rest => val paramEntry: NodeSeq = { - <dt class="param">{ vp.name }</dt><dd class="cmt">{ bodyToHtml(mbrCmt.valueParams(vp.name)) }</dd> + <dt class="param">{ vp.name }</dt><dd class="cmt">{ bodyToHtml(comment.valueParams(vp.name)) }</dd> } - paramEntry ++ paramCommentToHtml(rest) + paramEntry ++ paramCommentToHtml(rest, comment) case _ => NodeSeq.Empty } - if (mbr.comment.isEmpty) NodeSeq.Empty - else { + mbr.comment.fold(NodeSeq.Empty) { comment => val cmtedPrs = prs filter { - case tp: TypeParam => mbrCmt.typeParams isDefinedAt tp.name - case vp: ValueParam => mbrCmt.valueParams isDefinedAt vp.name + case tp: TypeParam => comment.typeParams isDefinedAt tp.name + case vp: ValueParam => comment.valueParams isDefinedAt vp.name } - if (cmtedPrs.isEmpty && mbrCmt.result.isEmpty) NodeSeq.Empty + if (cmtedPrs.isEmpty && comment.result.isEmpty) NodeSeq.Empty else { <dl class="paramcmts block">{ - paramCommentToHtml(cmtedPrs) ++ ( - mbrCmt.result match { + paramCommentToHtml(cmtedPrs, comment) ++ ( + comment.result match { case None => NodeSeq.Empty case Some(cmt) => <dt>returns</dt><dd class="cmt">{ bodyToHtml(cmt) }</dd> @@ -470,7 +465,7 @@ class Template(universe: doc.Universe, generator: DiagramGenerator, tpl: DocTemp } // --- start attributes block vals - val attributes: Seq[scala.xml.Node] = { + val attributes: NodeSeq = { val fvs: List[comment.Paragraph] = visibility(mbr).toList if (fvs.isEmpty || isReduced) NodeSeq.Empty else { @@ -479,7 +474,7 @@ class Template(universe: doc.Universe, generator: DiagramGenerator, tpl: DocTemp } } - val definitionClasses: Seq[scala.xml.Node] = { + val definitionClasses: NodeSeq = { val inDefTpls = mbr.inDefinitionTemplates if ((inDefTpls.tail.isEmpty && (inDefTpls.head == inTpl)) || isReduced) NodeSeq.Empty else { @@ -488,7 +483,7 @@ class Template(universe: doc.Universe, generator: DiagramGenerator, tpl: DocTemp } } - val fullSignature: Seq[scala.xml.Node] = { + val fullSignature: NodeSeq = { mbr match { case nte: NonTemplateMemberEntity if nte.isUseCase => <div class="full-signature-block toggleContainer"> @@ -499,14 +494,14 @@ class Template(universe: doc.Universe, generator: DiagramGenerator, tpl: DocTemp } } - val selfType: Seq[scala.xml.Node] = mbr match { + val selfType: NodeSeq = mbr match { case dtpl: DocTemplateEntity if (isSelf && !dtpl.selfType.isEmpty && !isReduced) => <dt>Self Type</dt> <dd>{ typeToHtml(dtpl.selfType.get, hasLinks = true) }</dd> case _ => NodeSeq.Empty } - val annotations: Seq[scala.xml.Node] = { + val annotations: NodeSeq = { // A list of annotations which don't show their arguments, e. g. because they are shown separately. val annotationsWithHiddenArguments = List("deprecated", "Deprecated", "migration") @@ -528,7 +523,7 @@ class Template(universe: doc.Universe, generator: DiagramGenerator, tpl: DocTemp } else NodeSeq.Empty } - val sourceLink: Seq[scala.xml.Node] = mbr match { + val sourceLink: NodeSeq = mbr match { case dtpl: DocTemplateEntity if (isSelf && dtpl.sourceUrl.isDefined && dtpl.inSource.isDefined && !isReduced) => val (absFile, line) = dtpl.inSource.get <dt>Source</dt> @@ -536,83 +531,87 @@ class Template(universe: doc.Universe, generator: DiagramGenerator, tpl: DocTemp case _ => NodeSeq.Empty } - val deprecation: Seq[scala.xml.Node] = - if (mbr.deprecation.isEmpty || isReduced) NodeSeq.Empty - else { - <dt>Deprecated</dt> - <dd class="cmt">{ bodyToHtml(mbr.deprecation.get) }</dd> + val deprecation: NodeSeq = + mbr.deprecation match { + case Some(deprecation) if !isReduced => + <dt>Deprecated</dt> + <dd class="cmt">{ bodyToHtml(deprecation) }</dd> + case _ => NodeSeq.Empty } - val migration: Seq[scala.xml.Node] = - if(mbr.migration.isEmpty || isReduced) NodeSeq.Empty - else { + val migration: NodeSeq = + mbr.migration match { + case Some(migration) if !isReduced => <dt>Migration</dt> - <dd class="cmt">{ bodyToHtml(mbr.migration.get) }</dd> + <dd class="cmt">{ bodyToHtml(migration) }</dd> + case _ => NodeSeq.Empty } - val mainComment: Seq[scala.xml.Node] = mbr.comment match { + val mainComment: NodeSeq = mbr.comment match { case Some(comment) if (! isReduced) => + def orEmpty[T](it: Iterable[T])(gen: =>NodeSeq): NodeSeq = + if (it.isEmpty) NodeSeq.Empty else gen + val example = - if(!comment.example.isEmpty) + orEmpty(comment.example) { <div class="block">Example{ if (comment.example.length > 1) "s" else ""}: - <ol>{ - val exampleXml: List[scala.xml.NodeSeq] = - for(example <- comment.example ) yield - <li class="cmt">{ bodyToHtml(example) }</li> - exampleXml.reduceLeft(_ ++ Text(", ") ++ _) + <ol>{ + val exampleXml: List[NodeSeq] = for (ex <- comment.example) yield + <li class="cmt">{ bodyToHtml(ex) }</li> + exampleXml.reduceLeft(_ ++ Text(", ") ++ _) }</ol> - </div> - else NodeSeq.Empty + </div> + } - val version: Seq[scala.xml.Node] = - if(!comment.version.isEmpty) { + val version: NodeSeq = + orEmpty(comment.version) { <dt>Version</dt> - <dd>{ for(body <- comment.version.toList) yield {bodyToHtml(body)} }</dd> - } else NodeSeq.Empty + <dd>{ for(body <- comment.version.toList) yield bodyToHtml(body) }</dd> + } - val sinceVersion: Seq[scala.xml.Node] = - if(!comment.since.isEmpty) { + val sinceVersion: NodeSeq = + orEmpty(comment.since) { <dt>Since</dt> - <dd>{ for(body <- comment.since.toList) yield {bodyToHtml(body)} }</dd> - } else NodeSeq.Empty + <dd>{ for(body <- comment.since.toList) yield bodyToHtml(body) }</dd> + } - val note: Seq[scala.xml.Node] = - if(!comment.note.isEmpty) { + val note: NodeSeq = + orEmpty(comment.note) { <dt>Note</dt> <dd>{ - val noteXml: List[scala.xml.NodeSeq] = (for(note <- comment.note ) yield <span class="cmt">{bodyToHtml(note)}</span> ) + val noteXml: List[NodeSeq] = for(note <- comment.note ) yield <span class="cmt">{bodyToHtml(note)}</span> noteXml.reduceLeft(_ ++ Text(", ") ++ _) }</dd> - } else NodeSeq.Empty + } - val seeAlso: Seq[scala.xml.Node] = - if(!comment.see.isEmpty) { + val seeAlso: NodeSeq = + orEmpty(comment.see) { <dt>See also</dt> <dd>{ - val seeXml:List[scala.xml.NodeSeq]=(for(see <- comment.see ) yield <span class="cmt">{bodyToHtml(see)}</span> ) + val seeXml: List[NodeSeq] = for(see <- comment.see ) yield <span class="cmt">{bodyToHtml(see)}</span> seeXml.reduceLeft(_ ++ _) }</dd> - } else NodeSeq.Empty + } - val exceptions: Seq[scala.xml.Node] = - if(!comment.throws.isEmpty) { + val exceptions: NodeSeq = + orEmpty(comment.throws) { <dt>Exceptions thrown</dt> <dd>{ - val exceptionsXml: Iterable[scala.xml.NodeSeq] = - for(exception <- comment.throws.toList.sortBy(_._1) ) yield - <span class="cmt">{Text(exception._1) ++ bodyToHtml(exception._2)}</span> + val exceptionsXml: List[NodeSeq] = + for((name, body) <- comment.throws.toList.sortBy(_._1) ) yield + <span class="cmt">{Text(name) ++ bodyToHtml(body)}</span> exceptionsXml.reduceLeft(_ ++ Text("") ++ _) }</dd> - } else NodeSeq.Empty + } - val todo: Seq[scala.xml.Node] = - if(!comment.todo.isEmpty) { + val todo: NodeSeq = + orEmpty(comment.todo) { <dt>To do</dt> <dd>{ - val todoXml: List[scala.xml.NodeSeq] = (for(todo <- comment.todo ) yield <span class="cmt">{bodyToHtml(todo)}</span> ) + val todoXml: List[NodeSeq] = (for(todo <- comment.todo ) yield <span class="cmt">{bodyToHtml(todo)}</span> ) todoXml.reduceLeft(_ ++ Text(", ") ++ _) }</dd> - } else NodeSeq.Empty + } example ++ version ++ sinceVersion ++ exceptions ++ todo ++ note ++ seeAlso diff --git a/src/compiler/scala/tools/nsc/interactive/Global.scala b/src/compiler/scala/tools/nsc/interactive/Global.scala index 0fc4fcaaf7..4ab7b98b3d 100644 --- a/src/compiler/scala/tools/nsc/interactive/Global.scala +++ b/src/compiler/scala/tools/nsc/interactive/Global.scala @@ -56,7 +56,6 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "") import log.logreplay debugLog("logger: " + log.getClass + " writing to " + (new java.io.File(logName)).getAbsolutePath) debugLog("classpath: "+classPath) - Console.err.println("\n ======= CHECK THREAD ACCESS compiler build ========\n") private var curTime = System.nanoTime private def timeStep = { diff --git a/src/compiler/scala/tools/nsc/interpreter/TypeStrings.scala b/src/compiler/scala/tools/nsc/interpreter/TypeStrings.scala index 6abb52a649..60399f53bf 100644 --- a/src/compiler/scala/tools/nsc/interpreter/TypeStrings.scala +++ b/src/compiler/scala/tools/nsc/interpreter/TypeStrings.scala @@ -212,7 +212,11 @@ trait TypeStrings { } private def tparamString[T: ru.TypeTag] : String = { - def typeArguments: List[ru.Type] = ru.typeOf[T] match { case ru.TypeRef(_, _, args) => args; case _ => Nil } + def typeArguments: List[ru.Type] = { + import ru.TypeRefTag // otherwise the pattern match will be unchecked + // because TypeRef is an abstract type + ru.typeOf[T] match { case ru.TypeRef(_, _, args) => args; case _ => Nil } + } // [Eugene to Paul] need to use not the `rootMirror`, but a mirror with the REPL's classloader // how do I get to it? acquiring context classloader seems unreliable because of multithreading def typeVariables: List[java.lang.Class[_]] = typeArguments map (targ => ru.rootMirror.runtimeClass(targ)) diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index f8adcaa25b..9d390476db 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -3497,12 +3497,13 @@ trait Typers extends Modes with Adaptations with Tags { // println(util.Position.formatMessage(uncheckedPattern.pos, "made unchecked type test into a checked one", true)) val args = List(uncheckedPattern) + val app = atPos(uncheckedPattern.pos)(Apply(classTagExtractor, args)) // must call doTypedUnapply directly, as otherwise we get undesirable rewrites // and re-typechecks of the target of the unapply call in PATTERNmode, // this breaks down when the classTagExtractor (which defineds the unapply member) is not a simple reference to an object, // but an arbitrary tree as is the case here - doTypedUnapply(Apply(classTagExtractor, args), classTagExtractor, classTagExtractor, args, PATTERNmode, pt) - } + doTypedUnapply(app, classTagExtractor, classTagExtractor, args, PATTERNmode, pt) + } // if there's a ClassTag that allows us to turn the unchecked type test for `pt` into a checked type test // return the corresponding extractor (an instance of ClassTag[`pt`]) @@ -4646,12 +4647,11 @@ trait Typers extends Modes with Adaptations with Tags { // [Eugene] no more MaxArrayDims. ClassTags are flexible enough to allow creation of arrays of arbitrary dimensionality (w.r.t JVM restrictions) val Some((level, componentType)) = erasure.GenericArray.unapply(tpt.tpe) val tagType = List.iterate(componentType, level)(tpe => appliedType(ArrayClass.toTypeConstructor, List(tpe))).last - val newArrayApp = atPos(tree.pos) { + atPos(tree.pos) { val tag = resolveClassTag(tree.pos, tagType) if (tag.isEmpty) MissingClassTagError(tree, tagType) - else new ApplyToImplicitArgs(Select(tag, nme.newArray), args) + else typed(new ApplyToImplicitArgs(Select(tag, nme.newArray), args)) } - typed(newArrayApp, mode, pt) case Apply(Select(fun, nme.apply), _) if treeInfo.isSuperConstrCall(fun) => //SI-5696 TooManyArgumentListsForConstructor(tree) case tree1 => @@ -5264,7 +5264,7 @@ trait Typers extends Modes with Adaptations with Tags { def typedDocDef(docdef: DocDef) = { if (forScaladoc && (sym ne null) && (sym ne NoSymbol)) { - val comment = docdef.comment + val comment = docdef.comment docComments(sym) = comment comment.defineVariables(sym) val typer1 = newTyper(context.makeNewScope(tree, context.owner)) @@ -5595,12 +5595,18 @@ trait Typers extends Modes with Adaptations with Tags { "context.owner" -> context.owner ) ) - val tree1 = typed1(tree, mode, dropExistential(pt)) + typed1(tree, mode, dropExistential(pt)) + } + // Can happen during erroneous compilation - error(s) have been + // reported, but we need to avoid causing an NPE with this tree + if (tree1.tpe eq null) + return setError(tree) + + if (!alreadyTyped) { printTyping("typed %s: %s%s".format( ptTree(tree1), tree1.tpe, if (isSingleType(tree1.tpe)) " with underlying "+tree1.tpe.widen else "") ) - tree1 } tree1.tpe = addAnnotations(tree1, tree1.tpe) diff --git a/src/library/scala/collection/LinearSeqOptimized.scala b/src/library/scala/collection/LinearSeqOptimized.scala index 0f0a405a85..81cccea519 100755 --- a/src/library/scala/collection/LinearSeqOptimized.scala +++ b/src/library/scala/collection/LinearSeqOptimized.scala @@ -12,6 +12,7 @@ import generic._ import mutable.ListBuffer import immutable.List import scala.util.control.Breaks._ +import scala.annotation.tailrec /** A template trait for linear sequences of type `LinearSeq[A]` which optimizes * the implementation of several methods under the assumption of fast linear access. @@ -247,14 +248,17 @@ trait LinearSeqOptimized[+A, +Repr <: LinearSeqOptimized[A, Repr]] extends Linea } override /*SeqLike*/ - def lengthCompare(len: Int): Int = { - var i = 0 - var these = self - while (!these.isEmpty && i <= len) { - i += 1 - these = these.tail + def lengthCompare(len: Int): Int = { + @tailrec def loop(i: Int, xs: Repr): Int = { + if (i == len) + if (xs.isEmpty) 0 else 1 + else if (xs.isEmpty) + -1 + else + loop(i + 1, xs.tail) } - i - len + if (len < 0) 1 + else loop(0, this) } override /*SeqLike*/ diff --git a/src/library/scala/collection/SeqLike.scala b/src/library/scala/collection/SeqLike.scala index f65e2ef9cd..1be0dba29f 100644 --- a/src/library/scala/collection/SeqLike.scala +++ b/src/library/scala/collection/SeqLike.scala @@ -84,13 +84,17 @@ trait SeqLike[+A, +Repr] extends Any with IterableLike[A, Repr] with GenSeqLike[ * if computing `length` is cheap. */ def lengthCompare(len: Int): Int = { - var i = 0 - val it = iterator - while (it.hasNext && i <= len) { - it.next() - i += 1 + if (len < 0) 1 + else { + var i = 0 + val it = iterator + while (it.hasNext) { + if (i == len) return if (it.hasNext) 1 else 0 + it.next() + i += 1 + } + i - len } - i - len } override /*IterableLike*/ def isEmpty: Boolean = lengthCompare(0) == 0 |