Skip to content

Conversion to opaque alias of singleton type not allowed in the companion #6288

Closed
@panacekcz

Description

@panacekcz

When an opaque type is an alias of a singleton type (literal or term), then in the companion object, the conversion from the singleton type to the alias type does not work. The conversion in the other direction works.

Test code 1:

object A{
  opaque type T = 3
  object T {
    val x: T = 3
  }
}

Output

-- [E007] Type Mismatch Error: opaque-singleton.scala:4:15 ---------
4 |    val x: T = 3
  |               ^
  |               Found:    Int(3)
  |               Required: A.T.T'
  |
  |               where:    T  is a object in object A
  |                         T' is a type in object T
one error found

Test code 2:

object O{
  val x = 3
  opaque type T = x.type
  object T {
    def wrap(a: x.type): T = a   // Error
    def unwrap(a: T): x.type = a // OK
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions