Skip to content

Commit baade1c

Browse files
committed
Fix #3383: Don't fail on unreported errors
#3383 shows that there are valid cases where an error type is assigned to a tree before the error is reported. The error will then be reported later in `adapt`.
1 parent be50d2c commit baade1c

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ object Trees {
112112
* type. (Overridden by empty trees)
113113
*/
114114
def withType(tpe: Type)(implicit ctx: Context): ThisTree[Type] = {
115-
if (tpe.isInstanceOf[ErrorType])
116-
assert(ctx.mode.is(Mode.Interactive) || ctx.reporter.errorsReported)
117-
else if (Config.checkTreesConsistent)
115+
if (Config.checkUnreportedErrors)
116+
if (tpe.isInstanceOf[ErrorType]) assert(ctx.reporter.errorsReported)
117+
if (Config.checkTreesConsistent)
118118
checkChildrenTyped(productIterator)
119119
withTypeUnchecked(tpe)
120120
}

compiler/src/dotty/tools/dotc/config/Config.scala

+12
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,18 @@ object Config {
106106
*/
107107
final val checkTypeRefCycles = false
108108

109+
/** If this flag is set, we check that types assigned to trees are error types only
110+
* if some error was already reported. There are complicicated scenarios where this
111+
* is not true. An example is TestNonCyclic in posTwice. If we remove the
112+
* first (unused) import `import dotty.tools.dotc.core.Types.Type` in `CompilationUnit`,
113+
* we end up assigning a CyclicReference error type to an import expression `annotation`
114+
* before the cyclic reference is reported. What happens is that the error was reported
115+
* as a result of a completion in a not-yet committed typerstate. So we cannot enforce
116+
* this in all circumstances. But since it is almost always true it is useful to
117+
* keep the Config option for debugging.
118+
*/
119+
final val checkUnreportedErrors = false
120+
109121
/** If this flag is set, it is checked that class type parameters are
110122
* only references with NoPrefix or ThisTypes as prefixes. This option
111123
* is usally disabled, because there are still some legitimate cases where

0 commit comments

Comments
 (0)