metals
metals copied to clipboard
Scala 3 incorrect return type suggestion for opaque type extensions
Describe the bug
Not sure if it's a Metals or Scala 3 bug, but even though the precise type of the extension method is known, it returns generic type parameter name.
Or may be this doesn't work on a fundamental level?
Code:
//> using scala "3.2.0"
object types:
trait Opaque[H, T](using H =:= T):
def apply(s: T): H = s.asInstanceOf[H]
extension (h: H) def value: T = h.asInstanceOf[T]
opaque type Hello = String
object Hello extends Opaque[Hello, String]
@main def hello =
import types.{*, given}
val x = Hello("yes")
x.value
Expected behavior
I was hoping to see value: String
Operating system
macOS
Editor/Extension
Nvim (nvim-metals)
Version of Metals
0.11.8+55-e48b5ad4-SNAPSHOT
Extra context or search terms
scala 3, suggestion, opaque, extension, return type
Thanks for reporting! Looks like the issue related to https://github.com/lampepfl/dotty/issues/15730 and https://github.com/scalameta/metals/issues/4184
This is already fixed in dotty presentation compiler which will be default from next LTS version and Scala Next. I'll add tests for this.