diff options
author | Martin Odersky <odersky@gmail.com> | 2015-05-16 11:23:50 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2015-05-21 17:41:13 +0200 |
commit | 9ab86534d7225edcafd3e16849b638c1d99aea69 (patch) | |
tree | 07d7e709c77f878442e7c1d3bda7f0189296db9d | |
parent | 3d9d90e1a29a80f9df968a0e53e01ecb31c397c7 (diff) | |
download | dotty-9ab86534d7225edcafd3e16849b638c1d99aea69.tar.gz dotty-9ab86534d7225edcafd3e16849b638c1d99aea69.tar.bz2 dotty-9ab86534d7225edcafd3e16849b638c1d99aea69.zip |
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.
-rw-r--r-- | src/dotty/tools/dotc/core/Types.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/printing/PlainPrinter.scala | 3 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Mode.scala | 2 |
3 files changed, 5 insertions, 2 deletions
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 } |