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

SI-5900 Fix pattern inference regression #3523

Merged
merged 2 commits into from
Feb 13, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/compiler/scala/tools/nsc/typechecker/PatternTypers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,12 @@ trait PatternTypers {
* see test/files/../t5189*.scala
*/
private def convertToCaseConstructor(tree: Tree, caseClass: Symbol, ptIn: Type): Tree = {
def untrustworthyPt = (
// TODO SI-7886 / SI-5900 This is well intentioned but doesn't quite hit the nail on the head.
// For now, I've put it completely behind -Xstrict-inference.
val untrustworthyPt = settings.strictInference && (
ptIn =:= AnyTpe
|| ptIn =:= NothingTpe
|| settings.strictInference && ptIn.typeSymbol != caseClass
|| ptIn.typeSymbol != caseClass
)
val variantToSkolem = new VariantToSkolemMap
val caseClassType = tree.tpe.prefix memberType caseClass
Expand Down Expand Up @@ -371,4 +373,4 @@ trait PatternTypers {
}
}
}
}
}
2 changes: 1 addition & 1 deletion test/files/neg/t4818.check
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
t4818.scala:4: error: type mismatch;
found : Int(5)
required: A
required: Nothing
def f(x: Any) = x match { case Fn(f) => f(5) }
^
one error found
2 changes: 1 addition & 1 deletion test/files/neg/t5189.check
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
t5189.scala:3: error: type mismatch;
found : T => U
found : Nothing => Any
required: Any => Any
def f(x: Any): Any => Any = x match { case Foo(bar) => bar }
^
Expand Down
1 change: 1 addition & 0 deletions test/files/neg/t6680a.flags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-Xstrict-inference
12 changes: 6 additions & 6 deletions test/files/neg/t6829.check
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,32 @@ t6829.scala:49: error: not found: value nextState
val (s,a,s2) = (state,actions(agent),nextState)
^
t6829.scala:50: error: type mismatch;
found : s.type (with underlying type T1)
found : s.type (with underlying type Any)
required: _53.State where val _53: G
val r = rewards(agent).r(s,a,s2)
^
t6829.scala:50: error: type mismatch;
found : a.type (with underlying type T2)
found : a.type (with underlying type Any)
required: _53.Action where val _53: G
val r = rewards(agent).r(s,a,s2)
^
t6829.scala:50: error: type mismatch;
found : s2.type (with underlying type T3)
found : s2.type (with underlying type Any)
required: _53.State where val _53: G
val r = rewards(agent).r(s,a,s2)
^
t6829.scala:51: error: type mismatch;
found : s.type (with underlying type T1)
found : s.type (with underlying type Any)
required: _50.State
agent.learn(s,a,s2,r): G#Agent
^
t6829.scala:51: error: type mismatch;
found : a.type (with underlying type T2)
found : a.type (with underlying type Any)
required: _50.Action
agent.learn(s,a,s2,r): G#Agent
^
t6829.scala:51: error: type mismatch;
found : s2.type (with underlying type T3)
found : s2.type (with underlying type Any)
required: _50.State
agent.learn(s,a,s2,r): G#Agent
^
Expand Down
6 changes: 0 additions & 6 deletions test/files/neg/t7886.check

This file was deleted.

9 changes: 9 additions & 0 deletions test/files/pos/t5900a.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
case class Transition[S](x: S)

object C

object Test {
(??? : Any) match {
case Transition(C) =>
}
}
File renamed without changes.
23 changes: 23 additions & 0 deletions test/pending/neg/t7886b.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
trait Covariant[+A]
trait Contra[-A] { def accept(p: A): Unit }
trait Invariant[A] extends Covariant[A] with Contra[A]

trait T
case class Unravel[A](m: Contra[A], msg: A) extends T

object Test extends Covariant[Any] {
def g(m: Contra[Any]): Unit = m accept 5
def f(x: T): Unit = x match {
case Unravel(m, msg) => g(m)
case _ =>
}
def main(args: Array[String]) {
f(Unravel[String](new Contra[String] { def accept(x: String) = x.length }, ""))
}
}
// java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
// at Test$$anon$1.accept(a.scala:18)
// at Test$.g(a.scala:13)
// at Test$.f(a.scala:15)
// at Test$.main(a.scala:18)
// at Test.main(a.scala)