summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala7
-rw-r--r--test/files/neg/t414.check2
-rw-r--r--test/files/neg/t4879.check4
-rw-r--r--test/files/pos/t5406.scala4
4 files changed, 13 insertions, 4 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index ea8112f1a4..0a1a385846 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -614,7 +614,12 @@ trait Typers extends Modes with Adaptations with PatMatVirtualiser {
if (tree.isErrorTyped) tree
else if ((mode & (PATTERNmode | FUNmode)) == PATTERNmode && tree.isTerm) { // (1)
- if (sym.isValue) checkStable(tree)
+ if (sym.isValue) {
+ val tree1 = checkStable(tree)
+ // A module reference in a pattern has type Foo.type, not "object Foo"
+ if (sym.isModule && !sym.isMethod) tree1 setType singleType(pre, sym)
+ else tree1
+ }
else fail()
} else if ((mode & (EXPRmode | QUALmode)) == EXPRmode && !sym.isValue && !phase.erasedTypes) { // (2)
fail()
diff --git a/test/files/neg/t414.check b/test/files/neg/t414.check
index a855497648..d0d24baa33 100644
--- a/test/files/neg/t414.check
+++ b/test/files/neg/t414.check
@@ -1,5 +1,5 @@
t414.scala:5: error: pattern type is incompatible with expected type;
- found : object Empty
+ found : Empty.type (with underlying type object Empty)
required: IntMap[a]
Note: if you intended to match against the class, try `case _: Empty[_]` or `case Empty()`
case Empty =>
diff --git a/test/files/neg/t4879.check b/test/files/neg/t4879.check
index 49f3c73cf7..94758c751c 100644
--- a/test/files/neg/t4879.check
+++ b/test/files/neg/t4879.check
@@ -1,11 +1,11 @@
t4879.scala:6: error: pattern type is incompatible with expected type;
- found : object C
+ found : C.type (with underlying type object C)
required: C
Note: if you intended to match against the class, try `case _: C` or `case C(_)`
case C => true
^
t4879.scala:10: error: pattern type is incompatible with expected type;
- found : object D
+ found : D.type (with underlying type object D)
required: D[T,U,V]
Note: if you intended to match against the class, try `case _: D[_,_,_]` or `case D(_,_,_)`
case D => true
diff --git a/test/files/pos/t5406.scala b/test/files/pos/t5406.scala
new file mode 100644
index 0000000000..c2e42c0ac3
--- /dev/null
+++ b/test/files/pos/t5406.scala
@@ -0,0 +1,4 @@
+object Wuffles { }
+object Test {
+ def f = (Some(Wuffles): Option[Wuffles.type]) match { case Some(Wuffles) => println("Woof"); case _ => println("Meow") }
+}