diff --git a/compiler/src/dotty/tools/backend/jvm/BCodeHelpers.scala b/compiler/src/dotty/tools/backend/jvm/BCodeHelpers.scala index a845df1eb561..f119cb867012 100644 --- a/compiler/src/dotty/tools/backend/jvm/BCodeHelpers.scala +++ b/compiler/src/dotty/tools/backend/jvm/BCodeHelpers.scala @@ -662,15 +662,13 @@ trait BCodeHelpers(val backendUtils: BackendUtils)(using ctx: Context) extends B import scala.tools.asm.util.CheckClassAdapter def wrap(body: => Unit): Unit = { try body - catch { - case ex: Throwable => - report.error( - em"""|compiler bug: created invalid generic signature for $sym in ${sym.denot.owner.showFullName} - |signature: $sig - |if this is reproducible, please report bug at https://github.com/scala/scala3/issues - """, sym.sourcePos) - throw ex - } + catch case ex: Exception => + report.error( + em"""|compiler bug: created invalid generic signature for $sym in ${sym.denot.owner.showFullName} + |signature: $sig + |if this is reproducible, please report bug at https://github.com/scala/scala3/issues + """, sym.sourcePos) + throw ex } wrap { diff --git a/compiler/src/dotty/tools/backend/jvm/ClassfileWriters.scala b/compiler/src/dotty/tools/backend/jvm/ClassfileWriters.scala index bd7acdcc75e2..27b5a5c603c9 100644 --- a/compiler/src/dotty/tools/backend/jvm/ClassfileWriters.scala +++ b/compiler/src/dotty/tools/backend/jvm/ClassfileWriters.scala @@ -238,7 +238,7 @@ class ClassfileWriters(frontendAccess: PostProcessorFrontendAccess)(using ctx: C catch { case ex: ClosedByInterruptException => try Files.deleteIfExists(path) // don't leave a empty of half-written classfile around after an interrupt - catch { case _: Throwable => () } + catch { case _: java.io.IOException => () } throw ex } os.close() diff --git a/compiler/src/dotty/tools/backend/jvm/CodeGen.scala b/compiler/src/dotty/tools/backend/jvm/CodeGen.scala index 201dcae9e63d..dcac24f35543 100644 --- a/compiler/src/dotty/tools/backend/jvm/CodeGen.scala +++ b/compiler/src/dotty/tools/backend/jvm/CodeGen.scala @@ -85,10 +85,7 @@ class CodeGen(val backendUtils: BackendUtils, val primitives: ScalaPrimitives, v registerGeneratedClass(mainClassNode, isArtifact = false) registerGeneratedClass(mirrorClassNode, isArtifact = true) catch - case ex: InterruptedException => throw ex - case ex: CompilationUnit.SuspendException => throw ex - case ex: Throwable => - if !ex.isInstanceOf[TypeError] then ex.printStackTrace() + case ex: TypeError => report.error(s"Error while emitting ${unit.source}\n${ex.getMessage}", cd.sourcePos) diff --git a/compiler/src/dotty/tools/backend/jvm/GeneratedClassHandler.scala b/compiler/src/dotty/tools/backend/jvm/GeneratedClassHandler.scala index 82b7aa7b282b..dbc1b744341e 100644 --- a/compiler/src/dotty/tools/backend/jvm/GeneratedClassHandler.scala +++ b/compiler/src/dotty/tools/backend/jvm/GeneratedClassHandler.scala @@ -10,10 +10,8 @@ import dotty.tools.dotc.core.Contexts.* import dotty.tools.io.AbstractFile import dotty.tools.dotc.profile.ThreadPoolFactory -import scala.util.control.NonFatal import dotty.tools.dotc.core.Phases import dotty.tools.dotc.core.Decorators.em -import dotty.tools.dotc.core.Types.IdentityTypeMap.mapCtx import dotty.tools.dotc.report import scala.compiletime.uninitialized @@ -155,10 +153,10 @@ private[jvm] object GeneratedClassHandler { unitInPostProcess.task.value.get.get catch case _: ClosedByInterruptException => throw new InterruptedException() - case NonFatal(t) => - t.printStackTrace() + case e: Exception => + e.printStackTrace() given Context = ctx - report.error(em"unable to write ${unitInPostProcess.sourceFile} $t") + report.error(em"unable to write ${unitInPostProcess.sourceFile} $e") } } } diff --git a/compiler/src/dotty/tools/backend/jvm/GenericSignatureVisitor.scala b/compiler/src/dotty/tools/backend/jvm/GenericSignatureVisitor.scala index 3648240171f8..dfca8cbecf1b 100644 --- a/compiler/src/dotty/tools/backend/jvm/GenericSignatureVisitor.scala +++ b/compiler/src/dotty/tools/backend/jvm/GenericSignatureVisitor.scala @@ -6,7 +6,7 @@ import scala.tools.asm.{ClassReader, Type, Handle } import scala.tools.asm.tree.* import scala.collection.mutable -import scala.util.control.{NoStackTrace, NonFatal} +import scala.util.control.NoStackTrace import scala.annotation.* import scala.jdk.CollectionConverters.* import BTypes.InternalName @@ -47,7 +47,7 @@ abstract class GenericSignatureVisitor(nestedOnly: Boolean) { @inline def safely(f: => Unit): Unit = try f catch { case Aborted => - case NonFatal(e) => raiseError(s"Exception thrown during signature parsing", sig, Some(e)) + case e: Exception => raiseError(s"Exception thrown during signature parsing", sig, Some(e)) } private def current = { diff --git a/compiler/src/dotty/tools/backend/jvm/PostProcessor.scala b/compiler/src/dotty/tools/backend/jvm/PostProcessor.scala index 72b8cbd7b807..fcaaf66bf382 100644 --- a/compiler/src/dotty/tools/backend/jvm/PostProcessor.scala +++ b/compiler/src/dotty/tools/backend/jvm/PostProcessor.scala @@ -49,7 +49,7 @@ class PostProcessor(val frontendAccess: PostProcessorFrontendAccess, case e: java.lang.RuntimeException if e.getMessage != null && e.getMessage.contains("too large!") => report.error(em"Could not write class $internalName because it exceeds JVM code size limits. ${e.getMessage}") null - case ex: Throwable => + case ex: Exception => if frontendAccess.compilerSettings.debug then ex.printStackTrace() report.error(em"Error while emitting $internalName\n${ex.getMessage}") null diff --git a/compiler/src/dotty/tools/debug/ExpressionCompilerBridge.scala b/compiler/src/dotty/tools/debug/ExpressionCompilerBridge.scala index c596c6d4a1e0..e14d218d347d 100644 --- a/compiler/src/dotty/tools/debug/ExpressionCompilerBridge.scala +++ b/compiler/src/dotty/tools/debug/ExpressionCompilerBridge.scala @@ -1,7 +1,6 @@ package dotty.tools.debug import java.nio.file.Path -import scala.util.control.NonFatal import dotty.tools.dotc.core.Contexts.Context import dotty.tools.dotc.Driver @@ -29,6 +28,6 @@ class ExpressionCompilerBridge: driver.process(args, reporter) !reporter.hasErrors catch - case NonFatal(cause) => + case cause: Exception => cause.printStackTrace() throw cause diff --git a/compiler/src/dotty/tools/dotc/Driver.scala b/compiler/src/dotty/tools/dotc/Driver.scala index 2a4feea9ed05..4896664c4e8f 100644 --- a/compiler/src/dotty/tools/dotc/Driver.scala +++ b/compiler/src/dotty/tools/dotc/Driver.scala @@ -11,7 +11,6 @@ import reporting.* import core.Decorators.* import util.chaining.* -import scala.util.control.NonFatal import fromtasty.{TASTYCompiler, TastyFileUtil} /** Run the Dotty compiler. @@ -39,13 +38,13 @@ class Driver { catch case ex: FatalError => report.error(ex.getMessage) // signals that we should fail compilation. - case ex: Throwable if ctx.usedBestEffortTasty => + case ex: Exception if ctx.usedBestEffortTasty => report.bestEffortError(ex, "Some best-effort tasty files were not able to be read.") throw ex case ex: TypeError if !runOrNull.enrichedErrorMessage => println(runOrNull.enrichErrorMessage(s"${ex.toMessage} while compiling ${files.map(_.path).mkString(", ")}")) throw ex - case ex: Throwable if !runOrNull.enrichedErrorMessage => + case ex: Exception if !runOrNull.enrichedErrorMessage => println(runOrNull.enrichErrorMessage(s"Exception while compiling ${files.map(_.path).mkString(", ")}")) throw ex ctx.reporter @@ -215,10 +214,6 @@ class Driver { } def main(args: Array[String]): Unit = { - // Preload scala.util.control.NonFatal. Otherwise, when trying to catch a StackOverflowError, - // we may try to load it but fail with another StackOverflowError and lose the original exception, - // see . - val _ = NonFatal sys.exit(if (process(args).hasErrors) 1 else 0) } } diff --git a/compiler/src/dotty/tools/dotc/Run.scala b/compiler/src/dotty/tools/dotc/Run.scala index 8a28d073137e..af21f7389c07 100644 --- a/compiler/src/dotty/tools/dotc/Run.scala +++ b/compiler/src/dotty/tools/dotc/Run.scala @@ -31,7 +31,6 @@ import java.io.{BufferedWriter, OutputStreamWriter} import java.nio.charset.StandardCharsets import scala.collection.mutable, mutable.ListBuffer -import scala.util.control.NonFatal import scala.io.Codec import Run.Progress @@ -323,7 +322,7 @@ extends ImplicitRunInfo, ConstraintRunInfo, cc.CaptureRunInfo { def compile(files: List[AbstractFile]): Unit = try compileSources(files.map(runContext.getSource(_))) - catch case NonFatal(ex) if !this.enrichedErrorMessage => + catch case ex: Exception if !this.enrichedErrorMessage => val files1 = if units.isEmpty then files else units.map(_.source.file) report.echo(this.enrichErrorMessage(s"exception occurred while compiling ${files1.map(_.path)}")) throw ex diff --git a/compiler/src/dotty/tools/dotc/classpath/DirectoryClassPath.scala b/compiler/src/dotty/tools/dotc/classpath/DirectoryClassPath.scala index 755ab8548b21..483ec535bd17 100644 --- a/compiler/src/dotty/tools/dotc/classpath/DirectoryClassPath.scala +++ b/compiler/src/dotty/tools/dotc/classpath/DirectoryClassPath.scala @@ -14,7 +14,6 @@ import PlainFile.toPlainFile import scala.jdk.CollectionConverters.* import scala.collection.immutable.ArraySeq -import scala.util.control.NonFatal /** * A trait allowing to look for classpath entries in directories. It provides common logic for @@ -134,7 +133,7 @@ object JrtClassPath { val ctSym = Paths.get(Properties.javaHome).resolve("lib").resolve("ct.sym") if (Files.notExists(ctSym)) None else Some(new CtSymClassPath(ctSym, v.toInt)) - catch case NonFatal(_) => None + catch case _: Exception => None case _ => try Some(new JrtClassPath(FileSystems.getFileSystem(URI.create("jrt:/")))) catch case _: ProviderNotFoundException | _: FileSystemNotFoundException => None diff --git a/compiler/src/dotty/tools/dotc/core/Decorators.scala b/compiler/src/dotty/tools/dotc/core/Decorators.scala index b78ef947cd8b..7bf9ad4b2b48 100644 --- a/compiler/src/dotty/tools/dotc/core/Decorators.scala +++ b/compiler/src/dotty/tools/dotc/core/Decorators.scala @@ -4,7 +4,6 @@ package core import scala.annotation.tailrec import scala.collection.mutable.ListBuffer -import scala.util.control.NonFatal import Contexts.*, Names.*, Phases.*, Symbols.* import printing.{ Printer, Showable }, printing.Formatting.*, printing.Texts.* @@ -286,7 +285,7 @@ object Decorators { try x.show catch case ex: CyclicReference => "... (caught cyclic reference) ..." - case NonFatal(ex) + case ex: Exception if !ctx.settings.YshowPrintErrors.value => s"... (cannot display due to ${ex.className} ${ex.getMessage}) ..." case _ => String.valueOf(x) diff --git a/compiler/src/dotty/tools/dotc/core/Phases.scala b/compiler/src/dotty/tools/dotc/core/Phases.scala index fef2ec843dd6..d145f56f51f1 100644 --- a/compiler/src/dotty/tools/dotc/core/Phases.scala +++ b/compiler/src/dotty/tools/dotc/core/Phases.scala @@ -19,7 +19,6 @@ import cc.CheckCaptures import typer.ImportInfo.withRootImports import ast.{tpd, untpd} import scala.annotation.internal.sharable -import scala.util.control.NonFatal import scala.compiletime.uninitialized object Phases { @@ -413,7 +412,7 @@ object Phases { catch case _: CompilationUnit.SuspendException => // this unit will be run again in `Run#compileSuspendedUnits` unitCtx.typerState.resetTo(previousTyperState) - case ex: Throwable if !ctx.run.enrichedErrorMessage => + case ex: Exception if !ctx.run.enrichedErrorMessage => println(ctx.run.enrichErrorMessage(s"unhandled exception while running $phaseName on $unit")) throw ex finally ctx.run.advanceUnit() @@ -537,7 +536,7 @@ object Phases { ctx.run.enterUnit(ctx.compilationUnit) && { try {body; true} - catch case NonFatal(ex) if !ctx.run.enrichedErrorMessage => + catch case ex: Exception if !ctx.run.enrichedErrorMessage => report.echo(ctx.run.enrichErrorMessage(s"exception occurred while $doing ${ctx.compilationUnit}")) throw ex finally ctx.run.advanceUnit() diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala index 1aabb85f5919..98716fd6f595 100644 --- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala @@ -19,7 +19,6 @@ import annotation.tailrec import util.SimpleIdentityMap import util.Stats import java.util.WeakHashMap -import scala.util.control.NonFatal import config.Config import reporting.* import collection.mutable @@ -2388,7 +2387,7 @@ object SymDenotations { } } catch { - case ex: Throwable => + case ex: Exception => tp match case tp: CachedType => btrCache.remove(tp) case _ => @@ -2429,8 +2428,7 @@ object SymDenotations { names } catch { - case ex: Throwable => - handleRecursive("member names", i"of $this", ex) + case ex: Throwable => handleRecursive("member names", i"of $this", ex) } } @@ -2618,7 +2616,7 @@ object SymDenotations { // since the older file might have been loaded from a jar earlier in the // classpath. def sameContainer(f: AbstractFile): Boolean = - try f.container == chosen.container catch case NonFatal(ex) => true + try f.container == chosen.container catch case ex: Exception => true if !ambiguityWarningIssued then for conflicting <- assocFiles.find(!sameContainer(_)) do report.warning(em"""${ambiguousFilesMsg(conflicting)} diff --git a/compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala b/compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala index 972fcff70df4..e3dab9c299f6 100644 --- a/compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala +++ b/compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala @@ -5,8 +5,6 @@ package core import java.io.{IOException, File} import java.nio.channels.ClosedByInterruptException -import scala.util.control.NonFatal - import dotty.tools.dotc.classpath.{ ClassPathFactory, PackageNameUtils } import dotty.tools.dotc.classpath.FileUtils.{hasTastyExtension, hasBetastyExtension} import dotty.tools.io.{ ClassPath, ClassRepresentation, AbstractFile, NoAbstractFile } @@ -437,16 +435,14 @@ abstract class SymbolLoader extends LazyType { self => report.informTime("loaded " + description, start) } catch { - case ex: InterruptedException => - throw ex case ex: ClosedByInterruptException => throw new InterruptedException case ex: IOException => signalError(ex) - case NonFatal(ex: TypeError) => + case ex: TypeError => println(s"exception caught when loading $root: ${ex.toMessage}") throw ex - case NonFatal(ex) => + case ex: Exception => println(s"exception caught when loading $root: $ex") throw ex } diff --git a/compiler/src/dotty/tools/dotc/core/TypeApplications.scala b/compiler/src/dotty/tools/dotc/core/TypeApplications.scala index 30bd3c168269..97b0af3e3a4f 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeApplications.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeApplications.scala @@ -393,15 +393,17 @@ class TypeApplications(val self: Type) extends AnyVal { case _ => false } } - if ((dealiased eq stripped) || followAlias) - try - val instantiated = dealiased.instantiate(args) - if (followAlias) instantiated.normalized else instantiated - catch - case ex: IndexOutOfBoundsException => - AppliedType(self, args) - case ex: Throwable => - handleRecursive("try to instantiate", i"$dealiased[$args%, %]", ex) + if (dealiased eq stripped) || followAlias then + val paramsWithoutArg = dealiased.typeParams.drop(args.length).map(_.paramRef) + val hasParamsWithoutArg = paramsWithoutArg.nonEmpty && dealiased.resType.existsPart(paramsWithoutArg.contains, forceLazy = false) + if hasParamsWithoutArg then + AppliedType(self, args) + else + try + val instantiated = dealiased.instantiate(args) + if (followAlias) instantiated.normalized else instantiated + catch + case ex: Throwable => handleRecursive("try to instantiate", i"$dealiased[$args%, %]", ex) else AppliedType(self, args) } diff --git a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala index 366af03a97e2..9bb179c80bbc 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala @@ -17,7 +17,6 @@ import TypeErasure.{erasedLub, erasedGlb} import TypeApplications.* import Variances.{Variance, variancesConform} import Constants.Constant -import scala.util.control.NonFatal import typer.ProtoTypes.constrained import typer.Applications.productSelectorTypes import reporting.trace @@ -1637,12 +1636,18 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling needsGc = false if (Stats.monitored) recordStatistics(result, savedSuccessCount) result - catch case NonFatal(ex) => - if ex.isInstanceOf[AssertionError] then showGoal(tp1, tp2) - recCount -= 1 - restore() - successCount = savedSuccessCount - throw ex + catch + case ex: AssertionError => + showGoal(tp1, tp2) + recCount -= 1 + restore() + successCount = savedSuccessCount + throw ex + case ex: Exception => + recCount -= 1 + restore() + successCount = savedSuccessCount + throw ex } /** Undo all actions in undoLog following prevSize */ @@ -2988,7 +2993,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling explainPoly(tp1) explainPoly(tp2) } - catch case NonFatal(ex) => + catch case ex: Exception => report.echo(s"assertion failure [[cannot display since $ex was thrown]]") /** Record statistics about the total number of subtype checks diff --git a/compiler/src/dotty/tools/dotc/core/TypeErasure.scala b/compiler/src/dotty/tools/dotc/core/TypeErasure.scala index 5459f953ecc5..37ac623714ab 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeErasure.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeErasure.scala @@ -933,8 +933,7 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst try erasureFn(sourceLanguage, semiEraseVCs = false, isConstructor, isSymbol, inSigName)(elemtp) match case _: WildcardType => WildcardType case elem => JavaArrayType(elem) - catch case ex: Throwable => - handleRecursive("erase array type", tp.show, ex) + catch case ex: Throwable => handleRecursive("erase array type", tp.show, ex) } private def erasePair(tp: Type)(using Context): Type = { diff --git a/compiler/src/dotty/tools/dotc/core/TypeErrors.scala b/compiler/src/dotty/tools/dotc/core/TypeErrors.scala index 1b6156ee74e8..4b28d17fc9d2 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeErrors.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeErrors.scala @@ -47,7 +47,7 @@ abstract class TypeError(using creationContext: Context) extends Exception(""): /** Uses creationContext to produce the message */ override def getMessage: String = - try toMessage.message catch case ex: Throwable => "TypeError" + try toMessage.message catch case _: Exception => "TypeError" object TypeError: def apply(msg: Message)(using Context) = new TypeError: @@ -131,7 +131,7 @@ end RecursionOverflow // Beware: Since this object is only used when handling a StackOverflow, this code // cannot consume significant amounts of stack. object handleRecursive: - inline def underlyingStackOverflowOrNull(exc: Throwable): Throwable | Null = + private inline def underlyingStackOverflowOrNull(exc: Throwable): Throwable | Null = var e: Throwable | Null = exc while e != null && !e.isInstanceOf[StackOverflowError] do e = e.getCause e diff --git a/compiler/src/dotty/tools/dotc/core/TypeEval.scala b/compiler/src/dotty/tools/dotc/core/TypeEval.scala index 4d162efe22ba..e9a23d800fee 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeEval.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeEval.scala @@ -84,8 +84,8 @@ object TypeEval: def runConstantOp[T](op: => T)(using Constant.ValueToConstant[T]): Type = val result = try op - catch case e: Throwable => - throw TypeError(em"${e.getMessage}") + catch case ex: Exception => + throw TypeError(em"${ex.getMessage}") ConstantType(Constant.fromValue(result)) def fieldsOf: Option[Type] = diff --git a/compiler/src/dotty/tools/dotc/core/TypeOps.scala b/compiler/src/dotty/tools/dotc/core/TypeOps.scala index e59b3c794ada..069cca698d31 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeOps.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeOps.scala @@ -504,8 +504,7 @@ object TypeOps: mapOver(tl) case _ => super.apply(tp) - catch case ex: Throwable => - handleRecursive("traversing for avoiding local references", s"${tp.show}" , ex) + catch case ex: Throwable => handleRecursive("traversing for avoiding local references", s"${tp.show}", ex) end apply /** Three deviations from standard derivedSelect: diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index e528143d20fc..e6717b51dff5 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -736,8 +736,7 @@ object Types extends TypeUtils { case tp: WildcardType => tp.effectiveBounds.hi.baseClasses case _ => Nil - catch case ex: Throwable => - handleRecursive("base classes of", this.show, ex) + catch case ex: Throwable => handleRecursive("base classes of", this.show, ex) // ----- Member access ------------------------------------------------- @@ -4967,10 +4966,7 @@ object Types extends TypeUtils { } override def toString: String = - try s"RecThis(${binder.hashCode})" - catch { - case ex: NullPointerException => s"RecThis()" - } + s"RecThis(${binder.hashCode})" } private final class RecThisImpl(binder: RecType) extends RecThis(binder) diff --git a/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala b/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala index eba64fe2b19e..00f9fd0f89eb 100644 --- a/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala +++ b/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala @@ -20,7 +20,6 @@ import scala.collection.mutable.{ ListBuffer, ArrayBuffer } import scala.annotation.switch import typer.Checking.checkNonCyclic import io.{AbstractFile, ZipArchive} -import scala.util.control.NonFatal import dotty.tools.dotc.classpath.FileUtils.hasSiblingTasty import scala.compiletime.uninitialized @@ -868,7 +867,7 @@ class ClassfileParser( } catch { case f: FatalError => throw f // don't eat fatal errors, they mean a class was not found - case NonFatal(ex) => + case ex: Exception => // We want to be robust when annotations are unavailable, so the very least // we can do is warn the user about the exception // There was a reference to ticket 1135, but that is outdated: a reference to a class not on diff --git a/compiler/src/dotty/tools/dotc/core/tasty/BestEffortTastyWriter.scala b/compiler/src/dotty/tools/dotc/core/tasty/BestEffortTastyWriter.scala index a027da8a8a29..299b9fd4c800 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/BestEffortTastyWriter.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/BestEffortTastyWriter.scala @@ -21,10 +21,7 @@ object BestEffortTastyWriter: val outstream = new DataOutputStream(new PlainFile(outTastyFile).bufferedOutput) try outstream.write(binary()) catch case ex: ClosedByInterruptException => - try - outTastyFile.delete() // don't leave an empty or half-written tastyfile around after an interrupt - catch - case _: Throwable => + outTastyFile.delete() // don't leave an empty or half-written tastyfile around after an interrupt throw ex finally outstream.close() } diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala index f75c3aa589d0..a78d9c976000 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala @@ -12,16 +12,12 @@ import ast.{untpd, tpd} import Contexts.*, Symbols.*, Types.*, Names.*, Constants.*, Decorators.*, Annotations.*, Flags.* import Comments.{Comment, docCtx} import NameKinds.* -import StdNames.{nme, tpnme} +import StdNames.nme import config.Config import config.Feature.sourceVersion import collection.mutable import reporting.{Profile, NoProfile} import dotty.tools.tasty.TastyFormat.ASTsSection -import quoted.QuotePatterns - -object TreePickler: - class StackSizeExceeded(val mdef: tpd.MemberDef) extends Exception class TreePickler(pickler: TastyPickler, attributes: Attributes) { val buf: TreeBuffer = new TreeBuffer @@ -29,7 +25,6 @@ class TreePickler(pickler: TastyPickler, attributes: Attributes) { import buf.* import pickler.nameBuffer.nameIndex import tpd.* - import TreePickler.* private val symRefs = Symbols.MutableSymbolMap[Addr](256) private val forwardSymRefs = Symbols.MutableSymbolMap[List[Addr]]() @@ -400,13 +395,7 @@ class TreePickler(pickler: TastyPickler, attributes: Attributes) { pickleTreeUnlessEmpty(rhs) pickleModifiers(sym, mdef) } - catch - case ex: Throwable => - if !ctx.settings.XnoEnrichErrorMessages.value - && handleRecursive.underlyingStackOverflowOrNull(ex) != null then - throw StackSizeExceeded(mdef) - else - throw ex + catch case t: Throwable => handleRecursive("tree pickling", mdef.show, t) if sym.is(Method) && sym.owner.isClass then profile.recordMethodSize(sym, (currentAddr.index - addr.index) max 1, mdef.span) for docCtx <- ctx.docCtx do @@ -956,15 +945,7 @@ class TreePickler(pickler: TastyPickler, attributes: Attributes) { def pickle(trees: List[Tree])(using Context): Unit = { profile = Profile.current for tree <- trees do - try - if !tree.isEmpty then pickleTree(tree) - catch case ex: StackSizeExceeded => - report.error( - em"""Recursion limit exceeded while pickling ${ex.mdef} - |in ${ex.mdef.symbol.showLocated}. - |You could try to increase the stacksize using the -Xss JVM option. - |For the unprocessed stack trace, compile with -Xno-enrich-error-messages.""", - ex.mdef.srcPos) + if !tree.isEmpty then pickleTree(tree) def missing = forwardSymRefs.keysIterator .map(sym => i"${sym.showLocated} (line ${sym.srcPos.line}) #${sym.id}") diff --git a/compiler/src/dotty/tools/dotc/fromtasty/Debug.scala b/compiler/src/dotty/tools/dotc/fromtasty/Debug.scala index 336d424e545d..a38b0fbf63ba 100644 --- a/compiler/src/dotty/tools/dotc/fromtasty/Debug.scala +++ b/compiler/src/dotty/tools/dotc/fromtasty/Debug.scala @@ -2,8 +2,6 @@ package dotty.tools package dotc package fromtasty -import scala.util.control.NonFatal - import dotty.tools.io.Directory import java.io.{File => JFile} @@ -11,11 +9,6 @@ import java.nio.file.{Files, Paths} object Debug { def main(args: Array[String]): Unit = { - // Preload scala.util.control.NonFatal. Otherwise, when trying to catch a StackOverflowError, - // we may try to load it but fail with another StackOverflowError and lose the original exception, - // see . - val _ = NonFatal - assert(!args.contains("-d")) val outPath = Paths.get("out") diff --git a/compiler/src/dotty/tools/dotc/interactive/Completion.scala b/compiler/src/dotty/tools/dotc/interactive/Completion.scala index 6c0288b2e8a6..3615875bc478 100644 --- a/compiler/src/dotty/tools/dotc/interactive/Completion.scala +++ b/compiler/src/dotty/tools/dotc/interactive/Completion.scala @@ -26,7 +26,6 @@ import dotty.tools.dotc.util.Chars import dotty.tools.dotc.util.SourcePosition import scala.collection.mutable -import scala.util.control.NonFatal import dotty.tools.dotc.core.ContextOps.localContext import dotty.tools.dotc.core.Names import dotty.tools.dotc.core.Types @@ -335,7 +334,7 @@ object Completion: try if denot.isType then denot.symbol.showFullName else denot.info.widenTermRefExpr.show - catch case NonFatal(_) => denot.symbol.name.toString + catch case _: Exception => denot.symbol.name.toString def isInNewContext(untpdPath: List[untpd.Tree]): Boolean = untpdPath match @@ -373,7 +372,7 @@ object Completion: || (completionMode.is(Mode.Type) && (sym.isType || sym.isStableMember))) ) catch - case NonFatal(ex) => + case ex: Exception => false end isValidCompletionSymbol @@ -628,7 +627,7 @@ object Completion: val tpe = asDefLikeType(tree.typeOpt.dealias) termRef.denot.asSingleDenotation.mapInfo(_ => tpe) } - catch case NonFatal(ex) => + catch case ex: Exception => logger.warning( s"Exception when trying to apply extension method:\n ${ex.getMessage()}\n${ex.getStackTrace().mkString("\n")}" ) @@ -736,7 +735,7 @@ object Completion: interactiv.println(i"implicit conversion targets considered: ${conversions.toList}%, %") conversions - } catch case NonFatal(ex) => + } catch case ex: Exception => logger.warning( s"Exception when searching for implicit conversions:\n ${ex.getMessage()}\n${ex.getStackTrace().mkString("\n")}" ) diff --git a/compiler/src/dotty/tools/dotc/interactive/LogicalPackagesProvider.scala b/compiler/src/dotty/tools/dotc/interactive/LogicalPackagesProvider.scala index b0aeed5cd0af..271f757f12bc 100644 --- a/compiler/src/dotty/tools/dotc/interactive/LogicalPackagesProvider.scala +++ b/compiler/src/dotty/tools/dotc/interactive/LogicalPackagesProvider.scala @@ -13,7 +13,6 @@ import dotty.tools.io.Path import java.io.File import scala.collection.mutable -import scala.util.control.NonFatal /** * A compiler component that adds support for parsing Scala and Java source files and finding out @@ -35,7 +34,7 @@ class LogicalPackagesProvider(sourcePath: String)(using Context){ try parseSourceFile(sourceFile, pkg) catch - case NonFatal(e) => + case e: Exception => // Silently ignore parsing errors pkg @@ -64,7 +63,7 @@ class LogicalPackagesProvider(sourcePath: String)(using Context){ val traverser = new SourceFileTraverser(fileName, rootPackage) traverser.traverse(tree) catch - case NonFatal(e) => + case e: Exception => // Silently ignore parsing errors private def parseJavaSourceFile( @@ -81,7 +80,7 @@ class LogicalPackagesProvider(sourcePath: String)(using Context){ val traverser = new SourceFileTraverser(fileName, rootPackage) traverser.traverse(tree) catch - case NonFatal(e) => + case e: Exception => // Silently ignore parsing errors /** diff --git a/compiler/src/dotty/tools/dotc/plugins/Plugin.scala b/compiler/src/dotty/tools/dotc/plugins/Plugin.scala index 09622044db50..de70138d58cf 100644 --- a/compiler/src/dotty/tools/dotc/plugins/Plugin.scala +++ b/compiler/src/dotty/tools/dotc/plugins/Plugin.scala @@ -101,15 +101,13 @@ object Plugin { /** Use a class loader to load the plugin class. */ def load(classname: String, loader: ClassLoader): Try[AnyClass] = { - import scala.util.control.NonFatal try Success[AnyClass](loader.loadClass(classname)) - catch { - case NonFatal(e) => + catch + case e: Exception => Failure(new PluginLoadException(classname, s"Error: unable to load class $classname: ${e.getMessage}")) case e: NoClassDefFoundError => Failure(new PluginLoadException(classname, s"Error: class not found: ${e.getMessage} required by $classname")) - } } /** Load all plugins specified by the arguments. diff --git a/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala b/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala index c245b201d189..2ba415f43b27 100644 --- a/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala +++ b/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala @@ -12,7 +12,6 @@ import typer.Implicits.* import typer.ImportInfo import Variances.varianceSign import util.{Chars, SourcePosition} -import scala.util.control.NonFatal import scala.annotation.switch import config.{Config, Feature} import ast.{tpd, untpd} @@ -90,7 +89,7 @@ class PlainPrinter(_ctx: Context) extends Printer { else tp private def sameBound(lo: Type, hi: Type): Boolean = - try lo frozen_=:= hi catch { case NonFatal(ex) => false } + try lo frozen_=:= hi catch { case ex: Exception => false } private def homogenizeArg(tp: Type) = tp match { case TypeBounds(lo, hi) if homogenizedView && sameBound(lo, hi) => homogenize(hi) @@ -355,7 +354,7 @@ class PlainPrinter(_ctx: Context) extends Printer { case tp: LazyRef => def refTxt = try toTextGlobal(tp.ref) - catch case _: Throwable => Str("...") // reconsider catching errors + catch case _: Exception => Str("...") // reconsider catching errors "LazyRef(" ~ refTxt ~ ")" case Range(lo, hi) => toText(lo) ~ ".." ~ toText(hi) @@ -398,8 +397,7 @@ class PlainPrinter(_ctx: Context) extends Printer { /** If -uniqid is set, the hashcode of the type, after a # */ protected def hashStr(tp: Type): String = if showUniqueIds then - try "#" + tp.hashCode - catch case ex: NullPointerException => "" + "#" + tp.hashCode else "" /** A string to append to a symbol composed of: diff --git a/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala b/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala index 8937213da9fe..eb2a42cb7b7a 100644 --- a/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala +++ b/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala @@ -340,7 +340,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { toText(elemtp) ~ "[]" case tp: LazyRef if !printDebug => try toText(tp.ref) - catch case ex: Throwable => "..." + catch case _: Exception => "..." case sel: cc.PathSelectionProto => "?.{ " ~ toText(sel.selector) ~ "}" case AnySelectionProto => diff --git a/compiler/src/dotty/tools/dotc/profile/FileUtils.scala b/compiler/src/dotty/tools/dotc/profile/FileUtils.scala index f95da89bf632..a8b26f3c0c67 100644 --- a/compiler/src/dotty/tools/dotc/profile/FileUtils.scala +++ b/compiler/src/dotty/tools/dotc/profile/FileUtils.scala @@ -26,7 +26,6 @@ import scala.concurrent.duration.Duration import scala.concurrent.{Await, Promise} import scala.util.{Failure, Success} import scala.annotation.internal.sharable -import compiletime.uninitialized object FileUtils { def newAsyncBufferedWriter(path: Path, charset: Charset = StandardCharsets.UTF_8.nn, options: Array[OpenOption] = NO_OPTIONS, threadsafe: Boolean = false): LineWriter = { @@ -185,9 +184,9 @@ object FileUtils { } } } catch { - case t: Throwable => - asyncStatus.tryFailure(t) - throw t + case ex: Exception => + asyncStatus.tryFailure(ex) + throw ex } finally scheduled.set(false) diff --git a/compiler/src/dotty/tools/dotc/report.scala b/compiler/src/dotty/tools/dotc/report.scala index cd7c917939cd..f68507ffb6a1 100644 --- a/compiler/src/dotty/tools/dotc/report.scala +++ b/compiler/src/dotty/tools/dotc/report.scala @@ -156,7 +156,7 @@ object report: def enrichErrorMessage(errorMessage: String)(using Context): String = if ctx.settings.XnoEnrichErrorMessages.value then errorMessage else try enrichErrorMessage1(errorMessage) - catch case _: Throwable => errorMessage // don't introduce new errors trying to report errors, so swallow exceptions + catch case _: Exception => errorMessage // don't introduce new errors trying to report errors, so swallow exceptions private def enrichErrorMessage1(errorMessage: String)(using Context): String = { import untpd.*, config.Settings.* diff --git a/compiler/src/dotty/tools/dotc/reporting/messages.scala b/compiler/src/dotty/tools/dotc/reporting/messages.scala index 4521df04895f..51511209e025 100644 --- a/compiler/src/dotty/tools/dotc/reporting/messages.scala +++ b/compiler/src/dotty/tools/dotc/reporting/messages.scala @@ -24,7 +24,6 @@ import typer.ErrorReporting.{err, matchReductionAddendum, substitutableTypeSymbo import typer.ProtoTypes.{ViewProto, FunProto} import typer.Implicits.* import typer.Inferencing -import scala.util.control.NonFatal import StdNames.nme import Formatting.{hl, delay} import scala.util.matching.Regex @@ -792,7 +791,7 @@ extends SyntaxMsg(WrongNumberOfTypeArgsID) { try fntpe.termSymbol match case NoSymbol => fntpe.show case symbol => symbol.showFullName - catch case NonFatal(ex) => fntpe.show + catch case ex: Exception => fntpe.show i"""|$msgPrefix type arguments for $prettyName$expectedArgString |expected: $expectedArgString |actual: $actualArgString""" diff --git a/compiler/src/dotty/tools/dotc/reporting/trace.scala b/compiler/src/dotty/tools/dotc/reporting/trace.scala index c557a6e4544c..36e698a3a364 100644 --- a/compiler/src/dotty/tools/dotc/reporting/trace.scala +++ b/compiler/src/dotty/tools/dotc/reporting/trace.scala @@ -126,7 +126,7 @@ trait TraceSyntax: case ex: runtime.NonLocalReturnControl[T @unchecked] => finalize(trailing(ex.value)) throw ex - case ex: Throwable => + case ex: Exception => val msg = s"<== $q = (with exception $ex)" finalize(msg) throw ex diff --git a/compiler/src/dotty/tools/dotc/sbt/package.scala b/compiler/src/dotty/tools/dotc/sbt/package.scala index e835a4b95fee..1b4eca3ca95a 100644 --- a/compiler/src/dotty/tools/dotc/sbt/package.scala +++ b/compiler/src/dotty/tools/dotc/sbt/package.scala @@ -10,8 +10,6 @@ import interfaces.IncrementalCallback import dotty.tools.io.FileWriters.BufferingReporter import dotty.tools.dotc.core.Decorators.em -import scala.util.control.NonFatal - inline val TermNameHash = 1987 // 300th prime inline val TypeNameHash = 1993 // 301st prime inline val InlineParamHash = 1997 // 302nd prime @@ -24,7 +22,7 @@ def asyncZincPhasesCompleted(cb: IncrementalCallback, pending: Option[BufferingR cb.apiPhaseCompleted() cb.dependencyPhaseCompleted() catch - case NonFatal(t) => + case t: Exception => zincReporter.exception(em"signaling API and Dependencies phases completion", t) zincReporter diff --git a/compiler/src/dotty/tools/dotc/semanticdb/SemanticSymbolBuilder.scala b/compiler/src/dotty/tools/dotc/semanticdb/SemanticSymbolBuilder.scala index 961ee69e029d..e55e727f639c 100644 --- a/compiler/src/dotty/tools/dotc/semanticdb/SemanticSymbolBuilder.scala +++ b/compiler/src/dotty/tools/dotc/semanticdb/SemanticSymbolBuilder.scala @@ -13,7 +13,6 @@ import Scala3.{*, given} import scala.annotation.tailrec import scala.collection.mutable -import scala.util.control.NonFatal // The API here is a little tricky because it's used both as a stateful builder with local symbols, // and for non-local symbols that do not need any state through the companion object. @@ -116,7 +115,7 @@ private[semanticdb] object SemanticSymbolBuilder: val pkg = s.split('/').map(stripBackticks).mkString(".") requiredPackage(pkg) :: Nil catch - case NonFatal(_) => + case _: Exception => Nil else val (desc, parent) = DescriptorParser(s) @@ -198,7 +197,7 @@ private[semanticdb] object SemanticSymbolBuilder: try val res = loop(sym) res.filterNot(_ == NoSymbol) - catch case NonFatal(e) => Nil + catch case e: Exception => Nil end inverseSymbol private def addName(b: StringBuilder, name: Name): Unit = diff --git a/compiler/src/dotty/tools/dotc/transform/MacroAnnotations.scala b/compiler/src/dotty/tools/dotc/transform/MacroAnnotations.scala index f01acb176ea3..c12cb5e3ce8a 100644 --- a/compiler/src/dotty/tools/dotc/transform/MacroAnnotations.scala +++ b/compiler/src/dotty/tools/dotc/transform/MacroAnnotations.scala @@ -13,9 +13,8 @@ import core.MacroClassLoader import core.Symbols.* import core.Types.* import quoted.* -import util.SrcPos -import scala.quoted.runtime.impl.{QuotesImpl, SpliceScope} +import scala.quoted.runtime.impl.{QuotesImpl, SpliceScope} import scala.quoted.Quotes import scala.util.control.NonFatal @@ -133,6 +132,8 @@ object MacroAnnotations: (List(tree), companion) case Interpreter.MissingClassValidInCurrentRun(sym, origin) => Interpreter.suspendOnMissing(sym, origin, annot.tree) + // We're dealing with user-thrown things here, so we must use NonFatal to catch anything realistic, + // including `Error`s like `NotImplementedError` case NonFatal(ex) => val stack0 = ex.getStackTrace.takeWhile(_.getClassName != this.getClass().getName()) val stack = stack0.take(1 + stack0.lastIndexWhere(_.getMethodName == "transform")) diff --git a/compiler/src/dotty/tools/dotc/transform/Pickler.scala b/compiler/src/dotty/tools/dotc/transform/Pickler.scala index 3045aa2b0fe3..964d8eaeab3b 100644 --- a/compiler/src/dotty/tools/dotc/transform/Pickler.scala +++ b/compiler/src/dotty/tools/dotc/transform/Pickler.scala @@ -30,7 +30,6 @@ import dotty.tools.dotc.sbt.interfaces.IncrementalCallback import dotty.tools.dotc.sbt.asyncZincPhasesCompleted import dotty.tools.dotc.util.chaining.* import scala.concurrent.ExecutionContext -import scala.util.control.NonFatal import java.util.concurrent.atomic.AtomicBoolean import java.nio.file.Files @@ -104,8 +103,8 @@ object Pickler { case jar: JarArchive => jar.close() case _ => catch - case NonFatal(t) => - ctx.reporter.error(em"Error closing early output: ${t}") + case ex: Exception => + ctx.reporter.error(em"Error closing early output: $ex") asyncTastyWritten.trySuccess: Some( @@ -162,11 +161,11 @@ object Pickler { if !async.cancelled then val _ = writer.writeTasty(internalName, pickled) catch - case NonFatal(t) => ctx.reporter.exception(em"writing TASTy to early output", t) + case ex: Exception => ctx.reporter.exception(em"writing TASTy to early output", ex) finally writer.close() catch - case NonFatal(t) => ctx.reporter.exception(em"closing early output writer", t) + case ex: Exception => ctx.reporter.exception(em"closing early output writer", ex) finally async.signalAsyncTastyWritten() } @@ -306,7 +305,7 @@ class Pickler extends Phase { treePkl.pickle(tree :: Nil) true catch - case NonFatal(ex) if ctx.isBestEffort => + case ex: Exception if ctx.isBestEffort => report.bestEffortError(ex, "Some best-effort tasty files will not be generated.") false Profile.current.recordTasty(treePkl.buf.length) diff --git a/compiler/src/dotty/tools/dotc/transform/Splicer.scala b/compiler/src/dotty/tools/dotc/transform/Splicer.scala index a40db72d0ccb..9a713f75de2d 100644 --- a/compiler/src/dotty/tools/dotc/transform/Splicer.scala +++ b/compiler/src/dotty/tools/dotc/transform/Splicer.scala @@ -20,7 +20,6 @@ import dotty.tools.dotc.core.Constants.Constant import dotty.tools.dotc.quoted.Interpreter -import scala.util.control.NonFatal import dotty.tools.dotc.util.SrcPos import dotty.tools.io.AbstractFileClassLoader @@ -76,7 +75,7 @@ object Splicer { case ex: StopInterpretation => report.error(ex.msg, ex.pos) ref(defn.Predef_undefined).withType(ErrorType(ex.msg)) - case NonFatal(ex) => + case ex: Exception => val msg = em"""Failed to evaluate macro. | Caused by ${ex.getClass}: ${if (ex.getMessage == null) "" else ex.getMessage} diff --git a/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala b/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala index f531cbbe4976..97f6a144ae67 100644 --- a/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala +++ b/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala @@ -26,8 +26,6 @@ import staging.StagingLevel import inlines.Inlines.inInlineMethod import cc.RetainingAnnotation -import scala.util.control.NonFatal - /** Run by -Ycheck option after a given phase, this class retypes all syntax trees * and verifies that the type of each tree node so obtained conforms to the type found in the tree node. * It also performs the following checks: @@ -128,7 +126,7 @@ class TreeChecker extends Phase with SymTransformer { } try checker.typedExpr(ctx.compilationUnit.tpdTree)(using checkingCtx) catch { - case NonFatal(ex) => //TODO CHECK. Check that we are bootstrapped + case ex: Exception => //TODO CHECK. Check that we are bootstrapped inContext(checkingCtx) { println(i"*** error while checking ${ctx.compilationUnit} after phase ${ctx.phase.prev.megaPhase(using ctx)} ***") } @@ -436,7 +434,7 @@ object TreeChecker { checkNoOrphans(res.tpe) phasesToCheck.foreach(_.checkPostCondition(res)) res - catch case NonFatal(ex) if !ctx.run.enrichedErrorMessage => + catch case ex: Exception if !ctx.run.enrichedErrorMessage => val treeStr = tree.show(using ctx.withPhase(ctx.phase.prev.megaPhase)) printer.println(ctx.run.enrichErrorMessage(s"exception while retyping $treeStr of class ${tree.className} # ${tree.uniqueId}")) throw ex diff --git a/compiler/src/dotty/tools/dotc/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala index a9a86ed61016..35d8ac8f3b68 100644 --- a/compiler/src/dotty/tools/dotc/typer/Applications.scala +++ b/compiler/src/dotty/tools/dotc/typer/Applications.scala @@ -38,7 +38,6 @@ import Denotations.SingleDenotation import annotation.threadUnsafe import scala.annotation.tailrec -import scala.util.control.NonFatal object Applications { import tpd.* diff --git a/compiler/src/dotty/tools/dotc/typer/ImportSuggestions.scala b/compiler/src/dotty/tools/dotc/typer/ImportSuggestions.scala index f0d8b2e3b135..a907c045b41b 100644 --- a/compiler/src/dotty/tools/dotc/typer/ImportSuggestions.scala +++ b/compiler/src/dotty/tools/dotc/typer/ImportSuggestions.scala @@ -13,7 +13,6 @@ import ast.{untpd, tpd} import Implicits.{hasExtMethod, Candidate} import java.util.{Timer, TimerTask} import collection.mutable -import scala.util.control.NonFatal import cc.isCaptureChecking /** This trait defines the method `importSuggestionAddendum` that adds an addendum @@ -256,7 +255,7 @@ trait ImportSuggestions: match case (Nil, partials) => (extensionImports, partials) case givenImports => givenImports - catch case NonFatal(ex) => + catch case ex: Exception => if ctx.settings.Ydebug.value then println("caught exception when searching for suggestions") ex.printStackTrace() diff --git a/compiler/src/dotty/tools/dotc/typer/Inferencing.scala b/compiler/src/dotty/tools/dotc/typer/Inferencing.scala index b7861c236b73..f28532d564eb 100644 --- a/compiler/src/dotty/tools/dotc/typer/Inferencing.scala +++ b/compiler/src/dotty/tools/dotc/typer/Inferencing.scala @@ -251,8 +251,7 @@ object Inferencing { } case tp => foldOver(x, tp) } - catch case ex: Throwable => - handleRecursive("check fully defined", tp.showSummary(20), ex) + catch case ex: Throwable => handleRecursive("check fully defined", tp.showSummary(20), ex) } def process(tp: Type): Boolean = diff --git a/compiler/src/dotty/tools/dotc/typer/ReTyper.scala b/compiler/src/dotty/tools/dotc/typer/ReTyper.scala index 8400639706d6..cd416c460241 100644 --- a/compiler/src/dotty/tools/dotc/typer/ReTyper.scala +++ b/compiler/src/dotty/tools/dotc/typer/ReTyper.scala @@ -9,7 +9,6 @@ import StdNames.* import Decorators.* import typer.ProtoTypes.* import ast.{tpd, untpd} -import scala.util.control.NonFatal import util.Spans.Span import Nullables.* import staging.StagingLevel.* diff --git a/compiler/src/dotty/tools/io/FileWriters.scala b/compiler/src/dotty/tools/io/FileWriters.scala index 59e69bdd731f..fcf63a366404 100644 --- a/compiler/src/dotty/tools/io/FileWriters.scala +++ b/compiler/src/dotty/tools/io/FileWriters.scala @@ -328,7 +328,7 @@ object FileWriters { catch { case ex: ClosedByInterruptException => try Files.deleteIfExists(path) // don't leave a empty of half-written classfile around after an interrupt - catch { case _: Throwable => () } + catch { case _: java.io.IOException => () } throw ex } os.close() diff --git a/compiler/src/dotty/tools/io/Path.scala b/compiler/src/dotty/tools/io/Path.scala index 93e54069f421..ee5b2cd82b05 100644 --- a/compiler/src/dotty/tools/io/Path.scala +++ b/compiler/src/dotty/tools/io/Path.scala @@ -210,7 +210,7 @@ class Path private[io] (val jpath: JPath) { // deletions def delete(): Unit = - try { Files.deleteIfExists(jpath) } catch { case _: DirectoryNotEmptyException => } + try { Files.deleteIfExists(jpath) } catch { case _: java.io.IOException => } /** Deletes the path recursively. Returns false on failure. * Use with caution! diff --git a/compiler/test/dotty/tools/dotc/CoverageSupport.scala b/compiler/test/dotty/tools/dotc/CoverageSupport.scala index d1fb60491ed2..d69d0c6dd794 100644 --- a/compiler/test/dotty/tools/dotc/CoverageSupport.scala +++ b/compiler/test/dotty/tools/dotc/CoverageSupport.scala @@ -6,7 +6,6 @@ import scala.language.unsafeNulls import java.nio.file.{Files, Paths} import scala.util.Try -import scala.util.control.NonFatal import dotty.tools.dotc.coverage.Serializer import vulpix.* import reporting.TestReporter @@ -97,7 +96,7 @@ trait CoverageSupport: .sorted(java.util.Comparator.reverseOrder()) .forEach(Files.delete) catch - case NonFatal(_) => // Ignore cleanup errors + case _: Exception => // Ignore cleanup errors end try end if end verifyCoverageFile diff --git a/compiler/test/dotty/tools/dotc/parsing/ScannerTest.scala b/compiler/test/dotty/tools/dotc/parsing/ScannerTest.scala index 65548ebbae95..120370631a49 100644 --- a/compiler/test/dotty/tools/dotc/parsing/ScannerTest.scala +++ b/compiler/test/dotty/tools/dotc/parsing/ScannerTest.scala @@ -48,7 +48,6 @@ class ScannerTest extends DottyTest { @Test def scanList() = { - println(System.getProperty("user.dir")) scan("compiler/src/dotty/tools/dotc/core/Symbols.scala") scan("compiler/src/dotty/tools/dotc/core/Symbols.scala") } diff --git a/compiler/test/dotty/tools/dotc/printing/PrintingTest.scala b/compiler/test/dotty/tools/dotc/printing/PrintingTest.scala index 703e21b8398c..eb536cb50dc2 100644 --- a/compiler/test/dotty/tools/dotc/printing/PrintingTest.scala +++ b/compiler/test/dotty/tools/dotc/printing/PrintingTest.scala @@ -12,7 +12,6 @@ import reporting.TestReporter import java.io.* import java.nio.file.{Path => JPath} -import java.lang.System.{lineSeparator => EOL} import java.nio.charset.StandardCharsets import interfaces.Diagnostic.INFO @@ -46,6 +45,7 @@ class PrintingTest { case e: Throwable => println(s"Compile $path exception:") e.printStackTrace() + throw e } val actualLines = byteStream.toString(StandardCharsets.UTF_8.name).linesIterator diff --git a/compiler/test/dotty/tools/dotc/semanticdb/SemanticdbTests.scala b/compiler/test/dotty/tools/dotc/semanticdb/SemanticdbTests.scala index 20cac8e7b321..0820a0d13646 100644 --- a/compiler/test/dotty/tools/dotc/semanticdb/SemanticdbTests.scala +++ b/compiler/test/dotty/tools/dotc/semanticdb/SemanticdbTests.scala @@ -8,7 +8,6 @@ import java.nio.file.* import java.nio.charset.StandardCharsets import java.util.stream.Collectors import java.util.Comparator -import scala.util.control.NonFatal import scala.collection.mutable import scala.jdk.CollectionConverters.* import javax.tools.ToolProvider diff --git a/tests/neg-macros/i19842-a.check b/tests/neg-macros/i19842-a.check index 493ccb36b611..dc98ac38937f 100644 --- a/tests/neg-macros/i19842-a.check +++ b/tests/neg-macros/i19842-a.check @@ -8,7 +8,7 @@ |Parents in tree: [trait Serializer] | | at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:10) - | at dotty.tools.dotc.transform.TreeChecker$.checkParents(TreeChecker.scala:208) + | at dotty.tools.dotc.transform.TreeChecker$.checkParents(TreeChecker.scala:206) | at scala.quoted.runtime.impl.QuotesImpl$reflect$ClassDef$.module(QuotesImpl.scala:284) | at scala.quoted.runtime.impl.QuotesImpl$reflect$ClassDef$.module(QuotesImpl.scala:283) | at Macros$.makeSerializer(Macro.scala:23) diff --git a/tests/neg-macros/i19842-b.check b/tests/neg-macros/i19842-b.check index e2ed2bb7ec88..761dc0ecd4d8 100644 --- a/tests/neg-macros/i19842-b.check +++ b/tests/neg-macros/i19842-b.check @@ -8,7 +8,7 @@ |Parents in tree: [class Object, trait Serializer, trait Foo] | | at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:10) - | at dotty.tools.dotc.transform.TreeChecker$.checkParents(TreeChecker.scala:208) + | at dotty.tools.dotc.transform.TreeChecker$.checkParents(TreeChecker.scala:206) | at scala.quoted.runtime.impl.QuotesImpl$reflect$ClassDef$.module(QuotesImpl.scala:284) | at scala.quoted.runtime.impl.QuotesImpl$reflect$ClassDef$.module(QuotesImpl.scala:283) | at Macros$.makeSerializer(Macro.scala:25)