Skip to content

Commit

Permalink
Tweak more
Browse files Browse the repository at this point in the history
  • Loading branch information
som-snytt committed Jan 8, 2024
1 parent 8caa7c2 commit 6d74ffb
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 41 deletions.
14 changes: 7 additions & 7 deletions src/interactive/scala/tools/nsc/interactive/Pickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -106,32 +106,32 @@ object Pickler {
* @param f the function to apply.
*/
def map[U](f: T => U): Unpickled[U] = this match {
case UnpickleSuccess(x) => UnpickleSuccess(f(x))
case f: UnpickleFailure => f
case UnpickleSuccess(x) => UnpickleSuccess(f(x))
case fail: UnpickleFailure => fail
}
/** Transforms success values to successes or failures using given function,
* leaves failures alone.
* @param f the function to apply.
*/
def flatMap[U](f: T => Unpickled[U]): Unpickled[U] = this match {
case UnpickleSuccess(x) => f(x)
case f: UnpickleFailure => f
case UnpickleSuccess(x) => f(x)
case fail: UnpickleFailure => fail
}
/** Tries alternate expression if current result is a failure
* @param alt the alternate expression to be tried in case of failure
*/
def orElse[U >: T](alt: => Unpickled[U]): Unpickled[U] = this match {
case UnpickleSuccess(x) => this
case f: UnpickleFailure => alt
case _: UnpickleFailure => alt
}

/** Transforms failures into thrown `MalformedInput` exceptions.
* @throws Lexer.MalformedInput if current result is a failure
*/
def requireSuccess: UnpickleSuccess[T] = this match {
case s @ UnpickleSuccess(x) => s
case s @ UnpickleSuccess(_) => s
case f: UnpickleFailure =>
throw new MalformedInput(f.rd, "Unrecoverable unpickle failure:\n"+f.errMsg)
throw new MalformedInput(f.rd, s"Unrecoverable unpickle failure:\n${f.errMsg}")
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/partest/scala/tools/partest/ReplTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

package scala.tools.partest

import java.io.File.pathSeparator

import scala.tools.nsc.Settings
import scala.tools.nsc.interpreter.shell.{ILoop, ShellConfig}
import scala.util.matching.Regex.{quoteReplacement, Match}
Expand All @@ -34,7 +36,7 @@ abstract class ReplTest extends DirectTest {
if (getClass.getClassLoader.getParent != null) {
s.classpath.value = s.classpath.value match {
case "" => testOutput.toString
case s => s + java.io.File.pathSeparator + testOutput.toString
case cp => s"$cp$pathSeparator$testOutput"
}
s.usejavacp.value = true
}
Expand Down
6 changes: 3 additions & 3 deletions src/partest/scala/tools/partest/ScaladocModelTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,11 @@ abstract class ScaladocModelTest extends DirectTest {

def countLinks(c: Comment, p: EntityLink => Boolean): Int = countLinksInBody(c.body, p)

def countLinksInBody(body: Body, p: EntityLink => Boolean): Int = {
def countLinksInBody(body: Body, linkTest: EntityLink => Boolean): Int = {
def countLinks(b: Any): Int = b match {
case el: EntityLink if p(el) => 1
case el: EntityLink if linkTest(el) => 1
case s: collection.Seq[_] => s.toList.map(countLinks(_)).sum
case p: Product => p.productIterator.toList.map(countLinks(_)).sum
case p: Product => p.productIterator.map(countLinks(_)).sum
case _ => 0
}
countLinks(body)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ trait LoopCommands {
def complete(buffer: String, cursor: Int, filter: Boolean) =
CompletionResult(buffer, cursor = 1, List(CompletionCandidate(completion)), "", "")
}
case cmd :: rest =>
case cmd :: _ =>
new Completion {
def complete(buffer: String, cursor: Int, filter: Boolean) =
CompletionResult(buffer, cursor = 1, cmds.map(cmd => CompletionCandidate(":" + cmd.name)), "", "")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class Scripted(@BeanProperty val factory: ScriptEngineFactory, settings: Setting
def dynamicContext_=(ctx: ScriptContext): Unit = intp.call("set", ctx)

def dynamicContext: ScriptContext = intp.call("value") match {
case Right(ctx: ScriptContext) => ctx
case Right(scriptctx: ScriptContext) => scriptctx
case Left(e) => throw e
case Right(other) => throw new ScriptException(s"Unexpected value for context: $other")
}
Expand Down
16 changes: 8 additions & 8 deletions src/repl/scala/tools/nsc/interpreter/ReplGlobal.scala
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,19 @@ trait ReplGlobal extends Global {
}

override def transform(tree: Tree): Tree = super.transform(tree) match {
case tree @ Template(parents, self, body) if nme.isReplWrapperName(tree.symbol.name) =>
case tpl @ Template(_, _, body) if nme.isReplWrapperName(tpl.symbol.name) =>
val unusedPrivates = newUnusedPrivates
unusedPrivates.traverse(tree)
unusedPrivates.traverse(tpl)
val unusedSyms = unusedPrivates.unusedTerms.iterator.map(_.symbol)
val unusedLineReadVals = unusedSyms.filter(sym => isLineReadVal(sym.name)).flatMap(sym => List(sym, sym.accessedOrSelf)).toSet
val (removedStats, retainedStats) = tree.body.partition (t => unusedLineReadVals(t.symbol))
if (removedStats.isEmpty) tree
val (removedStats, retainedStats) = body.partition(stat => unusedLineReadVals(stat.symbol))
if (removedStats.isEmpty) tpl
else {
val decls = tree.symbol.info.decls
removedStats.foreach(tree => decls.unlink(tree.symbol))
deriveTemplate(tree)(_ => retainedStats)
val decls = tpl.symbol.info.decls
removedStats.foreach(stat => decls.unlink(stat.symbol))
deriveTemplate(tpl)(_ => retainedStats)
}
case tree => tree
case transformed => transformed
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/sbt-bridge/scala/tools/xsbt/ExtractAPI.scala
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ class ExtractAPI[GlobalType <: Global](
xsbti.api.Annotated.of(processType(in, at.underlying), mkAnnotations(in, annots))
}
case rt: CompoundType => structure(rt, rt.typeSymbol)
case t: ExistentialType => makeExistentialType(in, t)
case et: ExistentialType => makeExistentialType(in, et)
case NoType =>
Constants.emptyType // this can happen when there is an error that will be reported by a later phase
case PolyType(typeParams, resultType) =>
Expand Down
21 changes: 10 additions & 11 deletions src/scaladoc/scala/tools/nsc/doc/model/ModelFactory.scala
Original file line number Diff line number Diff line change
Expand Up @@ -751,10 +751,11 @@ class ModelFactory(val global: Global, val settings: doc.Settings) {
docTemplatesCache(bSym)
else
docTemplatesCache.get(bSym.owner) match {
case Some(inTpl) =>
val mbrs = inTpl.members.collect({ case mbr: MemberImpl if mbr.sym == bSym => mbr })
assert(mbrs.length == 1, "must have exactly one member with bSym")
mbrs.head
case Some(docTpl) =>
docTpl.members.collect { case mbr: MemberImpl if mbr.sym == bSym => mbr } match {
case h :: Nil => h
case _ => throw new AssertionError("must have exactly one member with bSym")
}
case _ =>
// move the class completely to the new location
createNoDocMemberTemplate(bSym, inTpl)
Expand Down Expand Up @@ -961,14 +962,12 @@ class ModelFactory(val global: Global, val settings: doc.Settings) {
* - a NoDocTemplate if the type's symbol is not documented at all */
def makeTemplateOrMemberTemplate(parent: Type): TemplateImpl = {
def noDocTemplate = makeTemplate(parent.typeSymbol)
findTemplateMaybe(parent.typeSymbol) match {
case Some(tpl) => tpl
case None => parent match {
findTemplateMaybe(parent.typeSymbol).getOrElse {
parent match {
case TypeRef(pre, sym, args) =>
findTemplateMaybe(pre.typeSymbol) match {
case Some(tpl) => findMember(parent.typeSymbol, tpl).collect({case t: TemplateImpl => t}).getOrElse(noDocTemplate)
case None => noDocTemplate
}
findTemplateMaybe(pre.typeSymbol)
.flatMap(findMember(parent.typeSymbol, _).collect { case t: TemplateImpl => t })
.getOrElse(noDocTemplate)
case _ => noDocTemplate
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ class ScalaSigPrinter(stream: PrintStream, printPrivates: Boolean) {

// Print result type
mt.resultType match {
case mt: MethodType => printMethodType(mt, printResult)({})
case res: MethodType => printMethodType(res, printResult)(())
case x => if (printResult) {
print(": ")
printType(x)
Expand Down
15 changes: 8 additions & 7 deletions src/testkit/scala/tools/testkit/AllocationTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,17 @@ trait AllocationTest {
}

private def showAllocations(allocations: List[Long]): String = allocations match {
case Nil => ""
case a :: tail =>
case a :: allocations =>
val sb = new StringBuilder
def append(a: Long, count: Int) = sb.append(s" allocation $a ($count times)\n")
@tailrec def loop(allocations: List[Long], last: Long, count: Int): String = allocations match {
case Nil => append(last, count).result()
case a :: tail if a != last => append(a, count); loop(tail, a, 1)
case a :: tail => loop(tail, a, count + 1)
def loop(allocations: List[Long], last: Long, count: Int): String = allocations match {
case Nil => append(last, count).result()
case b :: allocations =>
val n = if (b != last) { append(b, count); 1 } else count + 1
loop(allocations, b, n)
}
loop(tail, a, 1)
loop(allocations, a, 1)
case _ => ""
}

/** Asserts that the execution of `fn` allocates `size` bytes or less. */
Expand Down

0 comments on commit 6d74ffb

Please sign in to comment.