summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-04-24 19:15:46 +0000
committerPaul Phillips <paulp@improving.org>2011-04-24 19:15:46 +0000
commit870679585afc3fe8dc07b40fe032919ede414489 (patch)
treecb0ba90f1f203c519d9fe739d7e3c3d22d22240f
parentadd75447f46bcfb608f32c15fb9a5eb69f45a10d (diff)
downloadscala-870679585afc3fe8dc07b40fe032919ede414489.tar.gz
scala-870679585afc3fe8dc07b40fe032919ede414489.tar.bz2
scala-870679585afc3fe8dc07b40fe032919ede414489.zip
Removed restriction on case classes having only...
Removed restriction on case classes having only two parameter lists. Closes #1333, no review.
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Namers.scala8
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala6
-rw-r--r--test/files/neg/bug1333.check4
-rw-r--r--test/files/neg/bug1333.scala1
-rw-r--r--test/files/run/bug1333.check3
-rw-r--r--test/files/run/bug1333.scala14
6 files changed, 25 insertions, 11 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala
index 29762360ea..f1f8257fff 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala
@@ -1125,13 +1125,9 @@ trait Namers { self: Analyzer =>
* @param namer is the namer of the module class (the comp. obj)
*/
def addApplyUnapply(cdef: ClassDef, namer: Namer) {
- if (!(cdef.symbol hasFlag ABSTRACT)) {
- val applyMethod = caseModuleApplyMeth(cdef)
- if (applyMethod.vparamss.size > 2)
- context.error(cdef.symbol.pos, "case classes limited by implementation: maximum of 2 constructor parameter lists.")
+ if (!cdef.symbol.hasAbstractFlag)
+ namer.enterSyntheticSym(caseModuleApplyMeth(cdef))
- namer.enterSyntheticSym(applyMethod)
- }
namer.enterSyntheticSym(caseModuleUnapplyMeth(cdef))
}
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index acf35b9854..8718d31520 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -1908,6 +1908,12 @@ trait Typers extends Modes {
error(x.pos, "_* may only come last")
val pat1: Tree = typedPattern(cdef.pat, pattpe)
+ // When case classes have more than two parameter lists, the pattern ends
+ // up typed as a method. We only pattern match on the first parameter
+ // list, so substitute the final result type of the method, i.e. the type
+ // of the case class.
+ if (pat1.tpe.paramSectionCount > 0)
+ pat1 setType pat1.tpe.finalResultType
if (forInteractive) {
for (bind @ Bind(name, _) <- cdef.pat)
diff --git a/test/files/neg/bug1333.check b/test/files/neg/bug1333.check
deleted file mode 100644
index 11ba633194..0000000000
--- a/test/files/neg/bug1333.check
+++ /dev/null
@@ -1,4 +0,0 @@
-bug1333.scala:1: error: case classes limited by implementation: maximum of 2 constructor parameter lists.
-case class A(a: Int)(b: Int)(c: Int)
- ^
-one error found
diff --git a/test/files/neg/bug1333.scala b/test/files/neg/bug1333.scala
deleted file mode 100644
index e16b38cefc..0000000000
--- a/test/files/neg/bug1333.scala
+++ /dev/null
@@ -1 +0,0 @@
-case class A(a: Int)(b: Int)(c: Int)
diff --git a/test/files/run/bug1333.check b/test/files/run/bug1333.check
new file mode 100644
index 0000000000..6303af7f1c
--- /dev/null
+++ b/test/files/run/bug1333.check
@@ -0,0 +1,3 @@
+10
+-10
+-1
diff --git a/test/files/run/bug1333.scala b/test/files/run/bug1333.scala
new file mode 100644
index 0000000000..1696629cbb
--- /dev/null
+++ b/test/files/run/bug1333.scala
@@ -0,0 +1,14 @@
+object Test {
+ case class A(x: Int)(y: Int)(z: String)
+
+ def f(x: Any) = x match {
+ case A(x) => x
+ case _ => -1
+ }
+
+ def main(args: Array[String]): Unit = {
+ println(f(A(10)(20)("abc")))
+ println(f(A(-10)(20)("abc")))
+ println(f(List(1)))
+ }
+}