From 52c13e29dd4a6e5ffd6cff600f09f65c1af5b9ce Mon Sep 17 00:00:00 2001 From: Liu Fengyun Date: Mon, 25 Mar 2019 15:02:09 +0100 Subject: [PATCH] Improve debugging for explained --- compiler/src/dotty/tools/dotc/core/TypeComparer.scala | 5 ++--- compiler/src/dotty/tools/dotc/transform/patmat/Space.scala | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala index 3e7fce488a6a..3314cb2abfef 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala @@ -2076,15 +2076,14 @@ object TypeComparer { /** Show trace of comparison operations when performing `op` as result string */ def explaining[T](say: String => Unit)(op: Context => T)(implicit ctx: Context): T = { val nestedCtx = ctx.fresh.setTypeComparerFn(new ExplainingTypeComparer(_)) - val res = op(nestedCtx) - say(nestedCtx.typeComparer.lastTrace()) + val res = try { op(nestedCtx) } finally { say(nestedCtx.typeComparer.lastTrace()) } res } /** Like [[explaining]], but returns the trace instead */ def explained[T](op: Context => T)(implicit ctx: Context): String = { var trace: String = null - explaining(trace = _)(op) + try { explaining(trace = _)(op) } catch { case ex: Throwable => ex.printStackTrace } trace } } diff --git a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala index 1a143f1d772c..a51a5507d52d 100644 --- a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala +++ b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala @@ -405,8 +405,8 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic { /** Is `tp1` a subtype of `tp2`? */ def isSubType(tp1: Type, tp2: Type): Boolean = { + debug.println(TypeComparer.explained(implicit ctx => tp1 <:< tp2)) val res = (tp1 != nullType || tp2 == nullType) && tp1 <:< tp2 - debug.println(s"${tp1} <:< ${tp2} = $res") res }