@@ -64,18 +64,22 @@ object Scala2Unpickler {
64
64
denot.info = PolyType .fromParams(denot.owner.typeParams, denot.info)
65
65
}
66
66
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 )
70
76
// Scala 2 traits have a constructor iff they have initialization code
71
77
// In dotc we represent that as !StableRealizable, which is also owner.is(NoInits)
72
78
if clsDenot.flagsUNSAFE.is(Trait ) then
73
79
constr.setFlag(StableRealizable )
74
80
clsDenot.setFlag(NoInits )
75
81
addConstructorTypeParams(constr)
76
82
cls.enter(constr, scope)
77
- }
78
- }
79
83
80
84
def setClassInfo (denot : ClassDenotation , info : Type , fromScala2 : Boolean , selfInfo : Type = NoType )(using Context ): Unit = {
81
85
val cls = denot.classSymbol
@@ -109,7 +113,7 @@ object Scala2Unpickler {
109
113
if (tsym.exists) tsym.setFlag(TypeParam )
110
114
else denot.enter(tparam, decls)
111
115
}
112
- if (! denot.flagsUNSAFE.isAllOf(JavaModule )) ensureConstructor (cls, denot, decls)
116
+ if (! denot.flagsUNSAFE.isAllOf(JavaModule )) doEnsureConstructor (cls, denot, decls, fromScala2 )
113
117
114
118
val scalacCompanion = denot.classSymbol.scalacLinkedClass
115
119
0 commit comments