@@ -64,18 +64,22 @@ object Scala2Unpickler {
6464 denot.info = PolyType .fromParams(denot.owner.typeParams, denot.info)
6565 }
6666
67- def ensureConstructor (cls : ClassSymbol , clsDenot : ClassDenotation , scope : Scope )(using Context ): Unit = {
68- if (scope.lookup(nme.CONSTRUCTOR ) == NoSymbol ) {
69- val constr = newDefaultConstructor(cls)
67+ def ensureConstructor (cls : ClassSymbol , clsDenot : ClassDenotation , scope : Scope )(using Context ): Unit =
68+ doEnsureConstructor(cls, clsDenot, scope, fromScala2 = true )
69+
70+ private def doEnsureConstructor (cls : ClassSymbol , clsDenot : ClassDenotation , scope : Scope , fromScala2 : Boolean )
71+ (using Context ): Unit =
72+ if scope.lookup(nme.CONSTRUCTOR ) == NoSymbol then
73+ val constr =
74+ if fromScala2 || cls.isAllOf(Trait | JavaDefined ) then newDefaultConstructor(cls)
75+ else newConstructor(cls, Private , paramNames = Nil , paramTypes = Nil )
7076 // Scala 2 traits have a constructor iff they have initialization code
7177 // In dotc we represent that as !StableRealizable, which is also owner.is(NoInits)
7278 if clsDenot.flagsUNSAFE.is(Trait ) then
7379 constr.setFlag(StableRealizable )
7480 clsDenot.setFlag(NoInits )
7581 addConstructorTypeParams(constr)
7682 cls.enter(constr, scope)
77- }
78- }
7983
8084 def setClassInfo (denot : ClassDenotation , info : Type , fromScala2 : Boolean , selfInfo : Type = NoType )(using Context ): Unit = {
8185 val cls = denot.classSymbol
@@ -109,7 +113,7 @@ object Scala2Unpickler {
109113 if (tsym.exists) tsym.setFlag(TypeParam )
110114 else denot.enter(tparam, decls)
111115 }
112- if (! denot.flagsUNSAFE.isAllOf(JavaModule )) ensureConstructor (cls, denot, decls)
116+ if (! denot.flagsUNSAFE.isAllOf(JavaModule )) doEnsureConstructor (cls, denot, decls, fromScala2 )
113117
114118 val scalacCompanion = denot.classSymbol.scalacLinkedClass
115119
0 commit comments