Skip to content

No implicit Show for union of singleton types in REPL #4010

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

Closed
senia-psm opened this issue Feb 18, 2018 · 1 comment
Closed

No implicit Show for union of singleton types in REPL #4010

senia-psm opened this issue Feb 18, 2018 · 1 comment

Comments

@senia-psm
Copy link
Contributor

senia-psm commented Feb 18, 2018

scala> trait TmpT { type A; type B; type AorB = A | B ; def fromA(a: A): AorB = a; def fromB(b: B): AorB = b } 
// defined trait TmpT
scala> object TmpO extends TmpT{ type A = 7; type B = 8 } 
// defined object TmpO
scala> val x: TmpO.AorB = TmpO.fromA(7) 
1 |val x: TmpO.AorB = TmpO.fromA(7)
  |^
  |no implicit argument of type dotty.Show[TmpO.AorB] was found for parameter ev of method show in class ShowValue.
  |I found:
  |
  |    dotty.Show.defaultShow[Nothing]
  |
  |But method defaultShow in trait LowPrioShow does not match type dotty.Show[TmpO.AorB].

Note that one can fix it using this line:

implicit val showAorB: dotty.Show[TmpO.AorB] = dotty.Show.defaultShow[TmpO.AorB]
@senia-psm senia-psm changed the title No implicit Show for union of singleton types No implicit Show for union of singleton types in REPL Feb 18, 2018
@Blaisorblade
Copy link
Contributor

Actually, @smarter at https://gitter.im/lampepfl/dotty?at=5a892b7035dd17022ebc5968 suggests the area:repl label, but the compile error can be reproduced outside the REPL (see below).

So there are two issues:

  1. union of singleton types are not supported currently

  2. But the repl shouldn't give confusing errors like this

For 2, I guess it should explain why it's searching for a Show instance, since that's not something the user explicitly asked for. Probably prepend the error with something like "error while trying to display result".

Non-REPL variant:

trait TmpT { type A; type B; type AorB = A | B ; def fromA(a: A): AorB = a; def fromB(b: B): AorB = b }
object TmpO extends TmpT{ type A = 7; type B = 8 }
object Tester {
  val x: TmpO.AorB = TmpO.fromA(7)
  //implicit val showAorB: dotty.Show[TmpO.AorB] = dotty.Show.defaultShow[TmpO.AorB]
  implicitly[dotty.Show[TmpO.AorB]]
}

liufengyun added a commit that referenced this issue Jul 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants