aboutsummaryrefslogtreecommitdiff
path: root/compiler/src/dotty/tools/dotc/typer/Inliner.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2017-02-21 09:28:22 +0100
committerMartin Odersky <odersky@gmail.com>2017-02-21 09:28:30 +0100
commit5f9e569926728e7f591a26729efa7700387aeb22 (patch)
tree435f8bc107e8def412ce00aef5fbc4d633ac1f53 /compiler/src/dotty/tools/dotc/typer/Inliner.scala
parentf467be62da8978e506f58b702b84e74ef7ce09de (diff)
downloaddotty-5f9e569926728e7f591a26729efa7700387aeb22.tar.gz
dotty-5f9e569926728e7f591a26729efa7700387aeb22.tar.bz2
dotty-5f9e569926728e7f591a26729efa7700387aeb22.zip
Don't inline when errors are detected
Inlining is only well-defined if the body to inline does not have any errors. We therefore check for errors before we perform any transformation of trees related to inlining. The error check is global, i.e. we stop on any error not just on errors in the code to be inlined. This is a safe approximation, of course.
Diffstat (limited to 'compiler/src/dotty/tools/dotc/typer/Inliner.scala')
-rw-r--r--compiler/src/dotty/tools/dotc/typer/Inliner.scala11
1 files changed, 7 insertions, 4 deletions
diff --git a/compiler/src/dotty/tools/dotc/typer/Inliner.scala b/compiler/src/dotty/tools/dotc/typer/Inliner.scala
index cfc0003c6..3fa39edd5 100644
--- a/compiler/src/dotty/tools/dotc/typer/Inliner.scala
+++ b/compiler/src/dotty/tools/dotc/typer/Inliner.scala
@@ -27,7 +27,7 @@ import transform.TypeUtils._
object Inliner {
import tpd._
- /** Adds accessors accessors for all non-public term members accessed
+ /** Adds accessors for all non-public term members accessed
* from `tree`. Non-public type members are currently left as they are.
* This means that references to a private type will lead to typing failures
* on the code when it is inlined. Less than ideal, but hard to do better (see below).
@@ -190,7 +190,8 @@ object Inliner {
val inlineCtx = ctx
sym.updateAnnotation(LazyBodyAnnotation { _ =>
implicit val ctx = inlineCtx
- ctx.withNoError(treeExpr(ctx))(makeInlineable)
+ val body = treeExpr(ctx)
+ if (ctx.reporter.hasErrors) body else makeInlineable(body)
})
}
}
@@ -233,8 +234,10 @@ object Inliner {
* and body that replace it.
*/
def inlineCall(tree: Tree, pt: Type)(implicit ctx: Context): Tree =
- if (enclosingInlineds.length < ctx.settings.xmaxInlines.value)
- new Inliner(tree, bodyToInline(tree.symbol)).inlined(pt)
+ if (enclosingInlineds.length < ctx.settings.xmaxInlines.value) {
+ val body = bodyToInline(tree.symbol) // can typecheck the tree and thereby produce errors
+ if (ctx.reporter.hasErrors) tree else new Inliner(tree, body).inlined(pt)
+ }
else errorTree(
tree,
i"""|Maximal number of successive inlines (${ctx.settings.xmaxInlines.value}) exceeded,