From 9ab86534d7225edcafd3e16849b638c1d99aea69 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sat, 16 May 2015 11:23:50 +0200 Subject: Add "Printing" mode Idea: when printing, we should be more lenient about conditions that would otherwise cause an assertion failure, because we want to avoid triggering further assertions while diagnosing previous errors. As a start we generalize an assertion that RefinedTypes cannot be created after erasure. This gets triggered when playing around with printing lambdas at erasure time (see following commit): erasure runs at phase erasure + 1, so ctx.erasedTypes is true, but we might still want to print lambdas then, and printing lambdas will create new refined types as of next commit. --- src/dotty/tools/dotc/core/Types.scala | 2 +- src/dotty/tools/dotc/printing/PlainPrinter.scala | 3 ++- src/dotty/tools/dotc/typer/Mode.scala | 2 ++ 3 files changed, 5 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index 3ab621db1..7d11ffae8 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -1842,7 +1842,7 @@ object Types { else make(RefinedType(parent, names.head, infoFns.head), names.tail, infoFns.tail) def apply(parent: Type, name: Name, infoFn: RefinedType => Type)(implicit ctx: Context): RefinedType = { - assert(!ctx.erasedTypes) + assert(!ctx.erasedTypes || ctx.mode.is(Mode.Printing)) ctx.base.uniqueRefinedTypes.enterIfNew(new CachedRefinedType(parent, name, infoFn)).checkInst } diff --git a/src/dotty/tools/dotc/printing/PlainPrinter.scala b/src/dotty/tools/dotc/printing/PlainPrinter.scala index fb1c0fc74..9e4c43fec 100644 --- a/src/dotty/tools/dotc/printing/PlainPrinter.scala +++ b/src/dotty/tools/dotc/printing/PlainPrinter.scala @@ -8,10 +8,11 @@ import StdNames.nme import ast.Trees._, ast._ import java.lang.Integer.toOctalString import config.Config.summarizeDepth +import typer.Mode import scala.annotation.switch class PlainPrinter(_ctx: Context) extends Printer { - protected[this] implicit def ctx: Context = _ctx + protected[this] implicit def ctx: Context = _ctx.fresh.addMode(Mode.Printing) protected def maxToTextRecursions = 100 diff --git a/src/dotty/tools/dotc/typer/Mode.scala b/src/dotty/tools/dotc/typer/Mode.scala index 997741819..b585cc793 100644 --- a/src/dotty/tools/dotc/typer/Mode.scala +++ b/src/dotty/tools/dotc/typer/Mode.scala @@ -63,5 +63,7 @@ object Mode { */ val AllowDependentFunctions = newMode(9, "AllowDependentFunctions") + val Printing = newMode(10, "Printing") + val PatternOrType = Pattern | Type } -- cgit v1.2.3