diff options
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 4 | ||||
-rw-r--r-- | test/files/run/patmatnew.scala | 44 |
2 files changed, 46 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index e8a52e9b2f..0ba003908c 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -1687,11 +1687,11 @@ trait Typers { self: Analyzer => if (!isFullyDefined(pt)) assert(false, tree+" ==> "+UnApply(fun1, args1)+", pt = "+pt) // <pending-change> // this would be a better choice (from #1196), but fails due to (broken?) refinements - // val itype = refinedType(List(pt, arg.tpe), context.owner) + val itype = refinedType(List(pt, arg.tpe), context.owner) // </pending-change> // restore old type (arg is a dummy tree, just needs to pass typechecking) arg.tpe = oldArgType - UnApply(fun1, args1) setPos tree.pos setType pt // itype //pt + UnApply(fun1, args1) setPos tree.pos setType itype //pt } else { errorTree(tree, "wrong number of arguments for "+treeSymTypeMsg(fun)) } diff --git a/test/files/run/patmatnew.scala b/test/files/run/patmatnew.scala index a54bac814f..1d4bf37e1a 100644 --- a/test/files/run/patmatnew.scala +++ b/test/files/run/patmatnew.scala @@ -289,5 +289,49 @@ object Test extends TestConsoleMain { case FooBar => true } + object Bug1270 { // unapply13 + + class Sync { + def apply(x: Int): Int = 42 + def unapply(scrut: Any): Option[Int] = None + } + + class Buffer { + object Get extends Sync + + var ps: PartialFunction[Any, Any] = { + case Get(y) if y > 4 => // y gets a wildcard type for some reason?! hack + } + } + + println((new Buffer).ps.isDefinedAt(42)) + } + + object Bug1261 { + sealed trait Elem + case class Foo extends Elem + case class Bar extends Elem + trait Row extends Elem + object Row { + def unapply(r: Row) = true + + def f(elem: Elem) { + elem match { + case Bar() => ; + case Row() => ; + case Foo() => ; // used to give ERROR (unreachable code) + }}} + } + + object Feature1196 { + def f(l: List[Int]) { } + + val l: Seq[Int] = List(1, 2, 3) + + l match { + case x @ List(1, _) => f(x) // x needs to get better type List[int] here + } + } + } |