@@ -60,7 +60,7 @@ object PostTyper {
60
60
* mini-phase or subfunction of a macro phase equally well. But taken by themselves
61
61
* they do not warrant their own group of miniphases before pickling.
62
62
*/
63
- class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase =>
63
+ class PostTyper extends MacroTransform with InfoTransformer { thisPhase =>
64
64
import tpd ._
65
65
66
66
override def phaseName : String = PostTyper .name
@@ -425,7 +425,7 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
425
425
if sym.isOpaqueAlias then
426
426
VarianceChecker .checkLambda(rhs, TypeBounds .upper(sym.opaqueAlias))
427
427
case _ =>
428
- processMemberDef(super .transform(tree))
428
+ processMemberDef(super .transform(scala2LibPatch( tree) ))
429
429
case tree : Bind =>
430
430
if tree.symbol.isType && ! tree.symbol.name.is(WildcardParamName ) then
431
431
Checking .checkGoodBounds(tree.symbol)
@@ -534,5 +534,30 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
534
534
sym.addAnnotation(Annotation (defn.ExperimentalAnnot , sym.span))
535
535
sym.companionModule.addAnnotation(Annotation (defn.ExperimentalAnnot , sym.span))
536
536
537
+ private def scala2LibPatch (tree : TypeDef )(using Context ) =
538
+ val sym = tree.symbol
539
+ if ctx.settings.Yscala2Stdlib .value
540
+ && sym.is(ModuleClass ) && ! sym.derivesFrom(defn.SerializableClass )
541
+ && sym.companionClass.derivesFrom(defn.SerializableClass )
542
+ then
543
+ // Add Serializable to companion objects of serializable classes
544
+ tree.rhs match
545
+ case impl : Template =>
546
+ val parents1 = impl.parents :+ TypeTree (defn.SerializableType )
547
+ val impl1 = cpy.Template (impl)(parents = parents1)
548
+ cpy.TypeDef (tree)(rhs = impl1)
549
+ else tree
537
550
}
551
+
552
+ protected override def infoMayChange (sym : Symbol )(using Context ): Boolean =
553
+ ctx.settings.Yscala2Stdlib .value && sym.isAllOf(ModuleClass , butNot = Package )
554
+
555
+ def transformInfo (tp : Type , sym : Symbol )(using Context ): Type = tp match
556
+ case info : ClassInfo =>
557
+ if ! sym.derivesFrom(defn.SerializableClass )
558
+ && sym.companionClass.derivesFrom(defn.SerializableClass )
559
+ then
560
+ info.derivedClassInfo(declaredParents = info.parents :+ defn.SerializableType )
561
+ else tp
562
+ case _ => tp
538
563
}
0 commit comments