Skip to content

Commit

Permalink
Remove by-name restriction for case copy
Browse files Browse the repository at this point in the history
  • Loading branch information
som-snytt committed May 2, 2024
1 parent 3fb0c39 commit 6b329bf
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/compiler/scala/tools/nsc/typechecker/Unapplies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ trait Unapplies extends ast.TreeDSL {
import global._
import definitions._
import CODE.{ CASE => _, _ }
import treeInfo.{ isRepeatedParamType, isByNameParamType }
import treeInfo.isRepeatedParamType

private def unapplyParamName = nme.x_0
private def caseMods = Modifiers(SYNTHETIC | CASE)
Expand Down Expand Up @@ -265,10 +265,9 @@ trait Unapplies extends ast.TreeDSL {
* ClassDef of the case class.
*/
def caseClassCopyMeth(cdef: ClassDef): Option[DefDef] = {
def isDisallowed(vd: ValDef) = isRepeatedParamType(vd.tpt) || isByNameParamType(vd.tpt)
val classParamss = constrParamss(cdef)

if (cdef.symbol.hasAbstractFlag || mexists(classParamss)(isDisallowed)) None
if (cdef.symbol.hasAbstractFlag || mexists(classParamss)(isRepeatedParamType)) None
else {
def makeCopyParam(vd: ValDef, putDefault: Boolean) = {
val rhs = if (putDefault) toIdent(vd) else EmptyTree
Expand Down
25 changes: 25 additions & 0 deletions test/files/run/t7879.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

scala> case class C(i: Int)(j: => Int) { def sum = i + j }
class C

scala> def z = 27.tap(println)
def z: Int

scala> val c = C(42)(z)
val c: C = C(42)

scala> c.sum
27
val res0: Int = 69

scala> def y = 28.tap(println)
def y: Int

scala> c.copy()(y)
val res1: C = C(42)

scala> c.copy()(y).sum
28
val res2: Int = 70

scala> :quit
6 changes: 6 additions & 0 deletions test/files/run/t7879.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

import scala.tools.partest.SessionTest

object Test extends SessionTest {
override def extraSettings = "-Yimports:java.lang,scala,scala.Predef,scala.util.chaining"
}

0 comments on commit 6b329bf

Please sign in to comment.