diff options
author | odersky <odersky@gmail.com> | 2016-11-07 19:08:05 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-07 19:08:05 +0100 |
commit | 5cef7a9098422dd568e9bc7e8eb5c9e4f04d4396 (patch) | |
tree | 33fa76c475d803f1b8bd0b0cb7275df2d87cb135 | |
parent | d1e0d3bc7096022d03928b78c33f9ffabae16aa5 (diff) | |
parent | 1fec582b4e85de715e92ccb621ac55e02874558e (diff) | |
download | dotty-5cef7a9098422dd568e9bc7e8eb5c9e4f04d4396.tar.gz dotty-5cef7a9098422dd568e9bc7e8eb5c9e4f04d4396.tar.bz2 dotty-5cef7a9098422dd568e9bc7e8eb5c9e4f04d4396.zip |
Merge pull request #1607 from felixmulder/topic/fix-inline-untyped
Fix #1605: don't inline methods that have errors
-rw-r--r-- | src/dotty/tools/dotc/reporting/Reporter.scala | 16 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Inliner.scala | 5 | ||||
-rw-r--r-- | tests/neg/i1605.scala | 5 |
3 files changed, 23 insertions, 3 deletions
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 4869b5e16..6499167ad 100644 --- a/src/dotty/tools/dotc/typer/Inliner.scala +++ b/src/dotty/tools/dotc/typer/Inliner.scala @@ -146,7 +146,7 @@ object Inliner { addAccessor(tree, methPart, targs, argss, accessedType = methPart.tpe.widen, rhs = (qual, tps, argss) => qual.appliedToTypes(tps).appliedToArgss(argss)) - } else { + } else { // TODO: Handle references to non-public types. // This is quite tricky, as such types can appear anywhere, including as parts // of types of other things. For the moment we do nothing and complain @@ -190,8 +190,7 @@ object Inliner { val inlineCtx = ctx sym.updateAnnotation(LazyBodyAnnotation { _ => implicit val ctx: Context = inlineCtx - val tree1 = treeExpr(ctx) - makeInlineable(tree1) + ctx.withNoError(treeExpr(ctx))(makeInlineable) }) } } diff --git a/tests/neg/i1605.scala b/tests/neg/i1605.scala new file mode 100644 index 000000000..776f2df47 --- /dev/null +++ b/tests/neg/i1605.scala @@ -0,0 +1,5 @@ +object Test { + def foo = inlineMe + + inline def inlineMe = 1 + x // error +} |