Skip to content

Fix #1605: don't inline methods that have errors #1607

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 2 commits into from
Nov 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@odersky - updated with your suggestion

})
}
}
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
}