Skip to content

Commit bdf5d80

Browse files
authored
Merge pull request #3705 from dotty-staging/fix-#3703
Fix #3703: Various fixes to make printing more robust in face of errors
2 parents 31a81fb + 03c6526 commit bdf5d80

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

compiler/src/dotty/tools/dotc/ast/Trees.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,11 @@ object Trees {
113113
*/
114114
def withType(tpe: Type)(implicit ctx: Context): ThisTree[Type] = {
115115
if (tpe.isInstanceOf[ErrorType])
116-
assert(!Config.checkUnreportedErrors || ctx.reporter.errorsReported)
116+
assert(!Config.checkUnreportedErrors ||
117+
ctx.reporter.errorsReported ||
118+
ctx.settings.YshowPrintErrors.value
119+
// under -Yshow-print-errors, errors might arise during printing, but they do not count as reported
120+
)
117121
else if (Config.checkTreesConsistent)
118122
checkChildrenTyped(productIterator)
119123
withTypeUnchecked(tpe)

compiler/src/dotty/tools/dotc/printing/Formatting.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ object Formatting {
3434
case NonFatal(ex)
3535
if !ctx.mode.is(Mode.PrintShowExceptions) &&
3636
!ctx.settings.YshowPrintErrors.value =>
37-
s"[cannot display due to $ex, raw string = $toString]"
37+
s"[cannot display due to $ex, raw string = ${arg.toString}]"
3838
}
3939
case _ => arg.toString
4040
}

compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,12 @@ class PlainPrinter(_ctx: Context) extends Printer {
196196
else toText(tp.origin)
197197
}
198198
case tp: LazyRef =>
199-
"LazyRef(" ~ toTextGlobal(tp.ref) ~ ")" // TODO: only print this during debug mode?
199+
def refTxt =
200+
try toTextGlobal(tp.ref)
201+
catch {
202+
case ex: Throwable => Str("...")
203+
}
204+
"LazyRef(" ~ refTxt ~ ")"
200205
case _ =>
201206
tp.fallbackToText(this)
202207
}
@@ -217,7 +222,10 @@ class PlainPrinter(_ctx: Context) extends Printer {
217222

218223
/** If -uniqid is set, the hashcode of the lambda type, after a # */
219224
protected def lambdaHash(pt: LambdaType): Text =
220-
if (ctx.settings.uniqid.value) "#" + pt.hashCode else ""
225+
if (ctx.settings.uniqid.value)
226+
try "#" + pt.hashCode
227+
catch { case ex: NullPointerException => "" }
228+
else ""
221229

222230
/** If -uniqid is set, the unique id of symbol, after a # */
223231
protected def idString(sym: Symbol): String =

tests/pos/i3703.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package bar {
2+
trait M[F[_]]
3+
class S[XS[_] <: M[XS], A](val x: XS[A])
4+
object S {
5+
def apply[X[_] <: M[X], A](x: X[A]): S[X, A] = S[X, A](x)
6+
def unapply[X[_] <: M[X], A](p: S[X, A]): S[X, A] = S(p.x)
7+
}
8+
}
9+
10+
11+

0 commit comments

Comments
 (0)