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

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

Closed
panacekcz opened this issue Apr 11, 2019 · 1 comment
Closed

Comments

@panacekcz
Copy link
Contributor

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
  }
}
@odersky
Copy link
Contributor

odersky commented Apr 13, 2019

This has to do with the fact that we don't allow yet singleton types in unions. Let's try to change that.

@odersky odersky closed this as completed in 63d8546 May 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants