From 1fec582b4e85de715e92ccb621ac55e02874558e Mon Sep 17 00:00:00 2001 From: Felix Mulder Date: Mon, 7 Nov 2016 13:12:26 +0100 Subject: Inline iff reporter has no new errors post typing `rhs` --- src/dotty/tools/dotc/reporting/Reporter.scala | 16 ++++++++++++++++ src/dotty/tools/dotc/typer/Inliner.scala | 5 +---- 2 files changed, 17 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/dotty/tools/dotc/reporting/Reporter.scala b/src/dotty/tools/dotc/reporting/Reporter.scala index b38334412..49bd3e811 100644 --- a/src/dotty/tools/dotc/reporting/Reporter.scala +++ b/src/dotty/tools/dotc/reporting/Reporter.scala @@ -167,6 +167,22 @@ trait Reporting { this: Context => throw ex } } + + /** Implements a fold that applies the function `f` to the result of `op` if + * there are no new errors in the reporter + * + * @param op operation checked for errors + * @param f function applied to result of op + * @return either the result of `op` if it had errors or the result of `f` + * applied to it + */ + def withNoError[A, B >: A](op: => A)(f: A => B): B = { + val before = reporter.errorCount + val op0 = op + + if (reporter.errorCount > before) op0 + else f(op0) + } } /** diff --git a/src/dotty/tools/dotc/typer/Inliner.scala b/src/dotty/tools/dotc/typer/Inliner.scala index 72a0158a5..6499167ad 100644 --- a/src/dotty/tools/dotc/typer/Inliner.scala +++ b/src/dotty/tools/dotc/typer/Inliner.scala @@ -190,10 +190,7 @@ object Inliner { val inlineCtx = ctx sym.updateAnnotation(LazyBodyAnnotation { _ => implicit val ctx: Context = inlineCtx - val tree1 = treeExpr(ctx) - if (tree1.hasType && !tree1.tpe.isError) - makeInlineable(tree1) - else tree1 + ctx.withNoError(treeExpr(ctx))(makeInlineable) }) } } -- cgit v1.2.3