Skip to content

Add context to safe-init warnings for inlined methods #14646

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 1 commit into from
Mar 9, 2022
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
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/init/Semantic.scala
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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