Skip to content

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

Closed
@aka-bash0r

Description

@aka-bash0r

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)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions