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