Skip to content

Fix more problems detected by fuzzing in #4389 #4411

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Apr 30, 2018
Merged
5 changes: 2 additions & 3 deletions compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,8 @@ object desugar {
else {
def msg =
s"no matching symbol for ${tp.symbol.showLocated} in ${defctx.owner} / ${defctx.effectiveScope.toList}"
if (ctx.reporter.errorsReported) ErrorType(msg)
else throw new java.lang.Error(msg)
}
ErrorType(msg).assertingErrorsReported(msg)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong indentation.

}
case _ =>
mapOver(tp)
}
Expand Down
10 changes: 9 additions & 1 deletion compiler/src/dotty/tools/dotc/core/Decorators.scala
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,16 @@ object Decorators {
recur(enclosingInlineds, pos)
}

implicit class reportingDeco[T](val x: T) extends AnyVal {
implicit class genericDeco[T](val x: T) extends AnyVal {
def reporting(op: T => String): T = { println(op(x)); x }
def assertingErrorsReported(implicit ctx: Context): T = {
assert(ctx.reporter.errorsReported)
x
}
def assertingErrorsReported(msg: => String)(implicit ctx: Context): T = {
assert(ctx.reporter.errorsReported, msg)
x
}
}

implicit class StringInterpolators(val sc: StringContext) extends AnyVal {
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
case Apply(Apply(unapply, `dummyArg` :: Nil), args2) => assert(args2.nonEmpty); args2
case Apply(unapply, `dummyArg` :: Nil) => Nil
case Inlined(u, _, _) => unapplyImplicits(u)
case _ => assert(ctx.reporter.errorsReported); Nil
case _ => Nil.assertingErrorsReported
}

var argTypes = unapplyArgs(unapplyApp.tpe, unapplyFn, args, tree.pos)
Expand Down
14 changes: 4 additions & 10 deletions compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,7 @@ object NamerContextOps {
private def findModuleBuddy(name: Name, scope: Scope)(implicit ctx: Context) = {
val it = scope.lookupAll(name).filter(_ is Module)
if (it.hasNext) it.next()
else {
assert(ctx.reporter.errorsReported, s"no companion $name in $scope")
NoSymbol
}
else NoSymbol.assertingErrorsReported(s"no companion $name in $scope")
}
}

Expand Down Expand Up @@ -921,8 +918,7 @@ class Namer { typer: Typer =>
fullyDefinedType(typedAheadExpr(parent).tpe, "class parent", parent.pos)
}
case _ =>
assert(ctx.reporter.errorsReported)
UnspecifiedErrorType
UnspecifiedErrorType.assertingErrorsReported
}
}

Expand Down Expand Up @@ -1036,10 +1032,8 @@ class Namer { typer: Typer =>
*/
def moduleValSig(sym: Symbol)(implicit ctx: Context): Type = {
val clsName = sym.name.moduleClassName
val cls = ctx.denotNamed(clsName).suchThat(_ is ModuleClass).orElse {
assert(ctx.reporter.errorsReported)
ctx.newStubSymbol(ctx.owner, clsName)
}
val cls = ctx.denotNamed(clsName).suchThat(_ is ModuleClass)
.orElse(ctx.newStubSymbol(ctx.owner, clsName).assertingErrorsReported)
ctx.owner.thisType.select(clsName, cls)
}

Expand Down
6 changes: 2 additions & 4 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1448,10 +1448,8 @@ class Typer extends Namer
}

def typedClassDef(cdef: untpd.TypeDef, cls: ClassSymbol)(implicit ctx: Context): Tree = track("typedClassDef") {
if (!cls.info.isInstanceOf[ClassInfo]) {
assert(ctx.reporter.errorsReported)
return cdef.withType(UnspecifiedErrorType)
}
if (!cls.info.isInstanceOf[ClassInfo]) return EmptyTree.assertingErrorsReported

val TypeDef(name, impl @ Template(constr, parents, self, _)) = cdef
val superCtx = ctx.superCallContext

Expand Down