Skip to content
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

[3.0.0-RC2 / 3.0.0-RC3] cannot resolve ValueOf for type literal argument of opaque types #12178

Closed
aka-bash0r opened this issue Apr 21, 2021 · 1 comment · Fixed by #13210
Closed

Comments

@aka-bash0r
Copy link

aka-bash0r commented Apr 21, 2021

Compiler version

3.0.0-RC2 / 3.0.0-RC3

Minimized code

opaque type LabelTagged[TLabel <: Singleton & String, TValue] = TValue

object LabelTagged:
  def apply[TLabel <: Singleton & String, TValue]
  (
    label: TLabel,
    value: TValue,
  )
  : LabelTagged[TLabel, TValue] = value

extension[TLabel <: Singleton & String, TValue] (labelTagged: LabelTagged[TLabel, TValue])
  def value
  : TValue = labelTagged

  def label
  (using label: ValueOf[TLabel])
  : TLabel
  = label.value

@main def hello(): Unit = {
  val foo: LabelTagged["foo", Int] = LabelTagged("foo", 10)
  println(foo.label)
}

Output

value label is not a member of Main$package.LabelTagged[("foo" : String), Int].
An extension method was tried, but could not be fully constructed:

    label[(Singleton & String), TValue](foo)(
      /* missing */summon[ValueOf[Singleton & String]]
    )    failed with

        No singleton value available for (Singleton & String).
  println(foo.label)

Expectation

Type inference does not generalize type literal arguments to Singleton & String while searching for an instance of ValueOf.

Works with case classes:

case class LabelTagged[TLabel <: Singleton & String, TValue](value: TValue):
  def label
  (using label: ValueOf[TLabel])
  : TLabel
  = label.value

@main def hello(): Unit = {
  val foo: LabelTagged["foo", Int] = LabelTagged(10)
  println(foo.label)
}
@odersky
Copy link
Contributor

odersky commented Apr 22, 2021

I noted that it works if I use a normal method, not an extension method:

@main def hello(): Unit = {
  val foo: LabelTagged["foo", Int] = LabelTagged("foo", 10)
  println(label(foo))  // works
}

griggt added a commit to griggt/dotty that referenced this issue Jul 29, 2021
OlivierBlanvillain added a commit that referenced this issue Jul 30, 2021
tanishiking pushed a commit to tanishiking/scala3 that referenced this issue Aug 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants