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

type variable escapes into the wild #7944

Closed
scabug opened this issue Oct 30, 2013 · 4 comments
Closed

type variable escapes into the wild #7944

scabug opened this issue Oct 30, 2013 · 4 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Oct 30, 2013

It is possible to convince a type variable to appear as an actual type. I'm not sure how else to describe it:

scala> :pa
// Entering paste mode (ctrl-D to finish)
 
sealed abstract class \/[+A, +B]
final case class -\/[+A](a: A) extends (A \/ Nothing)
final case class \/-[+B](b: B) extends (Nothing \/ B)
 
object \/ {
 
  def left[A, B]:  A => A \/ B = -\/(_)
  def right[A, B]: B => A \/ B = \/-(_)
 
  def fromEither[A, B](e: Either[A, B]): A \/ B =
    e fold (left, right)
 
}
 
implicit class EitherOps[A, B](self: Either[A, B]) {
  final def disjunction: A \/ B = \/ fromEither self
}
 
 
// Exiting paste mode, now interpreting.
 
defined class $bslash$div
defined class $minus$bslash$div
defined class $bslash$div$minus
defined module $bslash$div
defined class EitherOps
 
scala> Left(1).disjunction
res0: \/[Int,B] = -\/(1) // what the hell is B?
 
scala> Right(1).disjunction
res1: \/[A,Int] = \/-(1)
 
scala> Right(1).disjunction : Nothing \/ Int
<console>:15: error: type mismatch;
 found   : \/[A,Int]
 required: \/[Nothing,Int]
              Right(1).disjunction : Nothing \/ Int
@scabug
Copy link
Author

scabug commented Oct 30, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7944?orig=1
Reporter: Rob Norris (rnorris)
Affected Versions: 2.10.2

@scabug
Copy link
Author

scabug commented Oct 30, 2013

@retronym said:
Thanks for the small bug report. The bug seems specific to inferred type arguments of implicit views. It is also present in Scala 2.11.0-M6. I'll take a look at what's going on.

scala> Left(1)
res8: scala.util.Left[Int,Nothing] = Left(1)

scala> EitherOps(res8)
res9: EitherOps[Int,Nothing] = EitherOps@c60090d

scala> EitherOps(res8).disjunction
res10: \/[Int,Nothing] = -\/(1)

scala> res8.disjunction
res11: \/[Int,B] = -\/(1)

@scabug
Copy link
Author

scabug commented Oct 30, 2013

Rob Norris (rnorris) said:
I don't know if it's relevant, but the problematic expressions also do not reify. Using scalaz as a library you get

scala> reflect.runtime.universe.reify { Left(1).disjunction }
<console>:17: error: macro has not been expanded
              reflect.runtime.universe.reify { Left(1).disjunction }
                                       ^

and using the REPL example you get

scala> reflect.runtime.universe.reify { Left(1).disjunction }
<console>:15: error: this type parameter must be specified
              reflect.runtime.universe.reify { Left(1).disjunction }
                                       ^

@scabug
Copy link
Author

scabug commented Oct 30, 2013

@retronym said:
scala/scala#3088

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

2 participants