@@ -338,9 +338,9 @@ object desugar {
338338 def quotedPattern (tree : untpd.Tree , expectedTpt : untpd.Tree )(using Context ): untpd.Tree = {
339339 def adaptToExpectedTpt (tree : untpd.Tree ): untpd.Tree = tree match {
340340 // Add the expected type as an ascription
341- case _ : untpd.Splice =>
341+ case _ : untpd.SplicePattern =>
342342 untpd.Typed (tree, expectedTpt).withSpan(tree.span)
343- case Typed (expr : untpd.Splice , tpt) =>
343+ case Typed (expr : untpd.SplicePattern , tpt) =>
344344 cpy.Typed (tree)(expr, untpd.makeAndType(tpt, expectedTpt).withSpan(tpt.span))
345345
346346 // Propagate down the expected type to the leafs of the expression
@@ -637,7 +637,10 @@ object desugar {
637637 // new C[...](p1, ..., pN)(moreParams)
638638 val (caseClassMeths, enumScaffolding) = {
639639 def syntheticProperty (name : TermName , tpt : Tree , rhs : Tree ) =
640- DefDef (name, Nil , tpt, rhs).withMods(synthetic)
640+ val mods =
641+ if ctx.settings.Yscala2Stdlib .value then synthetic | Inline
642+ else synthetic
643+ DefDef (name, Nil , tpt, rhs).withMods(mods)
641644
642645 def productElemMeths =
643646 val caseParams = derivedVparamss.head.toArray
@@ -735,13 +738,25 @@ object desugar {
735738 .withMods(appMods) :: Nil
736739 }
737740 val unapplyMeth = {
741+ def scala2LibCompatUnapplyRhs (unapplyParamName : Name ) =
742+ assert(arity <= Definitions .MaxTupleArity , " Unexpected case class with tuple larger than 22: " + cdef.show)
743+ if arity == 1 then Apply (scalaDot(nme.Option ), Select (Ident (unapplyParamName), nme._1))
744+ else
745+ val tupleApply = Select (Ident (nme.scala), s " Tuple $arity" .toTermName)
746+ val members = List .tabulate(arity) { n => Select (Ident (unapplyParamName), s " _ ${n+ 1 }" .toTermName) }
747+ Apply (scalaDot(nme.Option ), Apply (tupleApply, members))
748+
738749 val hasRepeatedParam = constrVparamss.head.exists {
739750 case ValDef (_, tpt, _) => isRepeated(tpt)
740751 }
741752 val methName = if (hasRepeatedParam) nme.unapplySeq else nme.unapply
742753 val unapplyParam = makeSyntheticParameter(tpt = classTypeRef)
743- val unapplyRHS = if (arity == 0 ) Literal (Constant (true )) else Ident (unapplyParam.name)
754+ val unapplyRHS =
755+ if (arity == 0 ) Literal (Constant (true ))
756+ else if ctx.settings.Yscala2Stdlib .value then scala2LibCompatUnapplyRhs(unapplyParam.name)
757+ else Ident (unapplyParam.name)
744758 val unapplyResTp = if (arity == 0 ) Literal (Constant (true )) else TypeTree ()
759+
745760 DefDef (
746761 methName,
747762 joinParams(derivedTparams, (unapplyParam :: Nil ) :: Nil ),
@@ -1824,16 +1839,6 @@ object desugar {
18241839 flatTree(pats1 map (makePatDef(tree, mods, _, rhs)))
18251840 case ext : ExtMethods =>
18261841 Block (List (ext), Literal (Constant (())).withSpan(ext.span))
1827- case CapturingTypeTree (refs, parent) =>
1828- // convert `{refs} T` to `T @retains refs`
1829- // `{refs}-> T` to `-> (T @retainsByName refs)`
1830- def annotate (annotName : TypeName , tp : Tree ) =
1831- Annotated (tp, New (scalaAnnotationDot(annotName), List (refs)))
1832- parent match
1833- case ByNameTypeTree (restpt) =>
1834- cpy.ByNameTypeTree (parent)(annotate(tpnme.retainsByName, restpt))
1835- case _ =>
1836- annotate(tpnme.retains, parent)
18371842 case f : FunctionWithMods if f.hasErasedParams => makeFunctionWithValDefs(f, pt)
18381843 }
18391844 desugared.withSpan(tree.span)
@@ -1927,7 +1932,7 @@ object desugar {
19271932 }
19281933 tree match
19291934 case tree : FunctionWithMods =>
1930- untpd.FunctionWithMods (applyVParams, tree.body , tree.mods, tree.erasedParams)
1935+ untpd.FunctionWithMods (applyVParams, result , tree.mods, tree.erasedParams)
19311936 case _ => untpd.Function (applyVParams, result)
19321937 }
19331938 }
@@ -1986,15 +1991,13 @@ object desugar {
19861991 trees foreach collect
19871992 case Block (Nil , expr) =>
19881993 collect(expr)
1989- case Quote (expr ) =>
1994+ case Quote (body, _ ) =>
19901995 new UntypedTreeTraverser {
19911996 def traverse (tree : untpd.Tree )(using Context ): Unit = tree match {
1992- case Splice (expr ) => collect(expr )
1997+ case SplicePattern (body, _ ) => collect(body )
19931998 case _ => traverseChildren(tree)
19941999 }
1995- }.traverse(expr)
1996- case CapturingTypeTree (refs, parent) =>
1997- collect(parent)
2000+ }.traverse(body)
19982001 case _ =>
19992002 }
20002003 collect(tree)
0 commit comments