Skip to content

Commit 690321d

Browse files
committed
Streamline "assert errors reported" logic
1 parent 5f9f3a7 commit 690321d

File tree

5 files changed

+18
-19
lines changed

5 files changed

+18
-19
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,8 @@ object desugar {
8888
else {
8989
def msg =
9090
s"no matching symbol for ${tp.symbol.showLocated} in ${defctx.owner} / ${defctx.effectiveScope.toList}"
91-
if (ctx.reporter.errorsReported) ErrorType(msg)
92-
else throw new java.lang.Error(msg)
93-
}
91+
ErrorType(msg).assertingErrorsReported(msg)
92+
}
9493
case _ =>
9594
mapOver(tp)
9695
}

compiler/src/dotty/tools/dotc/core/Decorators.scala

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,16 @@ object Decorators {
175175
recur(enclosingInlineds, pos)
176176
}
177177

178-
implicit class reportingDeco[T](val x: T) extends AnyVal {
178+
implicit class genericDeco[T](val x: T) extends AnyVal {
179179
def reporting(op: T => String): T = { println(op(x)); x }
180+
def assertingErrorsReported(implicit ctx: Context): T = {
181+
assert(ctx.reporter.errorsReported)
182+
x
183+
}
184+
def assertingErrorsReported(msg: => String)(implicit ctx: Context): T = {
185+
assert(ctx.reporter.errorsReported, msg)
186+
x
187+
}
180188
}
181189

182190
implicit class StringInterpolators(val sc: StringContext) extends AnyVal {

compiler/src/dotty/tools/dotc/typer/Applications.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
973973
case Apply(Apply(unapply, `dummyArg` :: Nil), args2) => assert(args2.nonEmpty); args2
974974
case Apply(unapply, `dummyArg` :: Nil) => Nil
975975
case Inlined(u, _, _) => unapplyImplicits(u)
976-
case _ => assert(ctx.reporter.errorsReported); Nil
976+
case _ => Nil.assertingErrorsReported
977977
}
978978

979979
var argTypes = unapplyArgs(unapplyApp.tpe, unapplyFn, args, tree.pos)

compiler/src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,7 @@ object NamerContextOps {
165165
private def findModuleBuddy(name: Name, scope: Scope)(implicit ctx: Context) = {
166166
val it = scope.lookupAll(name).filter(_ is Module)
167167
if (it.hasNext) it.next()
168-
else {
169-
assert(ctx.reporter.errorsReported, s"no companion $name in $scope")
170-
NoSymbol
171-
}
168+
else NoSymbol.assertingErrorsReported(s"no companion $name in $scope")
172169
}
173170
}
174171

@@ -921,8 +918,7 @@ class Namer { typer: Typer =>
921918
fullyDefinedType(typedAheadExpr(parent).tpe, "class parent", parent.pos)
922919
}
923920
case _ =>
924-
assert(ctx.reporter.errorsReported)
925-
UnspecifiedErrorType
921+
UnspecifiedErrorType.assertingErrorsReported
926922
}
927923
}
928924

@@ -1036,10 +1032,8 @@ class Namer { typer: Typer =>
10361032
*/
10371033
def moduleValSig(sym: Symbol)(implicit ctx: Context): Type = {
10381034
val clsName = sym.name.moduleClassName
1039-
val cls = ctx.denotNamed(clsName).suchThat(_ is ModuleClass).orElse {
1040-
assert(ctx.reporter.errorsReported)
1041-
ctx.newStubSymbol(ctx.owner, clsName)
1042-
}
1035+
val cls = ctx.denotNamed(clsName).suchThat(_ is ModuleClass)
1036+
.orElse(ctx.newStubSymbol(ctx.owner, clsName).assertingErrorsReported)
10431037
ctx.owner.thisType.select(clsName, cls)
10441038
}
10451039

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,10 +1448,8 @@ class Typer extends Namer
14481448
}
14491449

14501450
def typedClassDef(cdef: untpd.TypeDef, cls: ClassSymbol)(implicit ctx: Context): Tree = track("typedClassDef") {
1451-
if (!cls.info.isInstanceOf[ClassInfo]) {
1452-
assert(ctx.reporter.errorsReported)
1453-
return cdef.withType(UnspecifiedErrorType)
1454-
}
1451+
if (!cls.info.isInstanceOf[ClassInfo]) return EmptyTree.assertingErrorsReported
1452+
14551453
val TypeDef(name, impl @ Template(constr, parents, self, _)) = cdef
14561454
val superCtx = ctx.superCallContext
14571455

0 commit comments

Comments
 (0)