Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SI-7296 Lifting the limit on case class arity #2305

Merged
merged 2 commits into from
Mar 29, 2013

Conversation

retronym
Copy link
Member

The first commit fixes a crasher with the limit still imposed, that shows up with nested fat case classes.

The second lifts the limit. For case classes with > 22 params:

  • omit generation of unapply
  • pattern matching directly binds to the case accessors (as it would do for smaller case classes already)
  • the companion doesn't inherit FunctionN.

There was some understandable fear of the piecemeal when
I tabled this idea on scala-internals [1]. But I'd like
to persist as this limit is a needless source of pain for
anyone using case classes to bind to database, XML or JSON
schemata.

Review by @paulp @szeiger (for a Slick perspective), and by the Scala Meeting tomorrow.

[1] https://groups.google.com/forum/#!topic/scala-internals/RRu5bppi16Y

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.
When venturing above the pre-ordained limit of twenty
two, `Companion extends FunctionN` and `Companion.unapply`
are sacrificed. But oh-so-many other case class features
work perfectly: equality/hashing/stringification, the apply
method, and even pattern matching (which already bypasses
unapply.)

There was some understandable fear of the piecemeal when
I tabled this idea on scala-internals [1]. But I'd like
to persist as this limit is a needless source of pain for
anyone using case classes to bind to database, XML or JSON
schemata.

[1] https://groups.google.com/forum/#!topic/scala-internals/RRu5bppi16Y
@szeiger
Copy link
Member

szeiger commented Mar 25, 2013

LGTM. This should have no impact on Slick at the moment but could be used to map case classes with higher arities once we can generate unboxed access paths that avoid the intermediate tuples.

Attempts to use large case classes when going through tupled APIs may lead to surprising error messages. I have opened SI-7299 for that.

@retronym
Copy link
Member Author

Good catch, I've sharpened up the error message in #2306.

@ghost ghost assigned paulp Mar 25, 2013
@paulp
Copy link
Contributor

paulp commented Mar 25, 2013

Is there any opportunity to warn about the differences from 22-and-under case classes without being annoyingly noisy? The enumerated distinctions seem like things which would turn up as "it doesn't compile anymore", not as hidden traps, so I'm not too fretty about it; but when there is a switch flipped at an utterly arbitrary number it feels like something somewhere ought to openly recognize the event, at the least if the user gives any sign of being interested in hearing about more things (e.g. -Xlint.)

@retronym
Copy link
Member Author

We could mandate the import of scala.language.largeCaseClasses. But I'm not really a fan of that, as you lose so little when you cross the line.

@adriaanm
Copy link
Contributor

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants