Skip to content

Commit

Permalink
Merge pull request #14646 from Xavientois/show-context-for-inline-saf…
Browse files Browse the repository at this point in the history
…e-init

Add context to safe-init warnings for inlined methods
  • Loading branch information
olhotak committed Mar 9, 2022
2 parents c04f566 + 18300d0 commit bef67f6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/init/Semantic.scala
Expand Up @@ -1239,8 +1239,9 @@ object Semantic {
Result(Hot, ress.flatMap(_.errors))

case Inlined(call, bindings, expansion) =>
val trace1 = trace.add(expr)
val ress = eval(bindings, thisV, klass)
eval(expansion, thisV, klass) ++ ress.flatMap(_.errors)
withTrace(trace1)(eval(expansion, thisV, klass)) ++ ress.flatMap(_.errors)

case Thicket(List()) =>
// possible in try/catch/finally, see tests/crash/i6914.scala
Expand Down
5 changes: 5 additions & 0 deletions tests/init/neg/inlined-method.check
@@ -0,0 +1,5 @@
-- Error: tests/init/neg/inlined-method.scala:8:45 ---------------------------------------------------------------------
8 | scala.runtime.Scala3RunTime.assertFailed(message) // error
| ^^^^^^^
|Cannot prove that the value is fully initialized. Only initialized values may be used as arguments. Calling trace:
| -> Assertion.failAssert(this) [ inlined-method.scala:2 ]
8 changes: 8 additions & 0 deletions tests/init/neg/inlined-method.scala
@@ -0,0 +1,8 @@
class InlineError {
Assertion.failAssert(this)
val v = 2;
}

object Assertion:
transparent inline def failAssert(inline message: => Any): Unit =
scala.runtime.Scala3RunTime.assertFailed(message) // error

0 comments on commit bef67f6

Please sign in to comment.