@@ -338,9 +338,9 @@ object desugar {
338
338
def quotedPattern (tree : untpd.Tree , expectedTpt : untpd.Tree )(using Context ): untpd.Tree = {
339
339
def adaptToExpectedTpt (tree : untpd.Tree ): untpd.Tree = tree match {
340
340
// Add the expected type as an ascription
341
- case _ : untpd.Splice =>
341
+ case _ : untpd.SplicePattern =>
342
342
untpd.Typed (tree, expectedTpt).withSpan(tree.span)
343
- case Typed (expr : untpd.Splice , tpt) =>
343
+ case Typed (expr : untpd.SplicePattern , tpt) =>
344
344
cpy.Typed (tree)(expr, untpd.makeAndType(tpt, expectedTpt).withSpan(tpt.span))
345
345
346
346
// Propagate down the expected type to the leafs of the expression
@@ -637,7 +637,10 @@ object desugar {
637
637
// new C[...](p1, ..., pN)(moreParams)
638
638
val (caseClassMeths, enumScaffolding) = {
639
639
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)
641
644
642
645
def productElemMeths =
643
646
val caseParams = derivedVparamss.head.toArray
@@ -735,13 +738,25 @@ object desugar {
735
738
.withMods(appMods) :: Nil
736
739
}
737
740
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
+
738
749
val hasRepeatedParam = constrVparamss.head.exists {
739
750
case ValDef (_, tpt, _) => isRepeated(tpt)
740
751
}
741
752
val methName = if (hasRepeatedParam) nme.unapplySeq else nme.unapply
742
753
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)
744
758
val unapplyResTp = if (arity == 0 ) Literal (Constant (true )) else TypeTree ()
759
+
745
760
DefDef (
746
761
methName,
747
762
joinParams(derivedTparams, (unapplyParam :: Nil ) :: Nil ),
@@ -1824,16 +1839,6 @@ object desugar {
1824
1839
flatTree(pats1 map (makePatDef(tree, mods, _, rhs)))
1825
1840
case ext : ExtMethods =>
1826
1841
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)
1837
1842
case f : FunctionWithMods if f.hasErasedParams => makeFunctionWithValDefs(f, pt)
1838
1843
}
1839
1844
desugared.withSpan(tree.span)
@@ -1927,7 +1932,7 @@ object desugar {
1927
1932
}
1928
1933
tree match
1929
1934
case tree : FunctionWithMods =>
1930
- untpd.FunctionWithMods (applyVParams, tree.body , tree.mods, tree.erasedParams)
1935
+ untpd.FunctionWithMods (applyVParams, result , tree.mods, tree.erasedParams)
1931
1936
case _ => untpd.Function (applyVParams, result)
1932
1937
}
1933
1938
}
@@ -1986,15 +1991,13 @@ object desugar {
1986
1991
trees foreach collect
1987
1992
case Block (Nil , expr) =>
1988
1993
collect(expr)
1989
- case Quote (expr ) =>
1994
+ case Quote (body, _ ) =>
1990
1995
new UntypedTreeTraverser {
1991
1996
def traverse (tree : untpd.Tree )(using Context ): Unit = tree match {
1992
- case Splice (expr ) => collect(expr )
1997
+ case SplicePattern (body, _ ) => collect(body )
1993
1998
case _ => traverseChildren(tree)
1994
1999
}
1995
- }.traverse(expr)
1996
- case CapturingTypeTree (refs, parent) =>
1997
- collect(parent)
2000
+ }.traverse(body)
1998
2001
case _ =>
1999
2002
}
2000
2003
collect(tree)
0 commit comments