Skip to content

Commit

Permalink
SI-7296 Avoid crash with nested 23-param case class
Browse files Browse the repository at this point in the history
The implementation restriction doesn't stop subsequent
typechecking in the same compilation unit from triggering
type completion which tries to synthesize the unapply
method.

This commit predicates generation of the unapply method
on having 22 or fewer parameters.
  • Loading branch information
retronym committed Mar 25, 2013
1 parent 1187c98 commit ad79d74
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/compiler/scala/tools/nsc/typechecker/Namers.scala
Expand Up @@ -1373,7 +1373,9 @@ trait Namers extends MethodSynthesis {
if (!cdef.symbol.hasAbstractFlag)
namer.enterSyntheticSym(caseModuleApplyMeth(cdef))

namer.enterSyntheticSym(caseModuleUnapplyMeth(cdef))
val primaryConstructorArity = treeInfo.firstConstructorArgs(cdef.impl.body).size
if (primaryConstructorArity <= MaxTupleArity)
namer.enterSyntheticSym(caseModuleUnapplyMeth(cdef))
}

def addCopyMethod(cdef: ClassDef, namer: Namer) {
Expand Down
4 changes: 4 additions & 0 deletions test/files/neg/t7296.check
@@ -0,0 +1,4 @@
t7296.scala:5: error: Implementation restriction: case classes cannot have more than 22 parameters.
case class Foo(a: A, b: A, c: A, d: A, e: A, f: A, g: A, h: A, i: A, j: A, k: A, l: A, m: A, n: A, o: A, p: A, q: A, r: A, s: A, t: A, u: A, v: A, w: A, x: A, y: A, Z: A)
^
one error found
6 changes: 6 additions & 0 deletions test/files/neg/t7296.scala
@@ -0,0 +1,6 @@
object Test {
type A = Int
// Emits the implementation restriction but then proceeds to crash
// when creating the Foo.unapply.
case class Foo(a: A, b: A, c: A, d: A, e: A, f: A, g: A, h: A, i: A, j: A, k: A, l: A, m: A, n: A, o: A, p: A, q: A, r: A, s: A, t: A, u: A, v: A, w: A, x: A, y: A, Z: A)
}

0 comments on commit ad79d74

Please sign in to comment.