Created
May 8, 2017 21:31
-
-
Save non/f575b2bb8986420440aac2f5c66047ce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// this code demonstrates unsoundness in scala (tested in 2.11 and 2.12) | |
// | |
// it seems like scala is checking that the return type is a Pipe[_] | |
// but not a Pipe[E]; maybe due to erasure? | |
sealed abstract class Pipe[E] | |
case class Single[E](elem: E) extends Pipe[E] | |
case class Double[A, B](a: Pipe[A], b: Pipe[B]) extends Pipe[(A, B)] | |
object Pipe { | |
def prepare[E](p: Pipe[E]): Pipe[E] = | |
p match { | |
case Single(_) => | |
p | |
case Double(a, b) => | |
// any Double works -- it's type doesn't have to match E. | |
Double(Single(1), Single(1)) | |
} | |
prepare[(String, String)](Double(Single("foo"), Single("bar"))) | |
} |
Dotty error reports really looks awesome :)
Wow, yeah, those Dotty errors look really great @olafurpg!
We ran into a similar problem with record pulled from Datomic (or was it DynamoDB? Not sure). Fields that were supposed to be List[A]
were indeed lists, but didn't contains A
s. I like your example, though: it's minimal in the sense that it gets right to the root of the issue.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
FWIW, here's what dotty reports (with glorious syntax highlighted error messages)