-
Notifications
You must be signed in to change notification settings - Fork 3.1k
SI-10097 Error if no non-implicit case class param #5585
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
Conversation
Destructuring in reflection also makes assumption about empty first param list that must be tweaked for case class. |
The spec doesn't mention any restrictions on case class parameter lists. I think they should be added. (This also goes for the existing restriction on requiring a parameter list at all) |
9b2492b
to
8549945
Compare
syntaxError(warnAt, "multiple implicit parameter sections are not allowed") | ||
else { | ||
// guard against anomalous class C(private implicit val x: Int)(implicit s: String) | ||
val ttl = vds.count(_ match { case ValDef(mods, _, _, _) :: _ => mods.isImplicit ; case _ => false }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
git push to clean this syntax is hanging for some reason. Try again later.
21d8b40
to
1656251
Compare
Looks very good. I think the last commit should be an error, and not only a warning under a flag. Can we change the parser to make a parameter list implicit also if the
Finally, I think we should be careful to introduce this (require |
I think the bug is typer taking a param section as implicit if the first param is implicit. That's why (as an afterthought) I put the noise about "effectively multiple" under a flag; I also considered -Xlint. This is really an implementation restriction and not in the spec. paulp said on gitter that implicit mod on a param is a non-feature. But people like But maybe that is syntax in the service of a non-feature. For 2.12 migration of missing non-implicit case class params, it can silently add the empty param section, but error under One of the tests used a space to indicate a missing param list. Since the syntax showed up in a couple of tests, probably it exists in the wild (and not just in |
3fa6051
to
804cc59
Compare
OK, I should have checked the spec earlier. I didn't realize that You say in one of the commit messages:
That sounds like a bug, shouldn't we fix this instead? Instead of In the REPL i get two warnings:
Also the warning text
|
804cc59
to
9589230
Compare
Case class must have a non-implicit param list. Error early, error often. Also update spec to say that class implicitly gets a non-implicit parameter section if it doesn't have one, and that a case class must have one.
Instead of aborting when a class def has extra parameter section, take all parameter sections and sanity check the use of leading implicit to indicate an implicit parameter section.
Current semantics are that leading implicit param turns the parameter section into an implicit section (though without making other params implicitly implicit). Warn if more than one head of a param section is implicit, since that results in multiple implicit param sections.
9589230
to
1c75588
Compare
The perils of relying on slave labor:
|
/rebuild |
For 2.12 migration, insert missing case class param section, strip caseaccessor from implicit paramsection, and deprecate the adaptation.
1c75588
to
b775f4f
Compare
IntelliJ seems to implement automatic insertion of the empty param lists (consistently with non-case classes), and gets the If we go ahead with this change, /cc @Alefas to add the deprecation to IntelliJ 2.12 and the error to IntelliJ 2.13. |
However, I'm not sure that we should treat case and non-case classes differently like this. We could just insert the empty parameter list, like we do for regular classes, and make sure that the other case class machinery is aware of this. Maybe we can argue in favor of the the inconsistency because of fact that we're just fixing an existing restriction:
Rather than adding a new one. With that in mind: LGTM |
IIUC, you mean the transitional behavior of assuming empty parens for If I'll push whichever warning the Scala team prefers. I guess that's why the Scala team always has an odd number of members, so Martin needn't break any ties. (Including personal ties.) |
In the end I'm happy to impose the new restriction, I was thinking out loud. |
@retronym I created new ticket for us: https://youtrack.jetbrains.com/issue/SCL-11169 |
There's an issue for "where implicit appears in front of first class param" (which lrytz suggests fixing above): https://issues.scala-lang.org/browse/SI-9494 There's also SIP for multi-implicits: |
I agree that SI-10097 needs fixing, but I'm unclear why this is the correct fix. Why isn't an implicit parameter list considered to be the parameter list required for a case class? |
you really want to do that? (or think someone else would?) |
One justification is so that a "constructor pattern" looks like a constructor invocation. The abstract case class trick lets you control apply but not unapply. Maybe an ergonomic solution to that would satisfy the implicit case elements use case. A second justification might be that capturing implicits as vals is unexpected? |
Another case class anomaly is |
On reflection, an implicit first (and only) parameter list for a case class isn't particularly useful because the bare name will always be interpreted as a reference to the companion object. So, fine by me. |
we also have a number of odd members. |
fixes scala/scala-dev#303 ; the regression was in scala#5585
fixes scala/scala-dev#303 ; the regression was in scala#5585
fixes scala/scala-dev#303 ; the regression was in scala#5585
Case class must have a non-implicit param list.
Error early, error often.
JIRA: https://issues.scala-lang.org/browse/SI-10097