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

Start offset for diagnostics should point to start of position #787

Closed
olafurpg opened this issue Jan 9, 2019 · 2 comments
Closed

Start offset for diagnostics should point to start of position #787

olafurpg opened this issue Jan 9, 2019 · 2 comments
Labels
bug A defect or misbehaviour. task / compile

Comments

@olafurpg
Copy link
Contributor

olafurpg commented Jan 9, 2019

object A {
  "".lengthCompare("1".substring(0))
}

In BSP, Bloop reports the following range position for the diagnostic

a/src/main/scala/A.scala:2:33: error: type mismatch;
 found   : String
 required: Int
  "".lengthCompare("1".substring(0))
                                ^^^

I expected the range position to be the following

a/src/main/scala/A.scala:2:33: error: type mismatch;
 found   : String
 required: Int
  "".lengthCompare("1".substring(0))
                   ^^^^^^^^^^^^^^^^

It looks like the start offset is using the Position.point offset from the compiler instead of Position.start. Here is how the error looks from scalac in the terminal with -Yrangepos enabled

err.scala:2: error: type mismatch;
 found   : String
 required: Int
      def a = "".lengthCompare("1".substring(1))
                                            ^
one error found

In mdoc, we use Position.{start,end} from the compiler diagnostics and the errors are published as expected.

info: Compiling 1 file to /Users/olafurpg/dev/metals/target/out
error: /Users/olafurpg/dev/metals/target/docs/in.md:2:28: type mismatch;
 found   : String
 required: Int
  def a = "".lengthCompare("1".substring(1))
                           ^^^^^^^^^^^^^^^^
info: Compiled in 1.28s (1 error)
@jvican jvican added bug A defect or misbehaviour. task / compile labels Jan 9, 2019
@olafurpg
Copy link
Contributor Author

olafurpg commented Jan 9, 2019

Here is how the error looks in vscode with Metals

screenshot 2019-01-09 at 19 50 58

@olafurpg
Copy link
Contributor Author

Another test case: val x: Int = "a" + "b" produces the following position currently

screenshot 2019-01-10 at 14 09 49

I expect the position to start at "a"

error: /Users/olafurpg/dev/metals/target/docs/in.md:2:16: type mismatch;
 found   : String("ab")
 required: Int
  val x: Int = "a" + "b"
               ^^^^^^^^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A defect or misbehaviour. task / compile
Projects
None yet
Development

No branches or pull requests

2 participants