Skip to content

Commit

Permalink
Merge pull request scala#1607 from felixmulder/topic/fix-inline-untyped
Browse files Browse the repository at this point in the history
Fix scala#1605: don't inline methods that have errors
  • Loading branch information
odersky authored Nov 7, 2016
2 parents d1e0d3b + 1fec582 commit 5cef7a9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
16 changes: 16 additions & 0 deletions src/dotty/tools/dotc/reporting/Reporter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

/**
Expand Down
5 changes: 2 additions & 3 deletions src/dotty/tools/dotc/typer/Inliner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
})
}
}
Expand Down
5 changes: 5 additions & 0 deletions tests/neg/i1605.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
object Test {
def foo = inlineMe

inline def inlineMe = 1 + x // error
}

0 comments on commit 5cef7a9

Please sign in to comment.