diff --git a/compiler/src/dotty/tools/dotc/ast/Trees.scala b/compiler/src/dotty/tools/dotc/ast/Trees.scala index 5229995ae6cb..429254d6c75c 100644 --- a/compiler/src/dotty/tools/dotc/ast/Trees.scala +++ b/compiler/src/dotty/tools/dotc/ast/Trees.scala @@ -113,7 +113,11 @@ object Trees { */ def withType(tpe: Type)(implicit ctx: Context): ThisTree[Type] = { if (tpe.isInstanceOf[ErrorType]) - assert(!Config.checkUnreportedErrors || ctx.reporter.errorsReported) + assert(!Config.checkUnreportedErrors || + ctx.reporter.errorsReported || + ctx.settings.YshowPrintErrors.value + // under -Yshow-print-errors, errors might arise during printing, but they do not count as reported + ) else if (Config.checkTreesConsistent) checkChildrenTyped(productIterator) withTypeUnchecked(tpe) diff --git a/compiler/src/dotty/tools/dotc/printing/Formatting.scala b/compiler/src/dotty/tools/dotc/printing/Formatting.scala index d16d49e82fac..e9f88523d8b8 100644 --- a/compiler/src/dotty/tools/dotc/printing/Formatting.scala +++ b/compiler/src/dotty/tools/dotc/printing/Formatting.scala @@ -34,7 +34,7 @@ object Formatting { case NonFatal(ex) if !ctx.mode.is(Mode.PrintShowExceptions) && !ctx.settings.YshowPrintErrors.value => - s"[cannot display due to $ex, raw string = $toString]" + s"[cannot display due to $ex, raw string = ${arg.toString}]" } case _ => arg.toString } diff --git a/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala b/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala index a6edd2ed7c4d..f5f503207e05 100644 --- a/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala +++ b/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala @@ -196,7 +196,12 @@ class PlainPrinter(_ctx: Context) extends Printer { else toText(tp.origin) } case tp: LazyRef => - "LazyRef(" ~ toTextGlobal(tp.ref) ~ ")" // TODO: only print this during debug mode? + def refTxt = + try toTextGlobal(tp.ref) + catch { + case ex: Throwable => Str("...") + } + "LazyRef(" ~ refTxt ~ ")" case _ => tp.fallbackToText(this) } @@ -217,7 +222,10 @@ class PlainPrinter(_ctx: Context) extends Printer { /** If -uniqid is set, the hashcode of the lambda type, after a # */ protected def lambdaHash(pt: LambdaType): Text = - if (ctx.settings.uniqid.value) "#" + pt.hashCode else "" + if (ctx.settings.uniqid.value) + try "#" + pt.hashCode + catch { case ex: NullPointerException => "" } + else "" /** If -uniqid is set, the unique id of symbol, after a # */ protected def idString(sym: Symbol): String = diff --git a/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala b/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala index 57587541d036..fddd463e393c 100644 --- a/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala +++ b/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala @@ -501,7 +501,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { typeDefText(tparamsTxt, toText(rhs)) case LambdaTypeTree(tparams, body) => recur(body, tparamsText(tparams)) - case rhs: TypeTree if rhs.tpe.isInstanceOf[TypeBounds] => + case rhs: TypeTree if rhs.typeOpt.isInstanceOf[TypeBounds] => typeDefText(tparamsTxt, toText(rhs)) case rhs => typeDefText(tparamsTxt, optText(rhs)(" = " ~ _)) diff --git a/tests/pos/i3703.scala b/tests/pos/i3703.scala new file mode 100644 index 000000000000..9fa67efd330a --- /dev/null +++ b/tests/pos/i3703.scala @@ -0,0 +1,11 @@ +package bar { + trait M[F[_]] + class S[XS[_] <: M[XS], A](val x: XS[A]) + object S { + def apply[X[_] <: M[X], A](x: X[A]): S[X, A] = S[X, A](x) + def unapply[X[_] <: M[X], A](p: S[X, A]): S[X, A] = S(p.x) + } +} + + +