Skip to content

Commit 5cef7a9

Browse files
authored
Merge pull request #1607 from felixmulder/topic/fix-inline-untyped
Fix #1605: don't inline methods that have errors
2 parents d1e0d3b + 1fec582 commit 5cef7a9

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

src/dotty/tools/dotc/reporting/Reporter.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,22 @@ trait Reporting { this: Context =>
167167
throw ex
168168
}
169169
}
170+
171+
/** Implements a fold that applies the function `f` to the result of `op` if
172+
* there are no new errors in the reporter
173+
*
174+
* @param op operation checked for errors
175+
* @param f function applied to result of op
176+
* @return either the result of `op` if it had errors or the result of `f`
177+
* applied to it
178+
*/
179+
def withNoError[A, B >: A](op: => A)(f: A => B): B = {
180+
val before = reporter.errorCount
181+
val op0 = op
182+
183+
if (reporter.errorCount > before) op0
184+
else f(op0)
185+
}
170186
}
171187

172188
/**

src/dotty/tools/dotc/typer/Inliner.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ object Inliner {
146146
addAccessor(tree, methPart, targs, argss,
147147
accessedType = methPart.tpe.widen,
148148
rhs = (qual, tps, argss) => qual.appliedToTypes(tps).appliedToArgss(argss))
149-
} else {
149+
} else {
150150
// TODO: Handle references to non-public types.
151151
// This is quite tricky, as such types can appear anywhere, including as parts
152152
// of types of other things. For the moment we do nothing and complain
@@ -190,8 +190,7 @@ object Inliner {
190190
val inlineCtx = ctx
191191
sym.updateAnnotation(LazyBodyAnnotation { _ =>
192192
implicit val ctx: Context = inlineCtx
193-
val tree1 = treeExpr(ctx)
194-
makeInlineable(tree1)
193+
ctx.withNoError(treeExpr(ctx))(makeInlineable)
195194
})
196195
}
197196
}

tests/neg/i1605.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
object Test {
2+
def foo = inlineMe
3+
4+
inline def inlineMe = 1 + x // error
5+
}

0 commit comments

Comments
 (0)