Skip to content

Opaque type leakage in Conversion typeclass definition #14070

Closed
@nbenns

Description

@nbenns

Compiler version

3.1.0

Minimized code

FirstName.scala

opaque type FirstName = String

object FirstName {
  def apply(s: String): FirstName = s
}

FullName.scala

opaque type FullName = String
object FullName {
  def apply(s: String): FullName = s
  
  given Conversion[FullName, FirstName] with {
    def apply(fullName: FullName): FirstName = fullName.split(" ")(0)
  }
}

Main.scala

object Main extends App {
  def printFirstName(f: FirstName): Unit = {
    println(f)
  }

  val fn = FullName("Johnny Test")

  printFirstName(fn)
}

Output

Inifinite Loop / Hang

Expectation

Should not compile as the Conversion given should not know that String =:= FirstName

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