Skip to content

Commit 9d60c98

Browse files
committed
Obey messaging in sbt-bridge
1 parent 9ecf74d commit 9d60c98

15 files changed

+53
-55
lines changed

build.sbt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,11 @@ lazy val sbtBridge = configureAsSubproject(project, srcdir = Some("sbt-bridge"))
627627
name := "scala2-sbt-bridge",
628628
description := "sbt compiler bridge for Scala 2",
629629
libraryDependencies += compilerInterfaceDep % Provided,
630+
Compile / scalacOptions ++= Seq(
631+
"-Xlint",
632+
"-feature",
633+
"-Wconf:cat=deprecation&msg=early initializers:s", // compiler heavily relies upon early initializers
634+
),
630635
generateServiceProviderResources("xsbti.compile.CompilerInterface2" -> "scala.tools.xsbt.CompilerBridge"),
631636
generateServiceProviderResources("xsbti.compile.ConsoleInterface1" -> "scala.tools.xsbt.ConsoleBridge"),
632637
generateServiceProviderResources("xsbti.compile.ScaladocInterface2" -> "scala.tools.xsbt.ScaladocBridge"),

src/reflect/scala/reflect/internal/Names.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,8 @@ trait Names extends api.Names {
546546
override final def toString: String = if (cachedString == null) new String(_chrs, index, len) else cachedString
547547
final def appendTo(buffer: java.lang.StringBuffer, start: Int, length: Int): Unit =
548548
buffer.append(_chrs, this.start + start, length)
549+
final def appendTo(sb: StringBuilder, start: Int, length: Int): sb.type =
550+
sb.appendAll(_chrs, this.start + start, length)
549551
}
550552

551553
implicit val NameTag: ClassTag[Name] = ClassTag[Name](classOf[Name])

src/sbt-bridge/scala/tools/xsbt/API.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ final class API(val global: CallbackGlobal) extends Compat with GlobalHelpers wi
6363
}
6464

6565
private def processScalaUnit(unit: CompilationUnit): Unit = {
66-
val sourceFile: VirtualFile = unit.source.file match { case AbstractZincFile(vf) => vf }
66+
val sourceFile: VirtualFile = unit.source.file match { case AbstractZincFile(vf) => vf case x => throw new MatchError(x) }
6767
debuglog("Traversing " + sourceFile)
6868
callback.startSource(sourceFile)
6969
val extractApi = new ExtractAPI[global.type](global, sourceFile)
@@ -213,7 +213,6 @@ final class API(val global: CallbackGlobal) extends Compat with GlobalHelpers wi
213213
def isTopLevel(sym: Symbol): Boolean = {
214214
!ignoredSymbol(sym) &&
215215
sym.isStatic &&
216-
!sym.isImplClass &&
217216
(!sym.hasFlag(Flags.JAVA) || global.callback.isPickleJava) &&
218217
!sym.isNestedClass
219218
}

src/sbt-bridge/scala/tools/xsbt/Analyzer.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import java.nio.file.Path
1919
import java.io.File
2020
import xsbti.VirtualFile
2121
import scala.tools.nsc.Phase
22-
import scala.collection.JavaConverters._
22+
import scala.jdk.CollectionConverters._
2323

2424
object Analyzer {
2525
def name = "xsbt-analyzer"
@@ -54,7 +54,7 @@ final class Analyzer(val global: CallbackGlobal) extends LocateClassFile {
5454

5555
def apply(unit: CompilationUnit): Unit = {
5656
if (!unit.isJava) {
57-
val sourceFile0: AbstractZincFile = unit.source.file match { case v: AbstractZincFile => v }
57+
val sourceFile0: AbstractZincFile = unit.source.file match { case v: AbstractZincFile => v case x => throw new MatchError(x) }
5858
val sourceFile: VirtualFile = sourceFile0.underlying
5959
lazy val outputDir = settings.outputDirs.outputDirFor(sourceFile0).file
6060
for (iclass <- unit.icode) {
@@ -77,7 +77,7 @@ final class Analyzer(val global: CallbackGlobal) extends LocateClassFile {
7777
}
7878
}
7979

80-
if (sym.isModuleClass && !sym.isImplClass) {
80+
if (sym.isModuleClass) {
8181
if (isTopLevelModule(sym) && sym.companionClass == NoSymbol)
8282
addGenerated(false)
8383
addGenerated(true)

src/sbt-bridge/scala/tools/xsbt/CallbackGlobal.scala

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ sealed abstract class CallbackGlobal(
4646
case single: SingleOutput => List(single.getOutputDirectoryAsPath)
4747
// Use Stream instead of List because Analyzer maps intensively over the directories
4848
case multi: MultipleOutput =>
49-
multi.getOutputGroups.toIterator.map(_.getOutputDirectoryAsPath).toSeq
49+
multi.getOutputGroups.iterator.map(_.getOutputDirectoryAsPath).toSeq
50+
case x => throw new MatchError(x)
5051
}
5152
}
5253

@@ -227,28 +228,27 @@ sealed class ZincCompiler(settings: Settings, dreporter: DelegatingReporter, out
227228
suffix: CharSequence,
228229
includePackageObjectClassNames: Boolean
229230
): String = {
230-
var b: java.lang.StringBuffer = null
231-
def loop(size: Int, sym: Symbol): Unit = {
231+
def loop(sb: StringBuilder, size: Int, sym: Symbol): StringBuilder = {
232232
val symName = sym.name
233233
// Use of encoded to produce correct paths for names that have symbols
234234
val encodedName = symName.encode
235235
val nSize = encodedName.length - (if (symName.endsWith(nme.LOCAL_SUFFIX_STRING)) 1 else 0)
236-
if (sym.isRoot || sym.isRootPackage || sym == NoSymbol || sym.owner.isEffectiveRoot) {
237-
val capacity = size + nSize
238-
b = new java.lang.StringBuffer(capacity)
239-
b.append(chrs, encodedName.start, nSize)
240-
} else {
241-
val next = if (sym.owner.isPackageObjectClass) sym.owner else sym.effectiveOwner.enclClass
242-
loop(size + nSize + 1, next)
243-
// Addition to normal `fullName` to produce correct names for nested non-local classes
244-
if (sym.isNestedClass) b.append(nme.MODULE_SUFFIX_STRING) else b.append(separator)
245-
b.append(chrs, encodedName.start, nSize)
246-
}
247-
()
236+
val sb1 =
237+
if (sym.isRoot || sym.isRootPackage || sym == NoSymbol || sym.owner.isEffectiveRoot) {
238+
val capacity = size + nSize
239+
new StringBuilder(capacity)
240+
} else {
241+
val next = if (sym.owner.isPackageObjectClass) sym.owner else sym.effectiveOwner.enclClass
242+
// Addition to normal `fullName` to produce correct names for nested non-local classes
243+
val sep = if (sym.isNestedClass) nme.MODULE_SUFFIX_STRING else separator
244+
loop(sb, size + nSize + 1, next)
245+
.append(sep)
246+
}
247+
encodedName.appendTo(sb1, 0, nSize)
248248
}
249-
loop(suffix.length(), symbol)
250-
b.append(suffix)
251-
b.toString
249+
loop(sb = null, suffix.length(), symbol)
250+
.append(suffix)
251+
.toString
252252
}
253253

254254
private[this] var callback0: AnalysisCallback = null

src/sbt-bridge/scala/tools/xsbt/ClassName.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ trait ClassName extends Compat {
9999

100100
protected def isTopLevelModule(sym: Symbol): Boolean =
101101
enteringPhase(currentRun.picklerPhase.next) {
102-
sym.isModuleClass && !sym.isImplClass && !sym.isNestedClass
102+
sym.isModuleClass && !sym.isNestedClass
103103
}
104104

105105
protected def flatclassName(s: Symbol, sep: Char, dollarRequired: Boolean): String =

src/sbt-bridge/scala/tools/xsbt/CompilerBridge.scala

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,11 @@ package xsbt
1818
import xsbti.{AnalysisCallback, AnalysisCallback2, Logger, Problem, Reporter, VirtualFile}
1919
import xsbti.compile._
2020

21-
import scala.tools.nsc.Settings
22-
import scala.collection.mutable
2321
import scala.reflect.io.AbstractFile
24-
import scala.tools.nsc.CompilerCommand
22+
import scala.tools.nsc.{CompilerCommand, Settings}
2523
import Log.debug
24+
2625
import java.io.File
27-
import java.util.{Collections, Optional}
2826

2927
/**
3028
* This is the entry point for the compiler bridge (implementation of CompilerInterface)
@@ -94,6 +92,7 @@ private final class CachedCompiler0(
9492
case single: SingleOutput =>
9593
val outputFilepath = single.getOutputDirectoryAsPath.toAbsolutePath
9694
settings.outputDirs.setSingleOutput(outputFilepath.toString)
95+
case x => throw new MatchError(x)
9796
}
9897

9998
val command = new CompilerCommand(args.toList, settings)
@@ -165,7 +164,7 @@ private final class CachedCompiler0(
165164
else callback.problem(p.category, p.position, p.message, p.severity, true)
166165

167166
if (command.shouldStopWithInfo) {
168-
underlyingReporter.info(null, command.getInfoMessage(compiler), true)
167+
underlyingReporter.echo(command.getInfoMessage(compiler))
169168
throw new InterfaceCompileFailed(args, Array(), StopInfoError)
170169
}
171170

src/sbt-bridge/scala/tools/xsbt/ConsoleBridge.scala

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ class ConsoleBridge extends xsbti.compile.ConsoleInterface1 {
5555
if (loader eq null) super.parentClassLoader
5656
else loader
5757
}
58-
intp.setContextClassLoader()
5958
} else
6059
super.createInterpreter(interpreterSettings)
6160

@@ -106,9 +105,5 @@ object MakeSettings {
106105
compilerSettings
107106
}
108107

109-
def sync(options: List[String], log: Logger): Settings = {
110-
val settings = apply(options, log)
111-
settings.Yreplsync.value = true
112-
settings
113-
}
108+
def sync(options: List[String], log: Logger): Settings = apply(options, log)
114109
}

src/sbt-bridge/scala/tools/xsbt/DelegatingReporter.scala

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ import java.io.File
1919
import java.{ util => ju }
2020
import ju.Optional
2121

22+
import scala.jdk.CollectionConverters._
2223
import scala.reflect.internal.util.{ CodeAction, FakePos, NoPosition, Position }
23-
import scala.collection.JavaConverters._
2424
import scala.reflect.io.AbstractFile
25+
import scala.tools.nsc.Settings
26+
import scala.tools.nsc.reporters.FilteringReporter
2527
import xsbti.{
2628
Action,
2729
DiagnosticCode => XDiagnosticCode,
@@ -42,8 +44,8 @@ import xsbti.{
4244
* Zinc in the Scala version Zinc uses.
4345
*/
4446
private object DelegatingReporter {
45-
def apply(settings: scala.tools.nsc.Settings, delegate: xsbti.Reporter): DelegatingReporter =
46-
new DelegatingReporter(settings.fatalWarnings.value, settings.nowarn.value, delegate)
47+
def apply(settings: Settings, delegate: xsbti.Reporter): DelegatingReporter =
48+
new DelegatingReporter(settings, delegate)
4749

4850
class PositionImpl(
4951
sourcePath0: Option[String],
@@ -194,12 +196,14 @@ private object DelegatingReporter {
194196
// Original author: Martin Odersky
195197
// Based on scala.tools.nsc.reporters.{AbstractReporter, ConsoleReporter}
196198
private final class DelegatingReporter(
197-
warnFatal: Boolean,
198-
noWarn: Boolean,
199+
val settings: Settings,
199200
private[this] var delegate: xsbti.Reporter
200-
) extends scala.tools.nsc.reporters.Reporter {
201+
) extends FilteringReporter {
201202
import DelegatingReporter._
202203

204+
private val Werror: Boolean = settings.fatalWarnings.value
205+
private val noWarn: Boolean = settings.nowarn.value
206+
203207
def dropDelegate(): Unit = { delegate = ReporterSink }
204208
def error(msg: String): Unit = error(FakePos("scalac"), msg)
205209
def printSummary(): Unit = delegate.printSummary()
@@ -217,7 +221,7 @@ private final class DelegatingReporter(
217221
override def doReport(pos: Position, msg: String, rawSeverity: Severity, actions: List[CodeAction]): Unit = {
218222
val skip = rawSeverity == WARNING && noWarn
219223
if (!skip) {
220-
val severity = if (warnFatal && rawSeverity == WARNING) ERROR else rawSeverity
224+
val severity = if (Werror && rawSeverity == WARNING) ERROR else rawSeverity
221225
val pos1 = DelegatingReporter.convert(pos)
222226
delegate.log(new CompileProblem(
223227
pos = pos1,
@@ -231,8 +235,7 @@ private final class DelegatingReporter(
231235
}
232236
}
233237

234-
protected def info0(pos: Position, msg: String, rawSeverity: Severity, force: Boolean): Unit =
235-
doReport(pos, msg, rawSeverity, Nil)
238+
//protected def info0(pos: Position, msg: String, rawSeverity: Severity, force: Boolean): Unit = doReport(pos, msg, rawSeverity, Nil)
236239

237240
import xsbti.Severity.{ Info, Warn, Error }
238241
private[this] def convert(sev: Severity): xsbti.Severity = sev match {

src/sbt-bridge/scala/tools/xsbt/Dependency.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ final class Dependency(val global: CallbackGlobal) extends LocateClassFile with
8686
}
8787
}
8888

89-
private val sourceFile: VirtualFile = unit.source.file match { case AbstractZincFile(vf) => vf }
89+
private val sourceFile: VirtualFile = unit.source.file match { case AbstractZincFile(vf) => vf case x => throw new MatchError(x) }
9090
private val responsibleOfImports = firstClassOrModuleClass(unit.body)
9191
private var orphanImportsReported = false
9292

src/sbt-bridge/scala/tools/xsbt/ExtractUsedNames.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ import java.util.{ HashSet => JavaSet }
2020
import java.util.EnumSet
2121

2222
import xsbti.UseScope
23-
// Left for compatibility
24-
import Compat._
2523

2624
/**
2725
* Extracts simple names used in given compilation unit.

src/sbt-bridge/scala/tools/xsbt/GlobalHelpers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ trait GlobalHelpers { self: Compat =>
113113

114114
case RefinedType(parents, decls) =>
115115
parents.foreach(traverse)
116-
decls.toIterator.foreach { decl =>
116+
decls.iterator.foreach { decl =>
117117
if (decl.isType) addTypeSymbolDependency(decl)
118118
else addDependency(decl)
119119
}

src/sbt-bridge/scala/tools/xsbt/InteractiveConsoleBridge.scala

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,5 @@ object InteractiveMakeSettings {
9999
compilerSettings
100100
}
101101

102-
def sync(options: List[String], onError: String => Unit): Settings = {
103-
val settings = apply(options, onError)
104-
settings.Yreplsync.value = true
105-
settings
106-
}
102+
def sync(options: List[String], onError: String => Unit): Settings = apply(options, onError)
107103
}

src/sbt-bridge/scala/tools/xsbt/InteractiveConsoleHelper.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package scala.tools
1616
package xsbt
1717

18+
import scala.language.implicitConversions
1819
import Compat._
1920
import xsbti.InteractiveConsoleResult
2021

src/sbt-bridge/scala/tools/xsbt/ScaladocBridge.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ private class Runner(
6363

6464
// 2.8 source compatibility
6565
class DefaultDocDriver {
66-
assert(false)
67-
def process(units: Iterator[CompilationUnit]) = error("for 2.8 compatibility only")
66+
assert(false, "2.8 compatibility")
67+
def process(units: Iterator[CompilationUnit]) = globalError("for 2.8 compatibility only")
6868
}
6969
}
7070
def document(ignore: Seq[String]): Unit = {

0 commit comments

Comments
 (0)