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

Remove by-name restriction for case copy #10770

Open
wants to merge 1 commit into
base: 2.13.x
Choose a base branch
from

Conversation

som-snytt
Copy link
Contributor

@som-snytt som-snytt commented May 2, 2024

-Xsource-features:case-copy-by-name synthesizes case copy method when a parameter is by-name.

Fixes scala/bug#7879

@scala-jenkins scala-jenkins added this to the 2.13.15 milestone May 2, 2024
@som-snytt som-snytt force-pushed the issue/7879-case-copy-by-name branch from 6b329bf to 7b8b267 Compare May 3, 2024 15:09
@lrytz
Copy link
Member

lrytz commented May 6, 2024

putting behind -Xsource-features

I think we have to as it's changing the binary output.

@som-snytt som-snytt force-pushed the issue/7879-case-copy-by-name branch from 7b8b267 to 914c657 Compare May 8, 2024 18:53
@som-snytt som-snytt marked this pull request as ready for review May 8, 2024 18:59
val classParamss = constrParamss(cdef)
def warn() = runReporting.warning(cdef.namePos, "case `copy` method is allowed to have by-name parameters under Scala 3 (or with -Xsource-features:case-copy-by-name)", Scala3Migration, cdef.symbol)
def isDisallowed(vd: ValDef) = isRepeatedParamType(vd.tpt) || isByNameParamType(vd.tpt).tap(if (_) warn())
def copyOK = currentRun.sourceFeatures.caseCopyByName || !mexists(classParamss)(isDisallowed)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now it tries to generate copy for repeated params:

➜ sandbox scpr 10770 T.scala -Vprint:cleanup -Xsource:3-cross
> scala compile --server=false -S 2.13.15-bin-914c657-SNAPSHOT -d . -release 8 --repository https://scala-ci.typesafe.com/artifactory/scala-pr-validation-snapshots T.scala -Vprint:cleanup -Xsource:3-cross
/Users/luc/code/scala/scala13/sandbox/T.scala:1: error: type mismatch;
 found   : Seq[Int]
 required: Int
case class C(x: Int)(y: Int*)
                     ^
1 error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, oops, I'll rename it to sourceFeatures.anythingGoes.

@som-snytt som-snytt force-pushed the issue/7879-case-copy-by-name branch from 914c657 to 4e5ceaa Compare May 13, 2024 12:17
@som-snytt som-snytt force-pushed the issue/7879-case-copy-by-name branch from 4e5ceaa to 9e19996 Compare May 13, 2024 12:21
@som-snytt
Copy link
Contributor Author

Refactored copyOK to use braces and isAllowed instead of isDisallowed. Added a neg test for varargs. (There is no existing test.)

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