metals icon indicating copy to clipboard operation
metals copied to clipboard

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

Open Atry opened this issue 3 years ago • 1 comments

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.

Atry avatar Mar 21 '22 05:03 Atry

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

tgodzik avatar Mar 21 '22 14:03 tgodzik