-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Incorrect position of error reported from macro in inline methods chain #13991
Comments
After looking a bit more at inline errors, I noticed that it's a broader topic than just a reported case in this issue. Even if the described case would have a more accurate position, it might be hard to understand the source of the error as it might depend on a parameter. For example - a chain of inline defs with a inline def second[A]: Int =
summonInline[Foo[A]].foo
inline def first[A]: Int
second[A] + 42
def foo = // It's hard to say what is wrong by this error even having a correct position
first[String] // [error] no implicit argument of type Foo[A] was found I've also noticed that From Metals viewpoint, if there were stacktraces from inlineContext we could show them to the user at the place of error + provide additional navigation. So, I'm wondering if it's possible to extend Could anyone dive into this thing? I don't know who should I ping to start a discussion. |
This example trait Foo[X]:
def foo: Int
inline def second[A]: Int = compiletime.summonInline[Foo[A]].foo
inline def first[A]: Int = second[A] + 42
def foo = first[String] fails with
which seems to be correct. The |
For the first case // Main.scala
object Main:
def main(args: Array[String]): Unit =
inline def v2 =
InlineMac.sample(
"foo" // <- the actual error position was here
)
inline def v1 = v2
v2 // [error] Error <- reported error position is here the error is
which points to the macro expansion site. This is the place where the error happened. It also points out the was reported on the |
What we can improve is how the inline stack is reported. We could show the code and not only the line number. |
By some reason this part isn't rendered for bsp-clients(bloop/sbt-bsp) so Metals doesn't show it. The problem from the editor and user viewpoint that inline error are different from a usual one. trait Foo[X]:
def foo: Int
// you can look at the `first` signature and check what is required to call it
object non-inlined:
def second[A](using f: Foo[A]): Int = f.foo
def first[A: Foo]: Int = second[A] + 42
def foo = first[String] // [error]
// looking at `first` signature/implementation won't be helpful
// there is also no errors on `second[A]` / `summonInline[A]`
// for methods larger than in this sample it might be hard to say what you need to fix
object inlined:
inline def second[A]: Int = compiletime.summonInline[Foo[A]].foo
inline def first[A]: Int = second[A] + 42
def foo = first[String] // [error] The solution with a better error message with code might improve the situation. I don't know what might be the final solution but at least having an extended information with a full trace would allow us to experiment with this thing. |
@dos65 @nicolasstucki Is #14002 supposed to be the solution to this issue? Or is there something else needed? |
From the dotty perspective #14002 is the solution. But metals also needs to do a similar improvement. |
With #14002 will it be possible to get all the locations or would Metals need to parse the messages for it? |
@tgodzik The plan was to extend the diagnostic structure to carry this additional info for inline error, but I haven't had time to prototype this thing yet. |
Thanks for all your work @nicolasstucki, @dos65 and @tgodzik! Being able to display error underlines on specific terms is super exciting for me! |
This issue is based on scalameta/metals#3214
The position of error that was produced in inline context is unwrapped to the outermost one.
In case if it's a chain of inline calls, it's unclear where the actual error happens.
Example:
There is a difference between in error message between direct compiler usage and using bsp-client.
The default compiler reportee additionally adds lines like:
This location contains code that was inlined from Main.scala:27
but I don't think that it helps a lot in this case.The text was updated successfully, but these errors were encountered: