Skip to content
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

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

Merged
merged 1 commit into from Mar 9, 2022

Conversation

Xavientois
Copy link
Contributor

Closes #14467

  • Adds the calling context of the inlined method to the stack trace for safe-init warnings

For source code:

class InlineError {
  Assertion.failAssert(this)
  val v = 2;
}

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

Old warning:

[error] -- Error: /*******/dotty/compiler/src/dotty/tools/dotc/InlineError.scala:10:45
[error] 10 |    scala.runtime.Scala3RunTime.assertFailed(message)
[error]    |                                             ^^^^^^^
[error]    |Cannot prove that the value is fully initialized. Only initialized values may be used as arguments.

New warning:

[error] -- Error: /*******/dotty/compiler/src/dotty/tools/dotc/InlineError.scala:10:45
[error] 10 |    scala.runtime.Scala3RunTime.assertFailed(message)
[error]    |                                             ^^^^^^^
[error]    |Cannot prove that the value is fully initialized. Only initialized values may be used as arguments. Calling trace:
[error]    | -> Assertion.failAssert(this)	[ InlineError.scala:4 ]

Review by @liufengyun

Copy link
Contributor

@liufengyun liufengyun left a comment

Choose a reason for hiding this comment

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

Let's add a test case with a check file to prevent regression. Otherwise, LGTM 🎉

Closes scala#14467

- Adds the calling context of the inlined method to the stack trace for safe-init warnings

For source code:
```Scala
class InlineError {
  Assertion.failAssert(this)
  val v = 2;
}

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

Old warning:
```
[error] -- Error: /*******/dotty/compiler/src/dotty/tools/dotc/InlineError.scala:10:45
[error] 10 |    scala.runtime.Scala3RunTime.assertFailed(message)
[error]    |                                             ^^^^^^^
[error]    |Cannot prove that the value is fully initialized. Only initialized values may be used as arguments.
```

New warning:
```
[error] -- Error: /*******/dotty/compiler/src/dotty/tools/dotc/InlineError.scala:10:45
[error] 10 |    scala.runtime.Scala3RunTime.assertFailed(message)
[error]    |                                             ^^^^^^^
[error]    |Cannot prove that the value is fully initialized. Only initialized values may be used as arguments. Calling trace:
[error]    | -> Assertion.failAssert(this)	[ InlineError.scala:4 ]
```

Review by @liufengyun
@Xavientois Xavientois force-pushed the show-context-for-inline-safe-init branch 2 times, most recently from 25cf4ed to 18300d0 Compare March 9, 2022 14:05
@olhotak olhotak enabled auto-merge March 9, 2022 15:44
@olhotak olhotak merged commit bef67f6 into scala:main Mar 9, 2022
@Xavientois Xavientois deleted the show-context-for-inline-safe-init branch March 10, 2022 19:38
@Kordyjan Kordyjan added this to the 3.1.3 milestone Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Initialization-checker error is unhelpful for inlined functions
4 participants