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
nested type inference not so good #7714
Comments
Imported From: https://issues.scala-lang.org/browse/SI-7714?orig=1 |
@retronym said (edited on Aug 5, 2013 1:28:21 PM UTC):
So this infers class A {
// Inferred type is Some[String]
def f1(x: Any) = (x: Option[String]) match { case y @ Some(Some(_: String)) => y }
} I'll reclassify this as "improvement" for now but I don't really see how we could change this. |
@paulp said:
|
@paulp said: object Test {
case class Cell[A](var x: A)
def f1(x: Any) = x match { case y @ Cell(_) => y } // Inferred type is Cell[Any] -- unsound
def f2[A](x: Cell[A]) = x match { case Cell(y @ Cell(_)) => y } // Inferred type is Cell[Any] -- unsound
def f3(x: Cell[_]) = x match { case y @ Cell(_) => y } // Inferred type is Cell[_]
def f4[A](x: Cell[A]) = x match { case y @ Cell(_) => y } // Inferred type is Cell[A]
} As is so often true in our codebase, this has all been done before: see propagateKnownTypes in Checkable.scala. 80% of the code related to inferring the types of patterns is duplicative with 80% of the code related to assessing the checkability of types of patterns. |
@paulp said: object Test {
// Infers (Some[Any], Int)
def f(p: Any) = p match { case x @ Some(y @ 5) => ((x, y)) }
} |
Scala 3.3.1 and 3.4.0-RC1-bin-20231101-e2b38f9-NIGHTLY also infer |
vs
|
Some[Any]?
The text was updated successfully, but these errors were encountered: