Skip to content

Double vision of toplevel definition in VSCode #6208

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

Closed
abgruszecki opened this issue Apr 2, 2019 · 4 comments
Closed

Double vision of toplevel definition in VSCode #6208

abgruszecki opened this issue Apr 2, 2019 · 4 comments
Labels
area:ide stat:needs minimization Needs a self contained minimization

Comments

@abgruszecki
Copy link
Contributor

Opening VSCode on BryanAbate@da2e2fa and navigating to tastydoc/src/dotty/tastydoc/printer.scala will show a bunch of errors like the one below:

cannot merge
  method formatToMarkdown in package tastydoc of type (container: dotty.tastydoc.Container, level: Int): String  and
  method formatToMarkdown in package tastydoc of type (container: dotty.tastydoc.Container, level: Int): String
they are both defined in package tastydoc but have matching signatures
  (container: dotty.tastydoc.Container, level: Int): String and
  (container: dotty.tastydoc.Container, level: Int): String
as members of package tastydoc

However, the code compiles w/o issues in SBT.
IDE LSP communication logs show nothing out of the ordinary, neither does anything appear in SBT.

@abgruszecki abgruszecki added area:ide stat:needs minimization Needs a self contained minimization labels Apr 2, 2019
@abgruszecki
Copy link
Contributor Author

Potentially related to #6201.

@benhutchison
Copy link
Contributor

FWIW I hit the same issue on my first try of Dotty in VSCode:

package dottytest

import scala.language.implicitConversions
import cats.effect._
import implied cats.implicits._

val msg = "Im using Dotty!"
object DottyApp extends IOApp {
    def run(args: List[String]): IO[ExitCode] = IO(println(msg)) >> IO(ExitCode.Success)
}

IO in IO(println(msg)) gets annotated with strange message:

cannot merge
  value msg in package dottytest of type String  and
  value msg in package dottytest of type String
they are both defined in package dottytest but have matching signatures
  String and
  String
as members of package dottytest

I noticed #6201 is marked as Fixed by a commit that only includes test code. Was it actually fixed by an earlier change, and the test is to prevent regression?

@odersky
Copy link
Contributor

odersky commented May 9, 2019

This could be a case where msg has migrated from a different source file and the old class file is still around. Then the compiler sees two different wrapper objects that each have msg as a toplevel definition. We can try to make the error message more informative to find out more.

@kfish610
Copy link

I made a very simple program that gives these errors

trait Test
implied for Test

Which gives

cannot merge
  object Test_instance of type object Test_instance  and
  object Test_instance of type object Test_instance
as members of package <empty>    

and

cannot merge
  object Test_instance of type Test_instance  and
  object Test_instance of type file:///home/kfish/Documents/Projects/dotty-testing/src/main/scala/Test$package.
  Test_instance
they are both defined in package <empty> but have matching signatures
  Test_instance and
  file:///home/kfish/Documents/Projects/dotty-testing/src/main/scala/Test$package.
  Test_instance
as members of package <empty>

Interestingly I didn't get any errors when I just defined a top level value like msg in benhutchison's example
Hopefully this helps in narrowing it down

smarter added a commit to dotty-staging/dotty that referenced this issue Jun 5, 2019
Toplevel defs are enclosed in an object named `<source>$package` by
`Desugar#packageDef`, this didn't work correctly in the IDE because the
name of the VirtualFile was the whole URI of the file. In particular
this lead to double-vision problems ("cannot merge ...") when the
toplevel definition was also present on the classpath.
@odersky odersky closed this as completed in 91950d1 Jun 5, 2019
odersky added a commit that referenced this issue Jun 5, 2019
Fix #6208, #6605: Properly support toplevel defs in the IDE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:ide stat:needs minimization Needs a self contained minimization
Projects
None yet
Development

No branches or pull requests

4 participants