metals icon indicating copy to clipboard operation
metals copied to clipboard

Scala 3 incorrect return type suggestion for opaque type extensions

Open keynmol opened this issue 2 years ago • 1 comments

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.

Screenshot 2022-09-03 at 12 12 02

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

keynmol avatar Sep 03 '22 11:09 keynmol

Thanks for reporting! Looks like the issue related to https://github.com/lampepfl/dotty/issues/15730 and https://github.com/scalameta/metals/issues/4184

tgodzik avatar Sep 03 '22 18:09 tgodzik

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.

image

rochala avatar Feb 29 '24 13:02 rochala