scalameta / metals

Scala language server with rich IDE features 🚀
https://scalameta.org/metals/
Apache License 2.0
2.09k stars 330 forks source link

Cannot decompile the companion object of an opaque type in Scala 3 #3741

Open Atry opened 2 years ago

Atry commented 2 years ago

Describe the bug

Reproduction steps:

  1. Check out https://github.com/Atry/metals-decompile
  2. Open the project in VS Code with Metals
  3. Import the project with bloop compiler server
  4. Open src/main/scala/mypackage/MyOpaqueType.scala in the editor
  5. From the Command Palette, run "Metals: Show decompiled with javap verbose"

Then the error message is shown in a new tab

File file:///private/tmp/metals-decompile/.bloop/metals-decompile/bloop-bsp-clients-classes/classes-Metals-TMvkzg3KQmK96kYMLWlZKQ==/mypackage/MyOpaqueType$.class doesn't exist

Expected behavior

Show decompiled in a new tab

Operating system

macOS

Editor/Extension

VS Code

Version of Metals

0.11.2

Extra context or search terms

Note that there is a class file compiled from the companion object at mypackage/MyOpaqueType$package$MyOpaqueType$.class, not mypackage/MyOpaqueType$.class.

tgodzik commented 2 years ago

Thanks for reporting! It looks like with opaque type the object classfile is different than when the object is a companion to a non opaque topelevel type.

mypackage/MyOpaqueType$package$MyOpaqueType$.class instead of mypackage/MyOpaqueType$.class

If we put the type into another class/object then the resulting classfiles are as we would expect them. We could special case this scenario or see if it actually needs to be fixed in the compiler