diff options
author | Paul Phillips <paulp@improving.org> | 2012-02-28 09:16:03 -0800 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2012-02-28 09:49:02 -0800 |
commit | c11ec6f532449f110c3b776b11f0b2c4398fe0f9 (patch) | |
tree | 0e5a5f13dfa53d7cdc093099b3dfe46063ae4409 | |
parent | f3711b634ccfa6ef4ab14ffc8d12d244de6917c2 (diff) | |
download | scala-c11ec6f532449f110c3b776b11f0b2c4398fe0f9.tar.gz scala-c11ec6f532449f110c3b776b11f0b2c4398fe0f9.tar.bz2 scala-c11ec6f532449f110c3b776b11f0b2c4398fe0f9.zip |
Fix for typing of objects in patterns.
An object in a pattern should have type "Foo.type" just as
objects not in patterns do. Closes SI-5406. Review by @moors.
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 7 | ||||
-rw-r--r-- | test/files/neg/t414.check | 2 | ||||
-rw-r--r-- | test/files/neg/t4879.check | 4 | ||||
-rw-r--r-- | test/files/pos/t5406.scala | 4 |
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") } +} |